diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bb7ff79703f2a4808891eef2692b8a69724dd22..cfb18e3be9462a4fca7031053c10a6f81303fd25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG +### 2.0.2 [!14](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/14) + +* Correction d'un crash. +* Détails : + * Corrige une erreur de type produisant une `error` pour toute requête à `/commune` suite à une évolution de `/calculate` + * Aligne le type de chaque commune type de `UiDisplayedImpacts.casTypes` de `/calculate` sur `ApiCommuneResponse` de `/commune` + ### 2.0.1 [!13](https://git.leximpact.dev/leximpact/simulateur-dotations-communes/leximpact-dotations-back/-/merge_requests/13) * Correction d'un crash technique. diff --git a/leximpact_dotations_back/computing/calculate_impact.py b/leximpact_dotations_back/computing/calculate_impact.py index 58b6936fd179b402e9cf30937a18ebae242365db..69751aa8546dd1a8ba8a6bce9b5df7be156c0b9b 100644 --- a/leximpact_dotations_back/computing/calculate_impact.py +++ b/leximpact_dotations_back/computing/calculate_impact.py @@ -1,7 +1,7 @@ import logging from leximpact_dotations_back.computing.dotations_simulation import DotationsSimulation -from leximpact_dotations_back.main_types import UiDisplayedImpacts +from leximpact_dotations_back.main_types import ApiCommuneRequest, UiDisplayedImpacts from leximpact_dotations_back.mapping.criteres_dgcl_2024 import montants_dotations_2024 from leximpact_dotations_back.computing.calculate_impact_commune import format_commune_impact @@ -13,13 +13,14 @@ from leximpact_dotations_back.computing.calculate_impact_total import format_tot logger = logging.getLogger() -def calculate_impact_base(dotation_simulation: DotationsSimulation, request_base, year_period) -> UiDisplayedImpacts: +def calculate_impact_base(dotation_simulation: DotationsSimulation, request_base: UiDisplayedImpacts, year_period) -> UiDisplayedImpacts: # construit la réponse en enrichissant le contenu de la requete base_response = request_base # conserve request_base.dotations # cas types - for commune_index, commune_request in enumerate(request_base.casTypes): + for commune_index, commune in enumerate(request_base.casTypes): + commune_request: ApiCommuneRequest = commune commune_impact = format_commune_impact(commune_request, dotation_simulation) base_response.casTypes[commune_index] = commune_impact diff --git a/leximpact_dotations_back/computing/calculate_impact_commune.py b/leximpact_dotations_back/computing/calculate_impact_commune.py index 67f9f864ce117717cd21d6287fc353f07aa7a04f..914f32fa66dc1e33d336345d48d9c9e88c84c1c7 100644 --- a/leximpact_dotations_back/computing/calculate_impact_commune.py +++ b/leximpact_dotations_back/computing/calculate_impact_commune.py @@ -19,8 +19,8 @@ def format_commune_impact( dotations_simulation: DotationsSimulation ) -> ApiCommuneResponse: - codeInseeCommune = str(commune["codeInseeCommune"]) - nomCommune = str(commune["nomCommune"]) + codeInseeCommune = str(commune.codeInseeCommune) + nomCommune = str(commune.nomCommune) commune_impact: ApiCommuneResponse = commune if dotations_simulation.adapted_criteres is None: @@ -37,7 +37,7 @@ def format_commune_impact( "nomCommune": nomCommune, # == commune_in_data.nom "codeInseeCommune": codeInseeCommune, # == commune_in_data.code_insee # TODO ajouter le "nomDepartement" récupéré via données de critères - "codeInseeDepartement": str(commune["codeInseeDepartement"]), + "codeInseeDepartement": str(commune.codeInseeDepartement), "nombreHabitants": int(commune_in_data.population_dgf.values[0]), "potentielFinancierParHabitant": float(commune_in_data.potentiel_financier_par_habitant.values[0]), # TODO tendanceReforme calculé par leximpact-dotations-ui diff --git a/leximpact_dotations_back/data_building/adapt_dotations_criteres.py b/leximpact_dotations_back/data_building/adapt_dotations_criteres.py index 5b609008b7552e6bd2fee33d6fe091cef6c97c6b..f912e624e57550359ea51ffed409804ebc4a681d 100644 --- a/leximpact_dotations_back/data_building/adapt_dotations_criteres.py +++ b/leximpact_dotations_back/data_building/adapt_dotations_criteres.py @@ -176,6 +176,7 @@ def corrige_revenu_moyen_strate( # ATTENTION FORMULE A VALIDER +# Calcul de la répartition par strate : population_dgf pour métier, population_insee pour l'UI def corrige_potentiel_moyen_strate( data, variables_openfisca_presentes_fichier, outre_mer_dgcl ): diff --git a/leximpact_dotations_back/main_types.py b/leximpact_dotations_back/main_types.py index b69772e4abbaf2fdc8dc5d6cae5476e254e26fc5..96423d93a2e42dd9b3995d6786c30cfda0951db5 100644 --- a/leximpact_dotations_back/main_types.py +++ b/leximpact_dotations_back/main_types.py @@ -49,7 +49,7 @@ class StrateImpact(BaseModel): class UiDisplayedImpacts(BaseModel): dotations: Optional[Dict[str, float]] = None # paramètres législatifs - casTypes: list # cas types de communes + casTypes: list[ApiCommuneResponse] # cas types de communes strates: list[StrateImpact] # strates de communes total: DotationSummaryTotal # communes gagantes / perdantes diff --git a/pyproject.toml b/pyproject.toml index 8d6c025b62926256cb0277728c738d66248210fc..40a37ffceb1d1272f26e6488f4795ddccfe1819c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "leximpact-dotations-back" -version = "2.0.1" +version = "2.0.2" description = "Simulating annual State grants to the French administrative divisions" authors = ["LexImpact <leximpact@assemblee-nationale.fr>"] license = "AGPL-3.0-or-later"