"""
Admin Dashboard
Web-based admin interface for IOM platform
"""
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import json
app = FastAPI(title="IOM Admin Dashboard")
# Templates
templates = Jinja2Templates(directory="admin/templates")
# Mock data for dashboard
DASHBOARD_DATA = {
"stats": {
"total_observations": 15420,
"total_objects": 8934,
"active_missions": 234,
"pending_reviews": 89,
"avg_rgi": 34.5,
"trend": "improving"
},
"recent_observations": [
{"id": "OBS-001", "location": "Stockholm City", "condition": 3, "timestamp": "2026-06-26T10:00:00Z"},
{"id": "OBS-002", "location": "Gothenburg Port", "condition": 4, "timestamp": "2026-06-26T09:30:00Z"},
{"id": "OBS-003", "location": "Malmö Bridge", "condition": 2, "timestamp": "2026-06-26T09:00:00Z"}
],
"alerts": [
{"type": "critical", "message": "Bridge condition degraded to 4", "location": "Malmö Bridge"},
{"type": "warning", "message": "High RGI in district 3", "location": "Stockholm"},
{"type": "info", "message": "New zoomer registered", "location": "Gothenburg"}
],
"top_issues": [
{"issue": "Damaged sidewalks", "count": 234, "trend": "up"},
{"issue": "Broken lighting", "count": 189, "trend": "down"},
{"issue": "Graffiti", "count": 156, "trend": "stable"}
]
}
@app.get("/", response_class=HTMLResponse)
async def dashboard(request: Request):
"""Main dashboard"""
return templates.TemplateResponse("dashboard.html", {
"request": request,
"data": DASHBOARD_DATA
})
@app.get("/api/stats")
async def get_stats():
"""Get dashboard stats"""
return DASHBOARD_DATA["stats"]
@app.get("/api/observations")
async def get_observations():
"""Get recent observations"""
return DASHBOARD_DATA["recent_observations"]
@app.get("/api/alerts")
async def get_alerts():
"""Get active alerts"""
return DASHBOARD_DATA["alerts"]
# HTML Template
def create_dashboard_template():
"""Create dashboard HTML template"""
html = """
IOM Admin Dashboard
Total Observations
{{ data.stats.total_observations }}
↗ {{ data.stats.trend }}
Total Objects
{{ data.stats.total_objects }}
→ stable
Active Missions
{{ data.stats.active_missions }}
↗ increasing
Pending Reviews
{{ data.stats.pending_reviews }}
↘ decreasing
Average RGI
{{ data.stats.avg_rgi }}
↘ improving
🚨 Active Alerts
| Type | Message | Location |
{% for alert in data.alerts %}
| {{ alert.type }} |
{{ alert.message }} |
{{ alert.location }} |
{% endfor %}
📊 Recent Observations
| ID | Location | Condition | Time |
{% for obs in data.recent_observations %}
| {{ obs.id }} |
{{ obs.location }} |
Condition {{ obs.condition }} |
{{ obs.timestamp }} |
{% endfor %}
⚠️ Top Issues
| Issue | Count | Trend |
{% for issue in data.top_issues %}
| {{ issue.issue }} |
{{ issue.count }} |
{{ issue.trend }} |
{% endfor %}
"""
import os
os.makedirs("admin/templates", exist_ok=True)
with open("admin/templates/dashboard.html", "w") as f:
f.write(html)
if __name__ == "__main__":
create_dashboard_template()
print("Dashboard template created")