From f311d75c73317f1508cef03e4776fdff363875c9 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Wed, 27 Mar 2024 10:52:12 +0100 Subject: [PATCH] added ata_atd and time_point_ref fields to database, yaml and python access layer --- misc/BreCalApi.yaml | 9 +++++++++ misc/update_1.1_to_1.2.sql | 9 +++++++-- src/server/BreCal/impl/shipcalls.py | 2 +- src/server/BreCal/impl/times.py | 2 +- src/server/BreCal/schemas/model.py | 9 +++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/misc/BreCalApi.yaml b/misc/BreCalApi.yaml index 78f7ad8..1b8f578 100644 --- a/misc/BreCalApi.yaml +++ b/misc/BreCalApi.yaml @@ -562,6 +562,10 @@ components: maxLength: 512 type: string nullable: true + time_ref_point: + type: integer + nullable: true + description: Physical reference point for all times given in shipcall and depending times entries participants: type: array items: @@ -660,6 +664,11 @@ components: nullable: true participant_type: type: integer + ata_atd: + type: string + format: date-time + nullable: true + description: can be set by mooring if actual times are different from planned created: type: string format: date-time diff --git a/misc/update_1.1_to_1.2.sql b/misc/update_1.1_to_1.2.sql index 2e2afef..0e31388 100644 --- a/misc/update_1.1_to_1.2.sql +++ b/misc/update_1.1_to_1.2.sql @@ -4,8 +4,8 @@ ALTER TABLE `bremen_calling_devel`.`shipcall` ADD COLUMN `evaluation_time` DATETIME NULL DEFAULT NULL AFTER `evaluation_message`, -ADD COLUMN `evaluation_notifications_sent` BIT NULL AFTER `evaluation_time`; - +ADD COLUMN `evaluation_notifications_sent` BIT NULL AFTER `evaluation_time`, +ADD COLUMN `time_ref_point` INT NULL DEFAULT 0 COMMENT 'Index of a location which is the reference point for all time value entries, e.g. berth or Geeste' AFTER `modified`; -- prepare notification table for historic notification data @@ -85,3 +85,8 @@ ADD CONSTRAINT `FK_HISTORY_USER` REFERENCES `bremen_calling_devel`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; + +-- add ata_atd field to times + +ALTER TABLE `bremen_calling_devel`.`times` +ADD COLUMN `ata_atd` DATETIME NULL DEFAULT NULL COMMENT 'Relevant only for mooring, this field can be used to record actual ATA / ATD' AFTER `participant_type`; \ No newline at end of file diff --git a/src/server/BreCal/impl/shipcalls.py b/src/server/BreCal/impl/shipcalls.py index 4a6faa8..733f516 100644 --- a/src/server/BreCal/impl/shipcalls.py +++ b/src/server/BreCal/impl/shipcalls.py @@ -21,7 +21,7 @@ def GetShipcalls(options): query = ("SELECT s.id as id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " + "flags, s.pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, " + "tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, " + - "evaluation_message, evaluation_time, evaluation_notifications_sent, s.created as created, s.modified as modified " + + "evaluation_message, evaluation_time, evaluation_notifications_sent, s.created as created, s.modified as modified, time_ref_point " + "FROM shipcall s " + "LEFT JOIN times t ON t.shipcall_id = s.id AND t.participant_type = 8 " + "WHERE " + diff --git a/src/server/BreCal/impl/times.py b/src/server/BreCal/impl/times.py index 5dd3851..5fff877 100644 --- a/src/server/BreCal/impl/times.py +++ b/src/server/BreCal/impl/times.py @@ -22,7 +22,7 @@ def GetTimes(options): commands = pydapper.using(pooledConnection) data = commands.query("SELECT id, eta_berth, eta_berth_fixed, etd_berth, etd_berth_fixed, lock_time, lock_time_fixed, " + "zone_entry, zone_entry_fixed, operations_start, operations_end, remarks, shipcall_id, participant_id, " + - "berth_id, berth_info, pier_side, participant_type, created, modified FROM times " + + "berth_id, berth_info, pier_side, participant_type, created, modified, ata_atd FROM times " + "WHERE times.shipcall_id = ?scid?", model=model.Times, param={"scid" : options["shipcall_id"]}) pooledConnection.close() diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index 89c52ed..5a2c15f 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -176,6 +176,7 @@ class ShipcallSchema(Schema): evaluation_message = fields.Str(allow_none=True, metadata={'Required':False}) # Solving: RemovedInMarshmallow4Warning: Passing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: {'Required': False} evaluation_time = fields.DateTime(Required = False, allow_none=True) evaluation_notifications_sent = fields.Bool(Required = False, allow_none=True) + time_ref_point = fields.Int(Required = False, allow_none=True) participants = fields.List(fields.Nested(ParticipantAssignmentSchema)) created = fields.DateTime(Required = False, allow_none=True) modified = fields.DateTime(Required = False, allow_none=True) @@ -221,6 +222,7 @@ class Shipcall: evaluation_message: str evaluation_time: datetime evaluation_notifications_sent: bool + time_ref_point: int created: datetime modified: datetime participants: List[Participant_Assignment] = field(default_factory=list) @@ -254,6 +256,7 @@ class Shipcall: "evaluation_message": self.evaluation_message, "evaluation_time": self.evaluation_time.isoformat() if self.evaluation_time else "", "evaluation_notifications_sent": self.evaluation_notifications_sent, + "time_ref_point": self.time_ref_point, "created": self.created.isoformat() if self.created else "", "modified": self.modified.isoformat() if self.modified else "", "participants": [participant.__dict__ for participant in self.participants] @@ -262,8 +265,8 @@ class Shipcall: @classmethod - def from_query_row(self, id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, flags, pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, evaluation_message, evaluation_time, evaluation_notifications_sent, created, modified): - return self(id, ship_id, ShipcallType(type), eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, flags, pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, EvaluationType(evaluation), evaluation_message, evaluation_time, evaluation_notifications_sent, created, modified) + def from_query_row(self, id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, flags, pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, evaluation_message, evaluation_time, evaluation_notifications_sent, time_ref_point, created, modified): + return self(id, ship_id, ShipcallType(type), eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, flags, pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, EvaluationType(evaluation), evaluation_message, evaluation_time, evaluation_notifications_sent, time_ref_point, created, modified) class ShipcallId(Schema): pass @@ -293,6 +296,7 @@ class TimesSchema(Schema): pier_side = fields.Bool(Required = False, allow_none = True) shipcall_id = fields.Int(Required = True) participant_type = fields.Int(Required = False, allow_none=True) + ata_atd = fields.DateTime(Required = False, allow_none=True) created = fields.DateTime(Required = False, allow_none=True) modified = fields.DateTime(Required = False, allow_none=True) @@ -330,6 +334,7 @@ class Times: pier_side: bool participant_type: int shipcall_id: int + ata_atd: datetime created: datetime modified: datetime