Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utiliser les FAR plutôt que les DEP pour déterminer les engins de la marée #3088

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions datascience/src/pipeline/queries/monitorfish/current_catches.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ordered_deps AS (
ircs,
external_identification,
trip_number,
value->'gearOnboard' AS gear_onboard,
(value->>'departureDatetimeUtc')::timestamptz AS departure_datetime_utc,
ROW_NUMBER() OVER(PARTITION BY cfr ORDER BY (value->>'departureDatetimeUtc')::timestamptz DESC) as rk
FROM public.logbook_reports
Expand All @@ -30,8 +29,7 @@ last_deps AS (
ircs,
external_identification,
departure_datetime_utc,
trip_number,
gear_onboard
trip_number
FROM ordered_deps
WHERE rk=1
),
Expand All @@ -53,6 +51,8 @@ catches AS (
r.cfr,
r.report_id,
(jsonb_array_elements(r.value -> 'hauls'))->>'gear' as gear,
((jsonb_array_elements(r.value -> 'hauls'))->>'mesh')::DOUBLE PRECISION as mesh,
(jsonb_array_elements(r.value -> 'hauls'))->>'dimensions' as dimensions,
Comment on lines +54 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding NULL checks for mesh and dimensions fields to handle potential missing data gracefully.

- ((jsonb_array_elements(r.value -> 'hauls'))->>'mesh')::DOUBLE PRECISION as mesh,
- (jsonb_array_elements(r.value -> 'hauls'))->>'dimensions' as dimensions,
+ COALESCE(((jsonb_array_elements(r.value -> 'hauls'))->>'mesh')::DOUBLE PRECISION, 0) as mesh,
+ COALESCE((jsonb_array_elements(r.value -> 'hauls'))->>'dimensions', 'N/A') as dimensions,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
((jsonb_array_elements(r.value -> 'hauls'))->>'mesh')::DOUBLE PRECISION as mesh,
(jsonb_array_elements(r.value -> 'hauls'))->>'dimensions' as dimensions,
COALESCE(((jsonb_array_elements(r.value -> 'hauls'))->>'mesh')::DOUBLE PRECISION, 0) as mesh,
COALESCE((jsonb_array_elements(r.value -> 'hauls'))->>'dimensions', 'N/A') as dimensions,

jsonb_array_elements((jsonb_array_elements(r.value -> 'hauls'))->'catches')->>'species' as species,
(jsonb_array_elements((jsonb_array_elements(r.value -> 'hauls'))->'catches')->>'weight')::DOUBLE PRECISION as weight,
jsonb_array_elements((jsonb_array_elements(r.value -> 'hauls'))->'catches')->>'faoZone' as fao_area
Expand All @@ -76,6 +76,20 @@ summed_catches AS (
SUM(weight) as weight
FROM catches
GROUP BY cfr, species, gear, fao_area
),

gear_onboard AS (
SELECT
cfr,
jsonb_agg(DISTINCT
jsonb_build_object(
'gear', gear,
'mesh', mesh,
'dimensions', dimensions
)
) AS gear_onboard
FROM catches
GROUP BY cfr
)

SELECT
Expand All @@ -85,7 +99,7 @@ SELECT
last_logbook_reports.last_logbook_message_datetime_utc,
departure_datetime_utc,
trip_number,
gear_onboard,
go.gear_onboard,
species,
gear,
fao_area,
Expand All @@ -95,3 +109,5 @@ FULL OUTER JOIN last_deps
ON last_logbook_reports.cfr = last_deps.cfr
LEFT JOIN summed_catches
ON last_logbook_reports.cfr = summed_catches.cfr
LEFT JOIN gear_onboard go
ON last_logbook_reports.cfr = go.cfr
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def current_segments() -> pd.DataFrame:
],
"trip_number": ["20210001", "20210002"],
"gear_onboard": [
[{"gear": "OTM", "mesh": 80.0}],
[{"gear": "OTB", "mesh": 80.0}],
[{"gear": "OTM", "mesh": 80.0, "dimensions": None}],
[{"gear": "OTB", "mesh": 80.0, "dimensions": None}],
],
"species_onboard": [
[
Expand Down
Loading