Spaces:
Sleeping
ποΈ Waste Intelligence API β Complete Documentation
AI-Powered Predictive Waste Management System for Jakarta Pusat (CASE 2)
Version:2.0.0| License:MIT| Author:Faril Putra Pratama - SMK Taruna Bangsa
π Table of Contents
- Project Overview
- System Architecture
- Core AI & Business Logic
- API Reference
- Data Dictionary
- Deployment & Setup
- Testing & Validation
- Business Impact & Use Cases
- Roadmap & Scalability
- Author & Support
1. Project Overview
Problem Statement
Penumpukan sampah di Jakarta Pusat sering terjadi secara mendadak saat:
- οΈ Musim hujan tinggi (sampah basah β berat volume naik)
- πͺ Event besar (PRJ, Lebaran, Konser, HUT RI)
- π Weekend & libur nasional
Penanganan saat ini masih reaktif: armada dikirim setelah laporan masuk atau tumpukan terlihat. Akibatnya: biaya operasional membengkak, jadwal pengangkutan tidak efisien, dan risiko kesehatan lingkungan meningkat.
π‘ Solution
Sistem ini mengubah paradigma menjadi prediktif menggunakan:
- π€ Amazon Chronos (Transformer time-series) untuk forecasting baseline volume
- π¦οΈ BMKG Weather Integration untuk penyesuaian berat sampah basah
- π Event Calendar Engine dengan location-aware impact modeling
- π Logistics Optimizer untuk rekomendasi armada & manpower presisi
Output: Prediksi volume sampah 1β30 hari ke depan per lokasi, dekomposisi organik/plastik, status risiko, dan rencana logistik operasional.
2. System Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β β’ Postman / Frontend Dashboard / Mobile App β
β β’ REST API Calls (JSON) β
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTPS / CORS
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β API GATEWAY (FastAPI) β
β β’ Request Validation (Pydantic) β
β β’ CORS Middleware β
β β’ Structured Logging β
βββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βββββββββββ΄ββββββββββ
βΌ βΌ
ββββββββββ βββββββββββββββ
β PREDICT β β STATUS β
βEndpoint β β Check β
ββββββ¬βββββ βββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β BUSINESS LOGIC LAYER β
β 1οΈβ£ Date Parser & Context Setup β
β 2οΈβ£ Chronos Inference (Async/ThreadPool) β
β 3οΈβ£ External Factor Integration β
β β’ Rain multiplier (BMKG) β
β β’ Event engine + radius mapping β
β β’ Soft impact scaling (10β35%) β
β 4οΈβ£ Post-Processing & Aggregation β
β β’ KLHK 2026 decomposition β
β β’ Risk scoring & truck calculation β
ββββββββββββββ¬ββββββββββββββββββββββββββββββββββββ
β
βββββββββββ΄ββββββββββ
βΌ βΌ
βββββββββββ βββββββββββββββ
β DATA β β MODEL β
β LAYER β β LAYER β
β β’ CSV β β β’ Chronos β
β β’ In-memβ β T5-Tiny β
β Cache β β β’ PyTorch β
βββββββββββ βββββββββββββββ
πΉ Tech Stack
| Layer | Technology |
|---|---|
| API Framework | FastAPI + Uvicorn |
| AI Model | Amazon Chronos-T5-Tiny (Hugging Face) |
| Data Processing | Pandas, NumPy |
| Validation | Pydantic v2 |
| Deployment | Hugging Face Spaces (CPU) |
| Logging | Python logging (structured) |
3. Core AI & Business Logic
π€ 3.1 Time-Series Forecasting (Chronos)
- Model:
amazon/chronos-t5-tiny(lightweight, CPU-optimized) - Input: Historical volume series (
dataset_vibe_coder_2026.csv, 365 hari) - Output: Probabilistic forecast (median quantile
0.5) untukNhari ke depan - Advantage: Mampu menangkap pola musiman, tren gradual, dan fluktuasi natural tanpa fitur engineering berat
πͺ 3.2 Event Engine & Location Matching
Event tidak serta-merta menaikkan volume di seluruh kota. Sistem menggunakan radius-aware logic:
EVENT_RADIUS_MAP = {
'jiexpo': ['jis', 'kemayoran', 'pademangan', 'jakarta'],
'monas': ['pasar senen', 'gang sempit tambora', 'merdeka', 'jakarta'],
'gbk': ['senayan', 'tanah abang', 'kuningan', 'jakarta'],
'ancol': ['pademangan', 'kelapa gading', 'jakarta'],
'jakarta': ['*'] # City-wide
}
- Matching Rules: Direct string match β City-wide fallback β Radius mapping
- Impact Scaling:
1.0 + (0.10 + min(scale * 0.05, 0.25))β Maksimal +35% volume - Result: Event di JIExpo hanya mempengaruhi JIS/Kemayoran, bukan GBK/Senayan
π§οΈ 3.3 Weather Integration (BMKG Style)
Curah hujan mempengaruhi berat sampah (basah = lebih padat/berat):
β€20mm: Tidak ada penyesuaian>20mm: Multiplier1.02hingga1.05(linear scaling)- Rationale: Sampah organik menyerap air β tonase naik tanpa volume fisik berubah drastis
οΈ 3.4 Risk Scoring Algorithm
def hitung_prioritas(nama_lokasi, volume_ton):
akses = DATABASE_LOKASI[nama_lokasi]['aksesibilitas'] # 0.25 β 1.0
skor = volume_ton / akses
if skor > 1600: return 'CRITICAL β οΈ'
if skor >= 1100: return 'WARNING π‘'
return 'SAFE β
'
- Accessibility Factor: Lokasi sempit/sulit dijangkau (
0.25) mendapat skor risiko lebih tinggi untuk volume yang sama - Thresholds: Dikalibrasi untuk rentang volume realistis Jakarta Pusat (1000β2000 ton)
π 3.5 Waste Decomposition (KLHK 2026)
Rasio dekomposisi dihitung dinamis dari dataset historis, fallback ke standar resmi:
- Organik/Sisa Makanan:
~49.87% - Plastik:
~22.95% - Sisanya: Kertas, logam, residu (tidak dihitung terpisah untuk optimasi logistik)
4. API Reference
POST /api/v1/predict
Deskripsi: Generate prediksi volume sampah 1β30 hari ke depan untuk lokasi tertentu.
Request Body
{
"hari_ke_depan": 7,
"prediksi_hujan_bmkg": 25.5,
"skala_keramaian": 0,
"nama_lokasi": "JIS",
"dari_tanggal": "06-01"
}
| Field | Type | Required | Description |
|---|---|---|---|
hari_ke_depan |
int |
β | Durasi prediksi (1β30 hari) |
prediksi_hujan_bmkg |
float |
β | Estimasi curah hujan (mm). 0 = kering |
skala_keramaian |
int |
β | Skala event manual (0β5). 0 = normal |
nama_lokasi |
string |
β | Target lokasi: JIS, GBK, Pasar Senen, Gang Sempit Tambora |
dari_tanggal |
string |
β | Tanggal mulai. Format: YYYY-MM-DD, MM-DD, atau "1 Juni 2026" |
Response Success (200)
{
"status": "success",
"message": "π‘ WARNING di JIS: Volume di atas rata-rata.",
"confidence_score": 0.94,
"data": {
"prediction_results": [
{
"tanggal": "2026-06-02",
"lokasi": "JIS",
"total_volume_ton": 1245.50,
"sisa_makanan_ton": 621.15,
"plastik_ton": 285.84,
"rekomendasi_truk": 125,
"status_risiko": "WARNING π‘",
"info_event": "PRJ Opening @ JIExpo"
}
],
"logistics_plan": {
"trucks_needed": 872,
"manpower": 2616,
"estimated_duration_hours": 1743.2,
"efficiency_rate": "85% (Optimal)"
}
}
}
Error Responses
| Status Code | Response | Cause |
|---|---|---|
400 |
{"detail": "Format tanggal tidak valid..."} |
Input tanggal tidak dikenali parser |
500 |
{"detail": "Gagal memproses prediksi: ..."} |
Internal error / model crash |
503 |
{"detail": "Model/Dataset belum siap."} |
Service masih startup / model loading |
GET /
Deskripsi: Health check & metadata sistem.
{
"status": "Online",
"model": "Chronos-T5 Tiny",
"dataset_year": "2026",
"events_loaded": 15
}
5. Data Dictionary
π dataset_vibe_coder_2026.csv
| Kolom | Tipe | Deskripsi |
|---|---|---|
TANGGAL |
YYYY-MM-DD |
Hari observasi |
RR |
float |
Curah hujan (mm) |
Nama_Event |
string |
Nama event (kosong jika tidak ada) |
Ada_Event |
int |
Flag 1/0 |
Crowd_Scale |
float |
Skala keramaian (0β5) |
Volume_Total_Ton |
float |
Volume sampah baseline |
Vol_Sisa_Makanan_Ton |
float |
Komponen organik |
Vol_Plastik_Ton |
float |
Komponen plastik |
Hari_Ke |
int |
Urutan hari (1β365) |
Is_Weekend |
int |
1 = Sabtu/Minggu |
ZONA |
string |
Klasifikasi area: Tourism, Residential, Commercial |
π event_jakarta_2026.txt
| Kolom | Tipe | Deskripsi |
|---|---|---|
tanggal |
YYYY-MM-DD |
Tanggal event |
nama_event |
string |
Nama event |
lokasi |
string |
Lokasi utama event |
skala_keramaian |
int |
Skala 1β5 |
6. Deployment & Setup
Hugging Face Spaces (Production)
- Create Space β Template:
Blankβ Runtime:Python - Upload files:
π waste-prediction-api/ βββ app.py βββ dataset_vibe_coder_2026.csv βββ event_jakarta_2026.txt βββ requirements.txt βββ SYSTEM_ARCHITECTURE.md - Settings β Python 3.10, Hardware:
CPU, Auto-rebuild:ON - Click Factory rebuild after each commit
π» Local Development
git clone https://huggingface.co/spaces/ALAMDIENG/waste-prediction-api
cd waste-prediction-api
pip install -r requirements.txt
uvicorn app:app --host 0.0.0.0 --port 8001 --reload
Test:
curl -X POST http://localhost:8001/api/v1/predict \
-H "Content-Type: application/json" \
-d '{"hari_ke_depan":7,"dari_tanggal":"06-01","nama_lokasi":"JIS"}'
π¦ requirements.txt
fastapi>=0.104.0
uvicorn>=0.24.0
pandas>=2.1.0
numpy>=1.26.0
torch>=2.1.0
chronos-forecasting>=0.1.0
pydantic>=2.5.0
7. Testing & Validation
π§ͺ Unit Tests (Conceptual)
def test_parse_flexible_date():
assert parse_flexible_date("06-01").date() == date(2026, 6, 1)
assert parse_flexible_date("1 Juni 2026").date() == date(2026, 6, 1)
def test_location_matching():
assert check_location_match("JIS", "JIExpo") == True
assert check_location_match("GBK", "JIExpo") == False
Integration Scenarios (Postman)
| Scenario | Input | Expected |
|---|---|---|
| Normal day | dari_tanggal: "06-10", skala: 0 |
info_event: null, volume ~1200 ton |
| Event match | dari_tanggal: "06-01", lokasi: "JIS" |
info_event: "PRJ...", +20β35% volume |
| Event no-match | dari_tanggal: "06-01", lokasi: "GBK" |
info_event: null, volume normal |
| Heavy rain | prediksi_hujan_bmkg: 50 |
Multiplier +2β5% |
| Low accessibility | lokasi: "Gang Sempit Tambora" |
Lower volume β WARNING/CRITICAL |
π Performance Targets
- Latency:
< 3.0s(p95) untuk forecast 7 hari - Throughput:
10β20 req/min(HF Spaces CPU tier) - Accuracy:
Β±8β12%MAE vs baseline historis (valid untuk perencanaan logistik)
8. Business Impact & Use Cases
Operational Efficiency
| Metric | Before (Reactive) | After (Predictive) | Improvement |
|---|---|---|---|
| Fleet dispatch | After complaint/report | H-1/H-2 scheduled | β¬οΈ 15β20% idle time |
| Fuel cost | Unplanned routes | Optimized zoning | οΈ 10β12% consumption |
| Manpower | Overtime-heavy | Shift-planned | β¬οΈ 8β10% overtime |
| Public health | Post-spill cleanup | Pre-emptive containment | β¬οΈ Risk mitigation |
Primary Use Cases
- Dinas Lingkungan Hidup: Penjadwalan armada harian berbasis risiko zonasi
- Event Organizer: Kalkulasi kebutuhan TPS & truk sampah saat izin keramaian
- Fasilitas Pengelola Sampah: Alokasi shift & kapasitas gudang 3 hari ke depan
- Dashboard Eksekutif: Executive summary + visual heatmap volume per kecamatan
9. Roadmap & Scalability
v2.1 (Next 3 Months)
- Real-time BMKG API integration (auto-fetch
prediksi_hujan_bmkg) - Batch prediction endpoint (
/api/v1/predict/multi) - Export to PDF/CSV + email webhook
- Rate limiting & API key auth
ποΈ v3.0 (Architecture Upgrade)
- Microservices split:
forecast-service,event-service,logistics-service - GPU inference optimization (Chronos-base/mini)
- Automated retraining pipeline (GitHub Actions + HF Datasets)
- Prometheus/Grafana observability + alerting
Long-term Vision
"Dari prediksi volume β optimasi rute real-time β circular economy tracking. Sistem ini menjadi tulang punggung smart city waste management yang data-driven, hemat biaya, dan berkelanjutan."
10. Author & Support
Developed by:
Faril Putra Pratama
SMK Taruna Bangsa
π GitHub: @FARILtau72
License: MIT
Case Study: Waste Volume Prediction System (CASE 2)
Last Updated: 2026-06-01
π© Issues & Contributions:
Gunakan GitHub Issues untuk bug report, feature request, atau dokumentasi improvement. PR welcome!
π‘ Presenter Note:
"Sistem ini bukan sekadar forecast angka. Ia adalah decision engine: Chronos memberi baseline, cuaca memberi koreksi berat, event memberi konteks spasial, dan risk scoring memberi prioritas aksi. Hasilnya? Armada tidak lagi keliling butaβmereka datang ke tempat yang tepat, di waktu yang tepat, dengan kapasitas yang tepat."