Skip to content

Commit

Permalink
Corriger l'attribution de segments dans le cas d'espèces cibles avec …
Browse files Browse the repository at this point in the history
…quantités NULL (#4049)

## Linked issues

- Resolve #3912
  • Loading branch information
VincentAntoine authored Jan 27, 2025
2 parents 96db003 + 69712a9 commit 1d6390b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 18 additions & 15 deletions datascience/src/pipeline/helpers/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,24 @@ def allocate_segments_to_catches(
s.segment_name,
s.impact_risk_factor,
s.priority AS priority,
(
SUM(
CASE WHEN
c.species = ANY(s.target_species) OR
s.target_species = []
THEN
weight
ELSE
0
END
)
OVER (PARTITION BY { batch_id_column }, s.segment)
) / (
SUM(weight)
OVER (PARTITION BY { batch_id_column }, s.segment)
COALESCE(
(
SUM(
CASE WHEN
c.species = ANY(s.target_species) OR
s.target_species = []
THEN
weight
ELSE
0
END
)
OVER (PARTITION BY { batch_id_column }, s.segment)
) / (
SUM(weight)
OVER (PARTITION BY { batch_id_column }, s.segment)
),
0
) AS share_of_target_species,
(
SUM(
Expand Down
2 changes: 2 additions & 0 deletions datascience/tests/test_data/csv/catches.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@
32,"trip_L-HKE",2050,"27.8.a","LLS",,"COD","DEMERSAL",50,"Navire polyvalent","L HKE","Lines targeting HKE","2.2"
33,"trip_L-BFT-0kg",2050,"27.8.a","LLS",,"BFT","DEMERSAL",0,"Navire polyvalent","L BFT","Lines targeting BFT","2.2"
34,"trip_L-BFT-0kg",2050,"27.8.a","LLS",,"HKE","DEMERSAL",50,"Navire polyvalent","L BFT","Lines targeting BFT","2.2"
35,"trip_L-BFT-0kg-total",2050,"27.8.a","LLS",,"BFT","DEMERSAL",0,"Navire polyvalent","L BFT","Lines targeting BFT","2.2"
36,"trip_L-BFT-null-kg",2050,"27.8.a","LLS",,"BFT","DEMERSAL",,"Navire polyvalent","L BFT","Lines targeting BFT","2.2"

0 comments on commit 1d6390b

Please sign in to comment.