Skip to content

Commit

Permalink
Merge pull request #521 from MTES-MCT/feature/instant-quality
Browse files Browse the repository at this point in the history
Haie / Les critères d'acceptabilité de la plantation sont affichés dynamiquement dans la saisie P (3/3)
  • Loading branch information
pyDez authored Jan 20, 2025
2 parents 7b57785 + dfcedc9 commit 587b378
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 161 deletions.
60 changes: 40 additions & 20 deletions envergo/hedges/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ def unfulfilled_conditions(self):

return self._evaluation_result.conditions

def evaluate(self):
"""Returns if the plantation is compliant with the regulation"""

evaluator = HedgeEvaluator(self.hedge_data)
evaluation = evaluator.evaluate()
result = EvaluationResult(
result=(
PlantationResults.Adequate
if all(evaluation[item]["result"] for item in evaluation.keys())
else PlantationResults.Inadequate
),
conditions=[
item for item in evaluation.keys() if not evaluation[item]["result"]
],
)

self._evaluation_result = result
return result


class HedgeEvaluator:
"""Evaluate the adequacy of a plantation project.
The plantation evaluator is used to evaluate if a project is compliant with the regulation.
"""

def __init__(self, hedge_data: HedgeData):
self.hedge_data = hedge_data
self.evaluate()

def is_not_planting_under_power_line(self):
"""Returns True if there is NO hedges to plant, containing high-growing trees (type alignement or mixte),
that are under power line"""
Expand Down Expand Up @@ -196,7 +226,7 @@ def evaluate_hedge_plantation_quality(self):
}

return {
"is_quality_sufficient": all(
"result": all(
[
missing_plantation["mixte"] == 0,
missing_plantation["alignement"] == 0,
Expand All @@ -210,23 +240,13 @@ def evaluate_hedge_plantation_quality(self):

def evaluate(self):
"""Returns if the plantation is compliant with the regulation"""
quality_evaluation = self.evaluate_hedge_plantation_quality()

conditions = {
"length_to_plant": self.is_length_to_plant_sufficient(),
"quality": quality_evaluation["is_quality_sufficient"],
"do_not_plant_under_power_line": self.is_not_planting_under_power_line(),
return {
"length_to_plant": {
"result": self.is_length_to_plant_sufficient(),
"minimum_length_to_plant": self.hedge_data.minimum_length_to_plant(),
},
"quality": self.evaluate_hedge_plantation_quality(),
"do_not_plant_under_power_line": {
"result": self.is_not_planting_under_power_line(),
},
}
result = EvaluationResult(
result=(
PlantationResults.Adequate
if all(conditions.values())
else PlantationResults.Inadequate
),
conditions=[
condition for condition in conditions if not conditions[condition]
],
)

self._evaluation_result = result
return result
Loading

0 comments on commit 587b378

Please sign in to comment.