fix: enforce Asia/Jakarta timezone for default start_date and autopilot calculations
Browse files
app.py
CHANGED
|
@@ -14,9 +14,12 @@ import io
|
|
| 14 |
import csv
|
| 15 |
import json
|
| 16 |
from chronos import ChronosPipeline
|
| 17 |
-
from datetime import datetime, timedelta
|
| 18 |
import os, logging, re
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# ==========================================
|
| 21 |
# 1. APPLICATION CONFIGURATION
|
| 22 |
# ==========================================
|
|
@@ -331,7 +334,7 @@ def get_latest_news():
|
|
| 331 |
"title": "DKI Uji Coba Penarikan Retribusi Sampah Pelayanan Kebersihan Harian",
|
| 332 |
"source": "Antara News",
|
| 333 |
"url": "https://www.antaranews.com/tag/sampah-jakarta",
|
| 334 |
-
"date_fetched": str(
|
| 335 |
"summary": "Pemprov DKI Jakarta merencanakan uji coba penarikan retribusi pelayanan kebersihan/sampah."
|
| 336 |
}
|
| 337 |
]
|
|
@@ -346,7 +349,7 @@ async def predict_waste_volume(req: PredictionRequest):
|
|
| 346 |
raise HTTPException(503, "Models not ready.")
|
| 347 |
|
| 348 |
try:
|
| 349 |
-
start_date = parse_flexible_date(req.start_date) if req.start_date else pd.Timestamp(
|
| 350 |
|
| 351 |
# Get location metadata
|
| 352 |
config = KECAMATAN_DATABASE[req.location]
|
|
@@ -529,7 +532,7 @@ async def get_alerts(location: str = Query(None)):
|
|
| 529 |
if df_history is None: raise HTTPException(503, "Model not ready")
|
| 530 |
|
| 531 |
alerts = []
|
| 532 |
-
today =
|
| 533 |
|
| 534 |
for i in range(3):
|
| 535 |
d = (today + timedelta(days=i)).strftime("%Y-%m-%d")
|
|
@@ -551,7 +554,7 @@ async def get_alerts(location: str = Query(None)):
|
|
| 551 |
"message": f"Alert: {status} volume expected at {loc}"
|
| 552 |
})
|
| 553 |
|
| 554 |
-
return AlertResponse(status="success", alert_count=len(alerts), alerts=alerts, last_updated=
|
| 555 |
|
| 556 |
@app.get("/api/v1/autopilot", tags=["Autonomous"])
|
| 557 |
async def get_autopilot_data():
|
|
@@ -559,7 +562,7 @@ async def get_autopilot_data():
|
|
| 559 |
if df_history is None:
|
| 560 |
raise HTTPException(503, "Models not ready")
|
| 561 |
|
| 562 |
-
today =
|
| 563 |
d_str = today.strftime("%Y-%m-%d")
|
| 564 |
|
| 565 |
total_vol = 0.0
|
|
|
|
| 14 |
import csv
|
| 15 |
import json
|
| 16 |
from chronos import ChronosPipeline
|
| 17 |
+
from datetime import datetime, timedelta, timezone
|
| 18 |
import os, logging, re
|
| 19 |
|
| 20 |
+
def get_jakarta_now() -> datetime:
|
| 21 |
+
return datetime.now(timezone(timedelta(hours=7)))
|
| 22 |
+
|
| 23 |
# ==========================================
|
| 24 |
# 1. APPLICATION CONFIGURATION
|
| 25 |
# ==========================================
|
|
|
|
| 334 |
"title": "DKI Uji Coba Penarikan Retribusi Sampah Pelayanan Kebersihan Harian",
|
| 335 |
"source": "Antara News",
|
| 336 |
"url": "https://www.antaranews.com/tag/sampah-jakarta",
|
| 337 |
+
"date_fetched": str(get_jakarta_now().date()),
|
| 338 |
"summary": "Pemprov DKI Jakarta merencanakan uji coba penarikan retribusi pelayanan kebersihan/sampah."
|
| 339 |
}
|
| 340 |
]
|
|
|
|
| 349 |
raise HTTPException(503, "Models not ready.")
|
| 350 |
|
| 351 |
try:
|
| 352 |
+
start_date = parse_flexible_date(req.start_date) if req.start_date else pd.Timestamp(get_jakarta_now().date())
|
| 353 |
|
| 354 |
# Get location metadata
|
| 355 |
config = KECAMATAN_DATABASE[req.location]
|
|
|
|
| 532 |
if df_history is None: raise HTTPException(503, "Model not ready")
|
| 533 |
|
| 534 |
alerts = []
|
| 535 |
+
today = get_jakarta_now().date()
|
| 536 |
|
| 537 |
for i in range(3):
|
| 538 |
d = (today + timedelta(days=i)).strftime("%Y-%m-%d")
|
|
|
|
| 554 |
"message": f"Alert: {status} volume expected at {loc}"
|
| 555 |
})
|
| 556 |
|
| 557 |
+
return AlertResponse(status="success", alert_count=len(alerts), alerts=alerts, last_updated=get_jakarta_now().isoformat())
|
| 558 |
|
| 559 |
@app.get("/api/v1/autopilot", tags=["Autonomous"])
|
| 560 |
async def get_autopilot_data():
|
|
|
|
| 562 |
if df_history is None:
|
| 563 |
raise HTTPException(503, "Models not ready")
|
| 564 |
|
| 565 |
+
today = get_jakarta_now()
|
| 566 |
d_str = today.strftime("%Y-%m-%d")
|
| 567 |
|
| 568 |
total_vol = 0.0
|