Skip to content

Commit

Permalink
Fix prior notification seafront calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed May 28, 2024
1 parent e2160a1 commit 90658f6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class GetPriorNotification(
null
}

val seafront = port?.facade?.let { Seafront.valueOf(it) }
val seafront: Seafront? = port?.facade?.let { Seafront.from(it) }

// Default to UNKNOWN vessel when null or not found
val vessel = priorNotification.logbookMessageTyped.logbookMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class GetPriorNotifications(
allRiskFactors.find { it.internalReferenceNumber == vesselInternalReferenceNumber }
}

val seafront: Seafront? = port?.facade?.let { Seafront.valueOf(it) }
val seafront: Seafront? = port?.facade?.let { Seafront.from(it) }

val finalPriorNotification = priorNotification.copy(
port = port,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
insert into ports (country_code_iso2, facade, region, locode, port_name, latitude, longitude, fao_areas, is_active)
values ('AD', null, null, 'ADALV', 'Andorra la Vella', 42.5, 1.01666666666667, ARRAY ['27.8'], true),
('FR', 'Guadeloupe', null, 'FRZEG', 'Auray', 47.666491, -2.983767, ARRAY ['27.7', '27.7.b'], true),
('AE', 'Guadeloupe', null, 'AEABU', 'Abu al Bukhoosh', 25.4833333333333, 53.05, null, true),
('AE', 'Guadeloupe', 'AZ', 'AEAUH', 'Abu Dhabi', 24.4666666666667, 54.0666666666667, null, false),
('AE', 'Guadeloupe', null, 'AEAMU', 'Abu Musa', 25.8666666666667, 55.0833333333333, null, true),
('AE', null, 'AZ', 'AEARP', 'Ahmed Bin Rashid Port', 25.5333333333333, 55.0833333333333, null, true),
('AE', 'NAMO', null, 'AEAJM', 'Ajman', null, null, null, true),
('AE', 'NAMO', 'FU', 'AEFJR', 'Al Fujayrah', 25.1166666666667, 56.1, null, true),
('AE', 'NAMO', 'RK', 'AEJAZ', 'Al Jazeera Port', 25.7166666666667, 55.0833333333333, null, true),
('AE', 'NAMO', 'RK', 'AEAJP', 'Al Jeer Port', 26.0333333333333, 56.1, null, true),
('AE', 'NAMO', null, 'AERUW', 'Ar Ruways', 24.1166666666667, 52.0333333333333, null, true),
('AE', null, null, 'AEARZ', 'Arzanah Island', null, null, null, true),
('AE', null, null, 'AEDAS', 'Das Island', null, null, null, false),
('AE', 'SA', 'SH', 'AEDBP', 'Dibba', 25.6166666666667, 56.1, null, true),
('AE', 'SA', 'DU', 'AEDXB', 'Dubai', 25.25, 55.0833333333333, null, true),
('AE', 'SA', 'AZ', 'AEEND', 'Esnnad', 24.3166666666667, 54.0666666666667, null, false),
('AE', 'SA', null, 'AEFAT', 'Fateh Terminal', null, null, null, true),
('AE', 'SA', 'DU', 'AEFRP', 'Free Port', 25.25, 55.0833333333333, null, true),
('AE', null, 'DU', 'AEHZP', 'Hamriya Free Zone Port', 25.3, 55.0833333333333, null, true),
('AE', null, 'DU', 'AEHSN', 'Hassyan', 24.9, 54.0666666666667, null, false),
('AE', null, null, 'AEHTL', 'Hulaylah Terminal', 25.9833333333333, 55.0833333333333, null, true),
INSERT INTO ports (
country_code_iso2, facade, region, locode, port_name, latitude, longitude, fao_areas, is_active)
VALUES
( 'AD', null, null, 'ADALV', 'Andorra la Vella', 42.5, 1.01666666666667, ARRAY ['27.8'], true),
( 'FR', 'Guadeloupe', null, 'FRZEG', 'Auray', 47.666491, -2.983767, ARRAY ['27.7', '27.7.b'], true),
( 'AE', 'Guadeloupe', null, 'AEABU', 'Abu al Bukhoosh', 25.4833333333333, 53.05, null, true),
( 'AE', 'Guadeloupe', 'AZ', 'AEAUH', 'Abu Dhabi', 24.4666666666667, 54.0666666666667, null, false),
( 'AE', 'Guadeloupe', null, 'AEAMU', 'Abu Musa', 25.8666666666667, 55.0833333333333, null, true),
( 'AE', null, 'AZ', 'AEARP', 'Ahmed Bin Rashid Port', 25.5333333333333, 55.0833333333333, null, true),
( 'AE', 'NAMO', null, 'AEAJM', 'Ajman', null, null, null, true),
( 'AE', 'NAMO', 'FU', 'AEFJR', 'Al Fujayrah', 25.1166666666667, 56.1, null, true),
( 'AE', 'NAMO', 'RK', 'AEJAZ', 'Al Jazeera Port', 25.7166666666667, 55.0833333333333, null, true),
( 'AE', 'NAMO', 'RK', 'AEAJP', 'Al Jeer Port', 26.0333333333333, 56.1, null, true),
( 'AE', 'NAMO', null, 'AERUW', 'Ar Ruways', 24.1166666666667, 52.0333333333333, null, true),
( 'AE', null, null, 'AEARZ', 'Arzanah Island', null, null, null, true),
( 'AE', null, null, 'AEDAS', 'Das Island', null, null, null, false),
( 'AE', 'SA', 'SH', 'AEDBP', 'Dibba', 25.6166666666667, 56.1, null, true),
( 'AE', 'SA', 'DU', 'AEDXB', 'Dubai', 25.25, 55.0833333333333, null, true),
( 'AE', 'SA', 'AZ', 'AEEND', 'Esnnad', 24.3166666666667, 54.0666666666667, null, false),
( 'AE', 'SA', null, 'AEFAT', 'Fateh Terminal', null, null, null, true),
( 'AE', 'SA', 'DU', 'AEFRP', 'Free Port', 25.25, 55.0833333333333, null, true),
( 'AE', null, 'DU', 'AEHZP', 'Hamriya Free Zone Port', 25.3, 55.0833333333333, null, true),
( 'AE', null, 'DU', 'AEHSN', 'Hassyan', 24.9, 54.0666666666667, null, false),
( 'AE', null, null, 'AEHTL', 'Hulaylah Terminal', 25.9833333333333, 55.0833333333333, null, true),

-- https://service.unece.org/trade/locode/fr.htm
('FR', 'NAMO', '29', 'FRBES', 'Brest', 48.24, 4.29, null, true),
('FR', 'MEMN', '13', 'FRMRS', 'Marseille', 43.18, 5.24, null, true),
('FR', 'MEMN', '06', 'FRNCE', 'Nice', 43.42, 7.16, null, true),
('FR', 'NAMO', '35', 'FRSML', 'Saint-Malo', 48.39, 2.01, null, true),
('FR', 'NAMO', '56', 'FRVNE', 'Vannes', 47.39, 2.46, null, true);
-- https://service.unece.org/trade/locode/fr.htm
( 'FR', 'NAMO', '29', 'FRBES', 'Brest', 48.24, 4.29, null, true),
( 'FR', 'MEMN', '13', 'FRMRS', 'Marseille', 43.18, 5.24, null, true),
( 'FR', 'MEMN', '06', 'FRNCE', 'Nice', 43.42, 7.16, null, true),
( 'FR', 'NAMO', '35', 'FRSML', 'Saint-Malo', 48.39, 2.01, null, true),
( 'FR', 'NAMO', '56', 'FRVNE', 'Vannes', 47.39, 2.46, null, true),
( 'RE', 'Sud Océan Indien', '974', 'REZSE', 'Saint-Denis De La Réunion', -20.88, 55.45, ARRAY ['51.6', '51.7'], true);
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ INSERT INTO logbook_raw_messages (operation_number, xml_message) VALUES ('FAKE_O

INSERT INTO logbook_raw_messages (operation_number, xml_message) VALUES ('FAKE_OPERATION_114', '<Flux>Message FLUX xml</Flux>');

INSERT INTO logbook_raw_messages (operation_number, xml_message) VALUES ('FAKE_OPERATION_115', '<Flux>Message FLUX xml</Flux>');

INSERT INTO logbook_reports (id, report_id, referenced_report_id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (101, 'FAKE_OPERATION_101', NULL, 'FAK000999999', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'FAKE_OPERATION_101', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '15 minutes', 'ERS', 'PHENOMENE', '[{"gear":"TBN","mesh":100,"dimensions":"250;180"},{"gear":"OTT","mesh":120.5,"dimensions":"250;280"}]', '[{"segment":"SWW04","segmentName":"Chaluts pélagiques"},{"segment":"SWW06","segmentName":"Sennes"}]', '{"catchOnboard":[{"weight":25,"nbFish":null,"species":"COD","faoZone":"27.8.a","effortZone":"C","economicZone":"FRA","statisticalRectangle":"23E6"}],"pnoTypes":[{"pnoTypeName":"Préavis type A","minimumNotificationPeriod":4,"hasDesignatedPorts":false},{"pnoTypeName":"Préavis type B","minimumNotificationPeriod":8,"hasDesignatedPorts":true}],"port":"FRSML","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '3.5 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 101;
Expand Down Expand Up @@ -108,3 +110,8 @@ INSERT INTO logbook_reports (id, report_id, referenced_report_id, cfr, enriched,
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 114;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 114;
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 114;

INSERT INTO logbook_reports (id, report_id, referenced_report_id, cfr, enriched, flag_state, integration_datetime_utc, log_type, operation_datetime_utc, operation_number, operation_type, report_datetime_utc, transmission_format, vessel_name, trip_gears, trip_segments, value) VALUES (115, 'FAKE_OPERATION_115', NULL, 'CFR110', true, 'FRA', NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours', 'PNO', NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours', 'FAKE_OPERATION_115', 'DAT', NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours', 'ERS', 'LA MER À BOIRE', '[]', '[]', '{"catchOnboard":[],"pnoTypes":[],"port":"REZSE","predictedArrivalDatetimeUtc":null,"predictedLandingDatetimeUtc":null,"purpose":"LAN","tripStartDate":null}');
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedArrivalDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 115;
UPDATE logbook_reports SET value = JSONB_SET(value, '{predictedLandingDatetimeUtc}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 115;
UPDATE logbook_reports SET value = JSONB_SET(value, '{tripStartDate}', TO_JSONB(TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')), true) WHERE id = 115;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
{ "operation_number": "FAKE_OPERATION_111_COR_ORPHAN", "xml_message": "<Flux>Message FLUX xml</Flux>" },
{ "operation_number": "FAKE_OPERATION_112", "xml_message": "<Flux>Message FLUX xml</Flux>" },
{ "operation_number": "FAKE_OPERATION_113", "xml_message": "<Flux>Message FLUX xml</Flux>" },
{ "operation_number": "FAKE_OPERATION_114", "xml_message": "<Flux>Message FLUX xml</Flux>" }
{ "operation_number": "FAKE_OPERATION_114", "xml_message": "<Flux>Message FLUX xml</Flux>" },
{ "operation_number": "FAKE_OPERATION_115", "xml_message": "<Flux>Message FLUX xml</Flux>" }
]
},
{
Expand Down Expand Up @@ -842,6 +843,36 @@
"purpose": "LAN",
"tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')"
}
},

// - Vessel: LA MER À BOIRE
// - Port: Saint-Denis De La Réunion (Sud Océan Indien)
{
"id": 115,
"report_id": "FAKE_OPERATION_115",
"referenced_report_id": null,
"cfr": "CFR110",
"enriched": true,
"flag_state": "FRA",
"integration_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours'",
"log_type": "PNO",
"operation_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours'",
"operation_number": "FAKE_OPERATION_115",
"operation_type": "DAT",
"report_datetime_utc:sql": "NOW() AT TIME ZONE 'UTC' - INTERVAL '6 hours'",
"transmission_format": "ERS",
"vessel_name": "LA MER À BOIRE",
"trip_gears:jsonb": [],
"trip_segments:jsonb": [],
"value:jsonb": {
"catchOnboard": [],
"pnoTypes": [],
"port": "REZSE",
"predictedArrivalDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '1 hour', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"predictedLandingDatetimeUtc:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' + INTERVAL '2 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')",
"purpose": "LAN",
"tripStartDate:sql": "TO_CHAR(NOW() AT TIME ZONE 'UTC' - INTERVAL '20 hours', 'YYYY-MM-DD\"T\"HH24:MI:SS\"Z\"')"
}
}
]
}
Expand Down

0 comments on commit 90658f6

Please sign in to comment.