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
…0kg (#4047)

## Linked issues

- Resolve #3912
  • Loading branch information
VincentAntoine authored Jan 27, 2025
2 parents 96ea498 + 46ebb0c commit 96db003
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
23 changes: 21 additions & 2 deletions datascience/src/pipeline/helpers/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,19 @@ def allocate_segments_to_catches(
) / (
SUM(weight)
OVER (PARTITION BY { batch_id_column }, s.segment)
) AS share_of_target_species
) AS share_of_target_species,
(
SUM(
CASE WHEN
c.species = ANY(s.target_species)
THEN
1
ELSE
0
END
)
OVER (PARTITION BY { batch_id_column }, s.segment)
) > 0 AS has_target_species
FROM catches_main_type c
JOIN segments s
Expand All @@ -135,7 +147,14 @@ def allocate_segments_to_catches(
AND (c.mesh < s.max_mesh OR s.max_mesh IS NULL)
AND (c.vessel_type = ANY(s.vessel_types) OR s.vessel_types = [])
AND (s.main_scip_species_type = c.main_scip_species_type OR s.main_scip_species_type IS NULL)
QUALIFY (share_of_target_species > s.min_share_of_target_species OR s.min_share_of_target_species IS NULL OR s.target_species = [])
QUALIFY (
(
has_target_species AND
share_of_target_species >= s.min_share_of_target_species
) OR
s.min_share_of_target_species IS NULL OR
s.target_species = []
)
),
catches_top_priority_segment AS (
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 @@ -29,3 +29,5 @@
30,"trip_T8-9",2050,"27.8.a","OTB",90,"GHI",,15000,"Navire polyvalent","T8-9","Trawls areas 8 and 9 targeting demersal","2.2"
31,"trip_L-HKE",2050,"27.8.a","LLS",,"HKE","DEMERSAL",120,"Navire polyvalent","L HKE","Lines targeting HKE","2.2"
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"
1 change: 1 addition & 0 deletions datascience/tests/test_data/csv/segments.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Old-T8-PEL,Old trawls area 8 targeting pelagic,2000,"[""OTM"",""OTB"",""PTM"",""
L,Lines,2050,"[""LLS"",""LLM"",""LHM"",""LHP""]",,,"[""27"",""37""]",[],,,[],1.9,0
L HKE,Lines targeting HKE,2050,"[""LLS"",""LLM"",""LHM"",""LHP""]",,,"[""27"",""37""]","[""HKE"",""AAA"",""BBB""]",0.2,,[],2.2,1
FT,Freezer trawlers,2050,"[""OTB"",""PTB""]",80,100,"[""27"",""37""]",[],,,"[""Chalutier congélateur"",""Chalutier pêche arrière congélateur""]",3.3,2
L BFT,Lines targeting BFT,2050,"[""LLS"",""LLM"",""LHM"",""LHP""]",,,"[""27"",""37""]","[""BFT""]",0.0,,[],2.2,3

0 comments on commit 96db003

Please sign in to comment.