Skip to content

Commit

Permalink
Fix ack message computation in pno distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentAntoine committed Aug 21, 2024
1 parent 6ecdc8b commit fb580e1
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions datascience/src/pipeline/queries/monitorfish/pnos_to_generate.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
WITH deleted_messages AS (
SELECT referenced_report_id
SELECT
operation_number,
referenced_report_id
FROM logbook_reports
WHERE
operation_datetime_utc >= :start_datetime_utc - INTERVAL '4 hours'
Expand All @@ -15,6 +17,13 @@ acknowledged_messages AS (
AND operation_datetime_utc < :end_datetime_utc + INTERVAL '8 hours'
AND operation_type ='RET'
AND value->>'returnStatus' = '000'
),

acknowledged_deleted_messages AS (
SELECT referenced_report_id
FROM deleted_messages
WHERE
operation_number IN (SELECT referenced_report_id FROM acknowledged_messages)
)

(SELECT DISTINCT ON (r.report_id) -- In rare cases the same PNO with the same data and the same report_id is sent multiple times in messages with different operation numbers
Expand Down Expand Up @@ -65,14 +74,17 @@ WHERE
(value->>'isBeingSent')::BOOLEAN IS true
OR report_id NOT IN (SELECT report_id FROM prior_notification_pdf_documents)
)
AND report_id NOT IN (SELECT referenced_report_id FROM deleted_messages)
AND NOT (
report_id IN (SELECT referenced_report_id FROM acknowledged_deleted_messages)
OR (
report_id IN (SELECT referenced_report_id FROM deleted_messages)
AND r.flag_state NOT IN ('FRA', 'GUF', 'VEN')
)
)
AND (
transmission_format = 'FLUX'
r.flag_state NOT IN ('FRA', 'GUF', 'VEN') -- Flag states for which we receive RET
OR report_id IN (SELECT referenced_report_id FROM acknowledged_messages)
OR (value->>'isVerified')::BOOLEAN IS true
OR (
transmission_format = 'ERS'
AND report_id IN (SELECT referenced_report_id FROM acknowledged_messages)
)
)
AND (
(value->>'isInvalidated') IS NULL
Expand Down

0 comments on commit fb580e1

Please sign in to comment.