sync: dashboard_routes.py from VPS — digest + contributor-graph endpoints
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c3d0b1f5a4
commit
11e026448a
1 changed files with 23 additions and 0 deletions
|
|
@ -1310,6 +1310,7 @@ def register_dashboard_routes(app: web.Application, get_conn):
|
||||||
app.router.add_get("/api/telegram-extractions", handle_telegram_extractions)
|
app.router.add_get("/api/telegram-extractions", handle_telegram_extractions)
|
||||||
app.router.add_get("/api/contributor-growth", handle_contributor_growth)
|
app.router.add_get("/api/contributor-growth", handle_contributor_growth)
|
||||||
app.router.add_get("/api/digest/latest", handle_digest_latest)
|
app.router.add_get("/api/digest/latest", handle_digest_latest)
|
||||||
|
app.router.add_get("/api/contributor-graph", handle_contributor_graph)
|
||||||
|
|
||||||
|
|
||||||
async def handle_digest_latest(request):
|
async def handle_digest_latest(request):
|
||||||
|
|
@ -1324,3 +1325,25 @@ async def handle_digest_latest(request):
|
||||||
return web.json_response({"error": "No digest available yet"}, status=404)
|
return web.json_response({"error": "No digest available yet"}, status=404)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return web.json_response({"error": str(e)}, status=500)
|
return web.json_response({"error": str(e)}, status=500)
|
||||||
|
|
||||||
|
|
||||||
|
async def handle_contributor_graph(request):
|
||||||
|
"""GET /api/contributor-graph — serve the PNG chart."""
|
||||||
|
import subprocess, os
|
||||||
|
png_path = "/opt/teleo-eval/static/contributor-graph.png"
|
||||||
|
# Regenerate if older than 1 hour or missing
|
||||||
|
regen = not os.path.exists(png_path)
|
||||||
|
if not regen:
|
||||||
|
age = __import__('time').time() - os.path.getmtime(png_path)
|
||||||
|
regen = age > 3600
|
||||||
|
if regen:
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
['python3', '/opt/teleo-eval/scripts/contributor-graph.py'],
|
||||||
|
timeout=30, capture_output=True
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if not os.path.exists(png_path):
|
||||||
|
return web.Response(text='Chart not available', status=503)
|
||||||
|
return web.FileResponse(png_path, headers={'Content-Type': 'image/png'})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue