Skip to content

Commit

Permalink
Write tests for bcae8 evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Nov 28, 2024
1 parent fec6507 commit a9c74eb
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 92 deletions.
14 changes: 14 additions & 0 deletions envergo/hedges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ def hedges_to_remove(self):

def length_to_remove(self):
return round(sum(h.length for h in self.hedges_to_remove()))

def lineaire_detruit_pac(self):
return sum(
h.length
for h in self.hedges_to_remove()
if h.is_on_pac and h.hedge_type != "alignement"
)

def lineaire_type_4_sur_parcelle_pac(self):
return sum(
h.length
for h in self.hedges_to_remove()
if h.is_on_pac and h.hedge_type == "alignement"
)
15 changes: 3 additions & 12 deletions envergo/moulinette/regulations/conditionnalitepac.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ def get_catalog_data(self):
lineaire_type_4_sur_parcelle_pac = 0
if "lineaire_total" in self.catalog:
haies = self.catalog["haies"]
for haie in haies:
if haie.is_on_pac and haie.hedge_type == "alignement":
lineaire_type_4_sur_parcelle_pac += haie.length
lineaire_type_4_sur_parcelle_pac = haies.lineaire_type_4_sur_parcelle_pac()
catalog["lineaire_type_4_sur_parcelle_pac"] = lineaire_type_4_sur_parcelle_pac

return catalog
Expand All @@ -162,19 +160,12 @@ def get_result_data(self):
is_small = False
haies = self.catalog["haies"]
lineaire_detruit_pac = 0
lineaire_type_4_sur_parcelle_pac = 0
ratio_detruit = 0
if "lineaire_total" in self.catalog:
lineaire_total = self.catalog["lineaire_total"]
for haie in haies:
if haie.is_on_pac and haie.hedge_type != "alignement":
lineaire_detruit_pac += haie.length

if haie.is_on_pac and haie.hedge_type == "alignement":
lineaire_type_4_sur_parcelle_pac += haie.length

lineaire_detruit_pac = haies.lineaire_detruit_pac()
ratio_detruit = lineaire_detruit_pac / lineaire_total
is_small = ratio_detruit <= 2 or lineaire_detruit_pac <= 5
is_small = ratio_detruit <= 0.02 or lineaire_detruit_pac <= 5

return (
# Main vars
Expand Down
Loading

0 comments on commit a9c74eb

Please sign in to comment.