Skip to content

feat(region): motore puro di aggregazione regionale (#228) - #244

Merged
gzileni merged 1 commit into
mainfrom
feat/region-aggregate-228
Jul 21, 2026
Merged

feat(region): motore puro di aggregazione regionale (#228)#244
gzileni merged 1 commit into
mainfrom
feat/region-aggregate-228

Conversation

@gzileni

@gzileni gzileni commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

F1 del cruscotto regionale (design #227). Motore puro opendata_core/region/ — nessun FastAPI/LLM/rete — che il backend (F2 #229) alimenterà con i dati del warehouse.

Cosa fa

aggregate_region(comuni, *, regione, cod_regione, comuni_totali=None) -> RegionOverview:

  • Distribuzione per stato riusando la macchina a stati [D13] Modello di accompagnamento attivo (macchina a stati zero→maturo) #184 (accompaniment_state): zero_dati / pochi_dati / in_crescita / maturo.
  • comuni_totali override: i comuni della regione senza sintesi contano come zero_dati (vista onesta anche quando pochi comuni sono valutati).
  • Mediana ODM sui soli comuni valutati.
  • Copertura HVD regionale: frazione di comuni con ≥1 dataset per categoria (HVD_LABELS).
  • Mediane per dimensione ODM.
  • dove_intervenire: comuni senza dati / con maturità < 40 (prima i senza-dati) + dimensioni ODM deboli (mediana < 50), come InterventionHint tipizzati.

Modelli

ComuneSummary (input iniettato), InterventionHint, RegionOverview.

Test

7 test (test_region_aggregate.py): distribuzione via macchina stati, override totali, mediana, copertura HVD, mediane dimensioni, dove-intervenire (zero-dati first + dimensione debole), regione vuota fail-safe. Core suite 390 passed, lint pulito.

Parte di #227 · sblocca F2 (#229, backend /regione/overview).

🤖 Generated with Claude Code

…227)

Prima fase del cruscotto regionale: motore PURO opendata_core/region/ (no
FastAPI/LLM/rete) che compone le sintesi-comune iniettate in una RegionOverview:
- distribuzione per stato riusando la macchina #184 (accompaniment_state);
- mediana ODM sui soli comuni valutati; comuni_totali override → mancanti = zero_dati;
- copertura HVD regionale (frazione comuni per categoria, HVD_LABELS);
- mediane per dimensione ODM;
- dove_intervenire: comuni senza dati / deboli (<40) + dimensioni deboli (<50).

Fail-safe su regione vuota. 7 test, core suite 390 passed, lint OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7511aa7366

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

`comuni_totali` (dall'anagrafica) può superare `len(comuni)` quando non tutti
i comuni hanno una sintesi: i mancanti contano come `zero_dati`.
"""
total = comuni_totali if comuni_totali is not None else len(comuni)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate totals before using them as denominators

When comuni_totali is lower than the number of summaries (for example because the anagrafica count and the joined assessment rows drift or contain duplicates), total is still used as the HVD denominator while every comuni entry is counted in the numerator and state distribution. That can produce impossible coverage values above 1.0 and a distribution whose sum exceeds comuni_totali; clamp or reject totals below len(comuni) before computing the KPIs.

Useful? React with 👍 / 👎.

@gzileni
gzileni merged commit bc3c86e into main Jul 21, 2026
27 checks passed
@gzileni
gzileni deleted the feat/region-aggregate-228 branch July 21, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant