Skip to content

Commit

Permalink
Merge pull request #778 from MTES-MCT/fix-mediane
Browse files Browse the repository at this point in the history
Suppression de la droite médiane
  • Loading branch information
alexisig authored Dec 3, 2024
2 parents 0325be8 + 4b0e7d5 commit 0e1b61d
Showing 1 changed file with 6 additions and 67 deletions.
73 changes: 6 additions & 67 deletions project/charts/demography/PopulationConsoComparisonChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def param(self):
"title": {"text": "Évolution démographique (hab)"},
"plotLines": [{"color": "#000", "width": 1, "value": 0, "zIndex": 3}],
},
"yAxis": {"title": {"text": "Consommation d'espaces NAF (ha)"}, "maxPadding": 0.2, "min": 0},
"yAxis": {
"title": {"text": "Consommation d'espaces NAF (ha)"},
"maxPadding": 0.2,
"min": 0,
},
"tooltip": {
"pointFormat": (
"Consommation : <span class='fr-text--bold'>{point.y} ha</span><br />"
Expand Down Expand Up @@ -83,70 +87,5 @@ def get_bubble_series(self):
for land in lands
]

def get_trend_series(self):
pop_comparison = PublicDataContainer.population_comparison_service().get_by_land(
land=self.project.land_proxy,
start_date=int(self.project.analyse_start_date),
end_date=int(self.project.analyse_end_date),
)
pop_evolution_mediane = pop_comparison.evolution_median
conso_mediane = (
PublicDataContainer.consommation_comparison_service()
.get_by_land(
land=self.project.land_proxy,
start_date=int(self.project.analyse_start_date),
end_date=int(self.project.analyse_end_date),
)
.total_median
)
lands = self.project.comparison_lands_and_self_land()
start_date = int(self.project.analyse_start_date)
end_date = int(self.project.analyse_end_date)

population_evolution = [
p.evolution
for p in PublicDataContainer.population_stats_service().get_by_lands(lands, start_date, end_date)
]

max_population_evolution = max(population_evolution)
min_population_evolution = min(population_evolution)

max_conso = max(
[
c.total
for c in PublicDataContainer.consommation_stats_service().get_by_lands(lands, start_date, end_date)
]
)

middle_point = {"x": pop_evolution_mediane, "y": conso_mediane}
slope = (max_conso - conso_mediane) / (max_population_evolution - pop_evolution_mediane)
low_point = {
"x": min_population_evolution,
"y": conso_mediane + slope * (min_population_evolution - pop_evolution_mediane),
}
high_point = {
"x": max_population_evolution,
"y": conso_mediane + slope * (max_population_evolution - pop_evolution_mediane),
}

return [
{
"name": (
f"Médiane des {self.project.land.land_type_label.lower()}s<br>à "
f"l'échelle de {pop_comparison.land.name}"
),
"type": "line",
"color": "black",
"marker": {"enabled": False},
"enableMouseTracking": False,
"states": {"hover": {"enabled": False}},
"data": [
low_point,
middle_point,
high_point,
],
}
]

def add_series(self):
self.chart["series"] = self.get_bubble_series() + self.get_trend_series()
self.chart["series"] = self.get_bubble_series()

0 comments on commit 0e1b61d

Please sign in to comment.