The documentation incorrectly stated that DEV environment uses SQLite when it actually uses PostgreSQL via Docker on localhost:5433. Updated files: - CLAUDE.md - main project instructions - PROJECT_INFO.md - environment documentation - deployment_checklist.md - deployment procedures - SCRIPTS_INDEX.md - script usage commands - .claude/commands/*.md - all slash command definitions - tests/test_admin_seo_dashboard.py - test database URL DEV environment: - PostgreSQL via Docker: localhost:5433 - Container: nordabiz-postgres - Database: nordabiz - User: nordabiz_app PROD environment: - PostgreSQL: 10.22.68.249:5432 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3.4 KiB
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 2.0 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@10.22.68.249 "sudo -u postgres psql -d nordabiz"