Implement Dashboard consolidation + Performance logging
Features: - Add unified "Dashboard Complet" sheet (Excel) with all 9 sections - Add unified "Dashboard Complet" page (PDF) with key metrics - Fix VALOARE_ANTERIOARA NULL bug (use sumar_executiv_yoy directly) - Add PerformanceLogger class for timing analysis - Remove redundant consolidated sheets (keep only Dashboard Complet) Bug fixes: - Fix Excel formula error (=== interpreted as formula, changed to >>>) - Fix args.output → args.output_dir in perf.summary() Performance analysis: - Add PERFORMANCE_ANALYSIS.md with detailed breakdown - SQL queries take 94% of runtime (31 min), Excel/PDF only 1% - Identified slow queries for optimization Documentation: - Update CLAUDE.md with new structure - Add context handover for query optimization task 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
28
queries.py
28
queries.py
@@ -2075,7 +2075,8 @@ ranked_anterior AS (
|
||||
SELECT vanzari, ROW_NUMBER() OVER (ORDER BY vanzari DESC) AS rn
|
||||
FROM vanzari_anterior
|
||||
),
|
||||
metrics_anterior AS (
|
||||
-- Raw metrics for anterior (may have NULL if no data)
|
||||
metrics_anterior_raw AS (
|
||||
SELECT
|
||||
SUM(vanzari) AS total,
|
||||
SUM(CASE WHEN rn <= 1 THEN vanzari ELSE 0 END) AS top1,
|
||||
@@ -2083,15 +2084,25 @@ metrics_anterior AS (
|
||||
SUM(CASE WHEN rn <= 10 THEN vanzari ELSE 0 END) AS top10
|
||||
FROM ranked_anterior
|
||||
),
|
||||
-- Fallback to 0 for NULL values (when no anterior data exists)
|
||||
metrics_anterior AS (
|
||||
SELECT
|
||||
NVL(total, 0) AS total,
|
||||
NVL(top1, 0) AS top1,
|
||||
NVL(top5, 0) AS top5,
|
||||
NVL(top10, 0) AS top10
|
||||
FROM metrics_anterior_raw
|
||||
),
|
||||
-- Final metrics: just 1 row each, no cartesian product
|
||||
combined AS (
|
||||
SELECT
|
||||
ROUND(mc.top1 * 100.0 / NULLIF(mc.total, 0), 2) AS pct_curent_1,
|
||||
ROUND(ma.top1 * 100.0 / NULLIF(ma.total, 0), 2) AS pct_anterior_1,
|
||||
CASE WHEN ma.total = 0 THEN NULL ELSE ROUND(ma.top1 * 100.0 / ma.total, 2) END AS pct_anterior_1,
|
||||
ROUND(mc.top5 * 100.0 / NULLIF(mc.total, 0), 2) AS pct_curent_5,
|
||||
ROUND(ma.top5 * 100.0 / NULLIF(ma.total, 0), 2) AS pct_anterior_5,
|
||||
CASE WHEN ma.total = 0 THEN NULL ELSE ROUND(ma.top5 * 100.0 / ma.total, 2) END AS pct_anterior_5,
|
||||
ROUND(mc.top10 * 100.0 / NULLIF(mc.total, 0), 2) AS pct_curent_10,
|
||||
ROUND(ma.top10 * 100.0 / NULLIF(ma.total, 0), 2) AS pct_anterior_10
|
||||
CASE WHEN ma.total = 0 THEN NULL ELSE ROUND(ma.top10 * 100.0 / ma.total, 2) END AS pct_anterior_10,
|
||||
CASE WHEN ma.total > 0 THEN 1 ELSE 0 END AS has_anterior
|
||||
FROM metrics_curent mc
|
||||
CROSS JOIN metrics_anterior ma
|
||||
)
|
||||
@@ -2099,8 +2110,9 @@ SELECT
|
||||
'Top 1 client' AS indicator,
|
||||
pct_curent_1 AS procent_curent,
|
||||
pct_anterior_1 AS procent_anterior,
|
||||
ROUND(pct_curent_1 - pct_anterior_1, 2) AS variatie,
|
||||
CASE WHEN has_anterior = 1 THEN ROUND(pct_curent_1 - pct_anterior_1, 2) ELSE NULL END AS variatie,
|
||||
CASE
|
||||
WHEN has_anterior = 0 THEN 'FARA DATE YOY'
|
||||
WHEN pct_curent_1 < pct_anterior_1 THEN 'DIVERSIFICARE'
|
||||
WHEN pct_curent_1 > pct_anterior_1 + 5 THEN 'CONCENTRARE'
|
||||
ELSE 'STABIL'
|
||||
@@ -2111,8 +2123,9 @@ SELECT
|
||||
'Top 5 clienti' AS indicator,
|
||||
pct_curent_5 AS procent_curent,
|
||||
pct_anterior_5 AS procent_anterior,
|
||||
ROUND(pct_curent_5 - pct_anterior_5, 2) AS variatie,
|
||||
CASE WHEN has_anterior = 1 THEN ROUND(pct_curent_5 - pct_anterior_5, 2) ELSE NULL END AS variatie,
|
||||
CASE
|
||||
WHEN has_anterior = 0 THEN 'FARA DATE YOY'
|
||||
WHEN pct_curent_5 < pct_anterior_5 THEN 'DIVERSIFICARE'
|
||||
WHEN pct_curent_5 > pct_anterior_5 + 5 THEN 'CONCENTRARE'
|
||||
ELSE 'STABIL'
|
||||
@@ -2123,8 +2136,9 @@ SELECT
|
||||
'Top 10 clienti' AS indicator,
|
||||
pct_curent_10 AS procent_curent,
|
||||
pct_anterior_10 AS procent_anterior,
|
||||
ROUND(pct_curent_10 - pct_anterior_10, 2) AS variatie,
|
||||
CASE WHEN has_anterior = 1 THEN ROUND(pct_curent_10 - pct_anterior_10, 2) ELSE NULL END AS variatie,
|
||||
CASE
|
||||
WHEN has_anterior = 0 THEN 'FARA DATE YOY'
|
||||
WHEN pct_curent_10 < pct_anterior_10 THEN 'DIVERSIFICARE'
|
||||
WHEN pct_curent_10 > pct_anterior_10 + 5 THEN 'CONCENTRARE'
|
||||
ELSE 'STABIL'
|
||||
|
||||
Reference in New Issue
Block a user