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": "♻️ Zero-Waste-Tipps",
"card_hint": "Zeige während des Kochens Tipps zur Wiederverwendung von Abfällen (Schalen, Kochwasser usw.). Standardmäßig deaktiviert.",
"label": "Tipps beim Kochen anzeigen"
},
"info": {
"tab": "Info",
"ai_title": "Gemini AI — Token-Nutzung",
"ai_hint": "Monatlicher Verbrauch und geschätzte Kosten für den aktuellen API-Schlüssel.",
"loading": "Laden…",
"total_tokens": "Token gesamt",
"est_cost": "Gesch. Kosten",
"input_tok": "Eingabe-Token",
"output_tok": "Ausgabe-Token",
"ai_calls": "KI-Aufrufe",
"by_action": "Aufschlüsselung nach Funktion",
"by_model": "Aufschlüsselung nach Modell",
"pricing_note": "Referenzpreise: gemini-2.5-flash $0.15/1M Input, $0.60/1M Output.",
"system_title": "System",
"db_size": "Datenbankgröße",
"log_size": "Log-Größe",
"log_level": "Log-Level"
}
},
"expiry": {
+18
View File
@@ -761,6 +761,24 @@
"card_title": "♻️ Zero-waste tips",
"card_hint": "During cooking, show tips on how to reuse scraps generated in each step (peels, cooking water, etc.). Disabled by default.",
"label": "Show tips during cooking"
},
"info": {
"tab": "Info",
"ai_title": "Gemini AI — Token Usage",
"ai_hint": "Monthly consumption and estimated cost for the current API key.",
"loading": "Loading…",
"total_tokens": "Total tokens",
"est_cost": "Est. cost",
"input_tok": "Input tokens",
"output_tok": "Output tokens",
"ai_calls": "AI calls",
"by_action": "Breakdown by function",
"by_model": "Breakdown by model",
"pricing_note": "Reference pricing: gemini-2.5-flash $0.15/1M input, $0.60/1M output.",
"system_title": "System",
"db_size": "Database size",
"log_size": "Log size",
"log_level": "Log level"
}
},
"expiry": {
+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": {