feat: Gemini token usage counter (#82) + smarter qty suggestions 90-day EWMA (#70)

Backend (api/index.php):
- callGemini() now extracts usageMetadata (tokens_in/tokens_out) from response
- _recordAiUsage() persists monthly token data to data/ai_usage.json
- callGeminiWithFallback() accepts $usageAction param; all 15 call sites labeled
- gemini_usage endpoint: returns token stats, cost estimate, log info, DB size
- smartShopping(): rolling 90-day EWMA (70% last-30d / 30% days-31-90)
  with fallback to all-time rate when <14 days of history

Frontend (index.html + app.js):
- New Info tab (ℹ️) in Settings with Gemini usage and System cards
- _loadInfoTab() / _renderInfoTab(): loads on click, auto-refreshes every 30s
- switchSettingsTab() stops auto-refresh when leaving Info tab

Translations (it/en/de): settings.info.* keys
This commit is contained in:
dadaloop82
2026-05-18 06:23:42 +00:00
parent dc3cefefd0
commit 9f554c6e22
6 changed files with 339 additions and 35 deletions
+18
View File
@@ -761,6 +761,24 @@
"card_title": "♻️ Suggerimenti zero-waste",
"card_hint": "Durante la cottura, mostra consigli su come riutilizzare gli scarti prodotti in ogni passo (bucce, acqua di cottura, ecc.). Disattivo per impostazione predefinita.",
"label": "Mostra suggerimenti durante la cottura"
},
"info": {
"tab": "Info",
"ai_title": "Gemini AI — Utilizzo Token",
"ai_hint": "Consumo mensile e costo stimato per la chiave API corrente.",
"loading": "Caricamento…",
"total_tokens": "Token totali",
"est_cost": "Costo stimato",
"input_tok": "Token input",
"output_tok": "Token output",
"ai_calls": "Chiamate AI",
"by_action": "Dettaglio per funzione",
"by_model": "Dettaglio per modello",
"pricing_note": "Prezzi di riferimento: gemini-2.5-flash $0.15/1M input, $0.60/1M output.",
"system_title": "Sistema",
"db_size": "Dimensione database",
"log_size": "Dimensione log",
"log_level": "Livello di log"
}
},
"expiry": {