nordabiz/.claude/commands/chat-stats.md
Maciej Pienczyn 110d971dca
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
feat: migrate prod docs to OVH VPS + UTC→Warsaw timezone in all templates
Production moved from on-prem VM 249 (10.22.68.249) to OVH VPS
(57.128.200.27, inpi-vps-waw01). Updated ALL documentation, slash
commands, memory files, architecture docs, and deploy procedures.

Added |local_time Jinja filter (UTC→Europe/Warsaw) and converted
155 .strftime() calls across 71 templates so timestamps display
in Polish timezone regardless of server timezone.

Also includes: created_by_id tracking, abort import fix, ICS
calendar fix for missing end times, Pros Poland data cleanup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 13:41:53 +02:00

3.4 KiB

NordaBiz AI Chat Statistics

Wyświetl statystyki użycia chatu AI (Google Gemini) w projekcie NordaBiz.

Kroki do wykonania:

1. Podstawowe statystyki

Wykonaj zapytania na bazie PostgreSQL (DEV via Docker):

docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '=== STATYSTYKI CHATU AI ===' as header;

SELECT '--- Konwersacje ---' as section;
SELECT 'Łącznie konwersacji: ' || COUNT(*) FROM ai_chat_conversations;
SELECT 'Aktywne (ostatnie 7 dni): ' || COUNT(*) FROM ai_chat_conversations
  WHERE updated_at > NOW() - INTERVAL '7 days';

SELECT '--- Wiadomości ---' as section;
SELECT 'Łącznie wiadomości: ' || COUNT(*) FROM ai_chat_messages;
SELECT 'Od użytkowników: ' || COUNT(*) FROM ai_chat_messages WHERE role='user';
SELECT 'Od asystenta: ' || COUNT(*) FROM ai_chat_messages WHERE role='assistant';

SELECT '--- Tokeny ---' as section;
SELECT 'Input tokens: ' || COALESCE(SUM(input_tokens), 0) FROM ai_chat_messages;
SELECT 'Output tokens: ' || COALESCE(SUM(output_tokens), 0) FROM ai_chat_messages;

SELECT '--- Koszty (USD) ---' as section;
SELECT 'Łączny koszt: \$' || ROUND(COALESCE(SUM(cost_usd), 0)::numeric, 4) FROM ai_chat_messages;
SELECT 'Średni koszt/wiadomość: \$' || ROUND(COALESCE(AVG(cost_usd), 0)::numeric, 6) FROM ai_chat_messages WHERE role='assistant';

SELECT '--- Wydajność ---' as section;
SELECT 'Średni czas odpowiedzi: ' || ROUND(COALESCE(AVG(latency_ms), 0)::numeric, 0) || ' ms' FROM ai_chat_messages WHERE role='assistant';
SELECT 'Max czas odpowiedzi: ' || COALESCE(MAX(latency_ms), 0) || ' ms' FROM ai_chat_messages WHERE role='assistant';
"

2. Statystyki dzienne (ostatnie 7 dni)

docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '=== AKTYWNOŚĆ OSTATNIE 7 DNI ===' as header;
SELECT DATE(created_at) as dzien, COUNT(*) as wiadomosci
FROM ai_chat_messages
WHERE created_at > NOW() - INTERVAL '7 days'
GROUP BY DATE(created_at)
ORDER BY dzien DESC;
"

3. Top użytkownicy (jeśli są powiązania)

docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '=== TOP UŻYTKOWNICY ===' as header;
SELECT c.user_id, COUNT(m.id) as wiadomosci
FROM ai_chat_conversations c
JOIN ai_chat_messages m ON c.id = m.conversation_id
GROUP BY c.user_id
ORDER BY wiadomosci DESC
LIMIT 10;
"

4. Koszty API (tabela ai_api_costs)

docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '=== KOSZTY API GEMINI ===' as header;
SELECT
  DATE(created_at) as dzien,
  COUNT(*) as wywolania,
  SUM(input_tokens) as input_tok,
  SUM(output_tokens) as output_tok,
  ROUND(SUM(total_cost_usd)::numeric, 4) as koszt_usd
FROM ai_api_costs
WHERE created_at > NOW() - INTERVAL '30 days'
GROUP BY DATE(created_at)
ORDER BY dzien DESC
LIMIT 10;
"

5. Informacje o modelu

curl -s http://localhost:5000/api/model-info 2>/dev/null || curl -s http://localhost:5001/api/model-info 2>/dev/null

Output:

Podsumuj w czytelnej formie:

Metryka Wartość
Konwersacje X
Wiadomości X
Tokeny (in/out) X / X
Koszt całkowity $X.XX
Śr. czas odpowiedzi X ms

Uwagi:

  • Google Gemini 3 Flash jest na free tier (0 cost)
  • Monitoruj tokeny dla kontroli limitów
  • Wysokie latency może wskazywać na problemy z API
  • DEV: docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz
  • PROD: ssh maciejpi@57.128.200.27 "sudo -u postgres psql -d nordabiz"