stats yay
This commit is contained in:
1 parent
2de0843344
commit
e7f10c4f59
1 file changed
+36
-1
+36
-1
@@ -5,6 +5,7 @@ from typing import Dict, Any
|
|||||||
from fastapi import FastAPI, Request, Response, status
|
from fastapi import FastAPI, Request, Response, status
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
import src.get_sq_env as sq_env
|
import src.get_sq_env as sq_env
|
||||||
|
import src.stats as stats
|
||||||
|
|
||||||
# Square webhook validation
|
# Square webhook validation
|
||||||
from square.utils.webhooks_helper import verify_signature
|
from square.utils.webhooks_helper import verify_signature
|
||||||
@@ -40,7 +41,11 @@ async def root():
|
|||||||
return {
|
return {
|
||||||
"service": "Studspider",
|
"service": "Studspider",
|
||||||
"status": "running",
|
"status": "running",
|
||||||
"endpoints": {"webhook": "/hook (POST)", "health": "/health (GET)"},
|
"endpoints": {
|
||||||
|
"webhook": "/hook (POST)",
|
||||||
|
"health": "/health (GET)",
|
||||||
|
"stats": "/stats (GET)",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,6 +60,36 @@ async def health_check():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/stats")
|
||||||
|
async def get_stats():
|
||||||
|
"""
|
||||||
|
Get daily statistics for LEGO inventory.
|
||||||
|
|
||||||
|
Returns metrics about enrichment progress, missing data, and catalog value.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
daily_stats = await stats.get_daily_stats()
|
||||||
|
|
||||||
|
# Calculate completion percentage
|
||||||
|
if daily_stats["total_items"] > 0:
|
||||||
|
completion_rate = (
|
||||||
|
daily_stats["enriched_items"] / daily_stats["total_items"] * 100
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
completion_rate = 0.0
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": "success",
|
||||||
|
"stats": daily_stats,
|
||||||
|
"completion_rate": round(completion_rate, 1),
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=500,
|
||||||
|
content={"status": "error", "message": str(e)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/hook")
|
@app.post("/hook")
|
||||||
async def webhook_handler(request: Request):
|
async def webhook_handler(request: Request):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in new issue
Block a user