From a4b70006f9cc8eeea96a954daee8a4ab7eb90e24 Mon Sep 17 00:00:00 2001 From: max_metz Date: Fri, 8 Sep 2023 15:33:06 +0200 Subject: [PATCH] creating stub classes and functions for every dataclass object. This will be the foundation for the traffic-light system, as the tests will be based on artificial entries (stubs) instead of data from the real system. tests will be added soon. --- .gitignore | 3 + .../brecal_utils/stubs/__init__.py | 5 ++ .../brecal_utils/stubs/berth.py | 27 +++++++ .../brecal_utils/stubs/participant.py | 32 ++++++++ .../brecal_utils/stubs/roles.py | 0 .../brecal_utils/stubs/ship.py | 39 ++++++++++ .../brecal_utils/stubs/shipcall.py | 76 +++++++++++++++++++ .../brecal_utils/stubs/times_agency.py | 0 .../brecal_utils/stubs/times_full.py | 5 ++ .../brecal_utils/stubs/times_mooring.py | 0 .../brecal_utils/stubs/times_pilot.py | 0 .../brecal_utils/stubs/times_portauthority.py | 0 .../brecal_utils/stubs/times_terminal.py | 0 .../brecal_utils/stubs/times_tug.py | 0 .../brecal_utils/stubs/tugs.py | 6 ++ .../brecal_utils/stubs/user.py | 35 +++++++++ 16 files changed, 228 insertions(+) create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/__init__.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/berth.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/participant.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/roles.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/ship.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/shipcall.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_agency.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_full.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_mooring.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_pilot.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_portauthority.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_terminal.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/times_tug.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/tugs.py create mode 100644 src/lib_brecal_utils/brecal_utils/stubs/user.py diff --git a/.gitignore b/.gitignore index 5f08e6a..37ee301 100644 --- a/.gitignore +++ b/.gitignore @@ -439,4 +439,7 @@ FodyWeavers.xsd change_log_metz.md src/notebooks_metz **.egg-info +docs/traffic_light_examples +**/.~lock* +misc/berths_and_terminals.csv diff --git a/src/lib_brecal_utils/brecal_utils/stubs/__init__.py b/src/lib_brecal_utils/brecal_utils/stubs/__init__.py new file mode 100644 index 0000000..0516049 --- /dev/null +++ b/src/lib_brecal_utils/brecal_utils/stubs/__init__.py @@ -0,0 +1,5 @@ + +def generate_uuid1_int(): + """# TODO: clarify, what kind of integer ID is used in mysql""" + from uuid import uuid1 + return uuid1().int>>64 diff --git a/src/lib_brecal_utils/brecal_utils/stubs/berth.py b/src/lib_brecal_utils/brecal_utils/stubs/berth.py new file mode 100644 index 0000000..a335c18 --- /dev/null +++ b/src/lib_brecal_utils/brecal_utils/stubs/berth.py @@ -0,0 +1,27 @@ +import datetime +from brecal_utils.stubs import generate_uuid1_int +from BreCal.schemas.model import Berth + +def get_berth_simple(): + berth_id = generate_uuid1_int() # uid? + + # Note: #TODO: name, participant_id & lock state are arbitrary + name = "Avangard Dalben" + participant_id = 1 # e.g., Avangard + lock = False + + created = datetime.datetime.now() + modified = created+datetime.timedelta(seconds=10) + deleted = modified+datetime.timedelta(seconds=3) + + berth = Berth( + berth_id, + name, + participant_id, + lock, + created, + modified, + deleted, + ) + return berth + diff --git a/src/lib_brecal_utils/brecal_utils/stubs/participant.py b/src/lib_brecal_utils/brecal_utils/stubs/participant.py new file mode 100644 index 0000000..697a011 --- /dev/null +++ b/src/lib_brecal_utils/brecal_utils/stubs/participant.py @@ -0,0 +1,32 @@ +import datetime +from brecal_utils.stubs import generate_uuid1_int +from BreCal.schemas.model import Participant + +def get_participant_simple(): + participant_id = generate_uuid1_int() + + # #TODO: role_type and flags are arbitrary + name = "Max Mustermann" + street = "Musterstrasse 1" + postal_code = "12345" + city = "Bremen" + role_type = 1 # integer + flags = 0 # integer. unclear + + created = datetime.datetime.now() + modified = created+datetime.timedelta(seconds=10) + deleted = modified+datetime.timedelta(seconds=3) + + participant = Participant( + participant_id, + name, + street, + postal_code, + city, + role_type, + flags, + created, + modified, + deleted + ) + return participant diff --git a/src/lib_brecal_utils/brecal_utils/stubs/roles.py b/src/lib_brecal_utils/brecal_utils/stubs/roles.py new file mode 100644 index 0000000..e69de29 diff --git a/src/lib_brecal_utils/brecal_utils/stubs/ship.py b/src/lib_brecal_utils/brecal_utils/stubs/ship.py new file mode 100644 index 0000000..f48bb69 --- /dev/null +++ b/src/lib_brecal_utils/brecal_utils/stubs/ship.py @@ -0,0 +1,39 @@ +import datetime +from brecal_utils.stubs import generate_uuid1_int +from BreCal.schemas.model import Ship + +def get_ship_simple(): + ship_id = generate_uuid1_int() + name = "african halcyon".upper() # 'Schiffe_sample_format.xlsx' uses .upper() for every ship + imo = 9343613 # assert str(len(imo))==7 + callsign = 1234567 # up to 7 characters. assert str(len(callsign))<=7 + participant_id = generate_uuid1_int() + length = 177.13 # assert 0>length<=500 + width = 28.4 # assert 0>width<=500 + is_tug = False + bollard_pull = None # only if is_tug + participant_id = None # only if is_tug + eni = "01234567" # Alternative to IMO. Dynamic assertion?. assert len(str(eni))==8 + + created = datetime.datetime.now() + modified = created+datetime.timedelta(seconds=10) + deleted = modified+datetime.timedelta(seconds=3) + + + ship = Ship( + ship_id, + name, + imo, + callsign, + participant_id, + length, + width, + is_tug, + bollard_pull, + eni, + created, + modified, + deleted + ) + return ship + diff --git a/src/lib_brecal_utils/brecal_utils/stubs/shipcall.py b/src/lib_brecal_utils/brecal_utils/stubs/shipcall.py new file mode 100644 index 0000000..1eb8d7a --- /dev/null +++ b/src/lib_brecal_utils/brecal_utils/stubs/shipcall.py @@ -0,0 +1,76 @@ +import datetime +from brecal_utils.stubs import generate_uuid1_int +from BreCal.schemas.model import Shipcall +from dataclasses import field + +def get_shipcall_simple(): + base_time = datetime.datetime.now() + + shipcall_id = generate_uuid1_int() + ship_id = generate_uuid1_int() + + eta = base_time+datetime.timedelta(hours=3, minutes=12) + role_type = 1 + voyage = "987654321" + etd = base_time+datetime.timedelta(hours=6, minutes=12) # should never be before eta + + arrival_berth_id = generate_uuid1_int() + departure_berth_id = generate_uuid1_int() + + tug_required = False + pilot_required = False + + flags = 0 # #TODO_shipcall_flags. What is meant here? What should be tested? + pier_side = False # whether a ship will be fixated on the pier side. en: pier side, de: Anlegestelle + bunkering = False # #TODO_bunkering_unclear + replenishing_terminal = False # en: replenishing terminal, de: Nachfüll-Liegeplatz + replenishing_lock = False # en: replenishing lock, de: Nachfüllschleuse + + draft = 0.12 # #TODO_draft_value: clarify, what 'draft' means and what kind of values are to be expected + + # tidal window: built in a way, where ETA and ETD are in-between the window + # #TODO_tidal_window_source: are these windows taken from a database or provided by the user? How do they know this? + tidal_window_from = base_time+datetime.timedelta(hours=2, minutes=12) + tidal_window_to = base_time+datetime.timedelta(hours=7, minutes=12) + rain_sensitive_cargo = False + recommended_tugs = 2 # assert 0