enumerators for Shipcall (type, evaluation), Participant (type, flags)

This commit is contained in:
scopesorting 2023-11-20 17:44:28 +01:00
parent 3856873381
commit c32160811d
7 changed files with 35 additions and 23 deletions

View File

@ -355,8 +355,8 @@ components:
ship_id: ship_id:
type: integer type: integer
type: type:
type: integer type: string
# TODO: use an enum enum: [UNDEFINED, INCOMING, OUTGOING, SHIFTING]
eta: eta:
type: string type: string
format: date-time format: date-time
@ -424,8 +424,9 @@ components:
type: boolean type: boolean
nullable: true nullable: true
evaluation: evaluation:
type: integer type: string
nullable: true nullable: true
enum: [NONE, GREEN, YELLOW, RED]
evaluation_message: evaluation_message:
type: string type: string
nullable: true nullable: true
@ -660,7 +661,8 @@ components:
type: string type: string
maxLength: 64 maxLength: 64
type: type:
type: integer type: string
enum: [NONE, BSMD, TERMINAL, PILOT, AGENCY, MOORING, PORT_ADMINISTRATION, TUG]
flags: flags:
type: integer type: integer
nullable: true nullable: true

View File

@ -2,7 +2,7 @@ from enum import Enum
class ParticipantType(Enum): class ParticipantType(Enum):
"""determines the type of a participant""" """determines the type of a participant"""
NONE = 0 UNDEFINED = 0
BSMD = 1 BSMD = 1
TERMINAL = 2 TERMINAL = 2
PILOT = 4 PILOT = 4
@ -11,8 +11,13 @@ class ParticipantType(Enum):
PORT_ADMINISTRATION = 32 PORT_ADMINISTRATION = 32
TUG = 64 TUG = 64
class ParticipantFlag(Enum):
UNDEFINED = 0
ALLOW_BSMD = 1
class ShipcallType(Enum): class ShipcallType(Enum):
"""determines the type of a shipcall, as this changes the applicable validation rules""" """determines the type of a shipcall, as this changes the applicable validation rules"""
UNDEFINED = 0
INCOMING = 1 INCOMING = 1
OUTGOING = 2 OUTGOING = 2
SHIFTING = 3 SHIFTING = 3
@ -31,7 +36,7 @@ class StatusFlags(Enum):
these enumerators ensure that each traffic light validation rule state corresponds to a value, which will be used in the ValidationRules object to identify these enumerators ensure that each traffic light validation rule state corresponds to a value, which will be used in the ValidationRules object to identify
the necessity of notifications. the necessity of notifications.
""" """
NONE = 0 UNDEFINED = 0
GREEN = 1 GREEN = 1
YELLOW = 2 YELLOW = 2
RED = 3 RED = 3

View File

@ -7,6 +7,8 @@ from typing import List
import json import json
import datetime import datetime
from BreCal.database.enums import ParticipantFlag, ParticipantType, ShipcallType, StatusFlags
def obj_dict(obj): def obj_dict(obj):
if isinstance(obj, datetime.datetime): if isinstance(obj, datetime.datetime):
return obj.isoformat() return obj.isoformat()
@ -36,8 +38,8 @@ class Notification(Schema):
id: int id: int
times_id: int times_id: int
acknowledged: bool acknowledged: bool
level: int level: int # note: could become an enum
type: int type: int # note: could become an enum
message: str message: str
created: datetime created: datetime
modified: datetime modified: datetime
@ -49,8 +51,8 @@ class Participant(Schema):
street: str street: str
postal_code: str postal_code: str
city: str city: str
type: int type: ParticipantType
flags: int flags: ParticipantFlag
created: datetime created: datetime
modified: datetime modified: datetime
deleted: bool deleted: bool
@ -60,7 +62,7 @@ class ParticipantList(Participant):
class ParticipantAssignmentSchema(Schema): class ParticipantAssignmentSchema(Schema):
participant_id = fields.Int() participant_id = fields.Int()
type = fields.Int() type : ParticipantType = fields.Enum(enum=ParticipantType)
class ShipcallSchema(Schema): class ShipcallSchema(Schema):
def __init__(self): def __init__(self):
@ -69,7 +71,7 @@ class ShipcallSchema(Schema):
id = fields.Int() id = fields.Int()
ship_id = fields.Int() ship_id = fields.Int()
type = fields.Int() type : ShipcallType = fields.Enum(enum=ShipcallType)
eta = fields.DateTime(Required = False, allow_none=True) eta = fields.DateTime(Required = False, allow_none=True)
voyage = fields.Str(Required = False, allow_none=True) voyage = fields.Str(Required = False, allow_none=True)
etd = fields.DateTime(Required = False, allow_none=True) etd = fields.DateTime(Required = False, allow_none=True)
@ -77,7 +79,7 @@ class ShipcallSchema(Schema):
departure_berth_id = fields.Int(Required = False, allow_none=True) departure_berth_id = fields.Int(Required = False, allow_none=True)
tug_required = fields.Bool(Required = False, allow_none=True) tug_required = fields.Bool(Required = False, allow_none=True)
pilot_required = fields.Bool(Required = False, allow_none=True) pilot_required = fields.Bool(Required = False, allow_none=True)
flags = fields.Int(Required = False, allow_none=True) flags = fields.Int(Required = False, allow_none=True) # note: could become an enum
pier_side = fields.Bool(Required = False, allow_none=True) pier_side = fields.Bool(Required = False, allow_none=True)
bunkering = fields.Bool(Required = False, allow_none=True) bunkering = fields.Bool(Required = False, allow_none=True)
replenishing_terminal = fields.Bool(Required = False, allow_none=True) replenishing_terminal = fields.Bool(Required = False, allow_none=True)
@ -90,7 +92,7 @@ class ShipcallSchema(Schema):
anchored = fields.Bool(Required = False, allow_none=True) anchored = fields.Bool(Required = False, allow_none=True)
moored_lock = fields.Bool(Required = False, allow_none=True) moored_lock = fields.Bool(Required = False, allow_none=True)
canceled = fields.Bool(Required = False, allow_none=True) canceled = fields.Bool(Required = False, allow_none=True)
evaluation = fields.Int(Required = False, allow_none=True) evaluation = fields.Enum(Required = False, allow_none=True, enum=StatusFlags)
evaluation_message = fields.Str(Required = False, allow_none=True) evaluation_message = fields.Str(Required = False, allow_none=True)
participants = fields.List(fields.Nested(ParticipantAssignmentSchema)) participants = fields.List(fields.Nested(ParticipantAssignmentSchema))
created = fields.DateTime(Required = False, allow_none=True) created = fields.DateTime(Required = False, allow_none=True)
@ -104,14 +106,14 @@ class Participant_Assignment:
pass pass
participant_id: int participant_id: int
type: int type: ParticipantType
@dataclass @dataclass
class Shipcall: class Shipcall:
id: int id: int
ship_id: int ship_id: int
type: str type: ShipcallType
eta: datetime eta: datetime
voyage: str voyage: str
etd: datetime etd: datetime
@ -132,7 +134,7 @@ class Shipcall:
anchored: bool anchored: bool
moored_lock: bool moored_lock: bool
canceled: bool canceled: bool
evaluation: int evaluation: StatusFlags
evaluation_message: str evaluation_message: str
created: datetime created: datetime
modified: datetime modified: datetime

View File

@ -1,6 +1,8 @@
import datetime import datetime
from BreCal.stubs import generate_uuid1_int from BreCal.stubs import generate_uuid1_int
from BreCal.schemas.model import Participant from BreCal.schemas.model import Participant
from BreCal.database.enums import ParticipantType, ParticipantFlag
def get_participant_simple(): def get_participant_simple():
participant_id = generate_uuid1_int() participant_id = generate_uuid1_int()
@ -10,8 +12,8 @@ def get_participant_simple():
street = "Musterstrasse 1" street = "Musterstrasse 1"
postal_code = "12345" postal_code = "12345"
city = "Bremen" city = "Bremen"
role_type = 1 # integer role_type = ParticipantType.BSMD
flags = 0 # integer. unclear flags = ParticipantFlag.UNDEFINED # integer. unclear
created = datetime.datetime.now() created = datetime.datetime.now()
modified = created+datetime.timedelta(seconds=10) modified = created+datetime.timedelta(seconds=10)

View File

@ -2,6 +2,7 @@ import datetime
from BreCal.stubs import generate_uuid1_int from BreCal.stubs import generate_uuid1_int
from BreCal.schemas.model import Shipcall from BreCal.schemas.model import Shipcall
from dataclasses import field from dataclasses import field
from BreCal.database.enums import ShipcallType, StatusFlags
def get_shipcall_simple(): def get_shipcall_simple():
# only used for the stub # only used for the stub
@ -11,7 +12,7 @@ def get_shipcall_simple():
ship_id = generate_uuid1_int() ship_id = generate_uuid1_int()
eta = base_time+datetime.timedelta(hours=3, minutes=12) eta = base_time+datetime.timedelta(hours=3, minutes=12)
role_type = 1 role_type = ShipcallType.INCOMING
voyage = "987654321" voyage = "987654321"
etd = base_time+datetime.timedelta(hours=6, minutes=12) # should never be before eta etd = base_time+datetime.timedelta(hours=6, minutes=12) # should never be before eta
@ -39,7 +40,7 @@ def get_shipcall_simple():
moored_lock = False # de: 'Festmacherschleuse', en: 'moored lock' moored_lock = False # de: 'Festmacherschleuse', en: 'moored lock'
canceled = False canceled = False
evaluation = None evaluation = StatusFlags.UNDEFINED
evaluation_message = "" evaluation_message = ""
created = datetime.datetime.now() created = datetime.datetime.now()
modified = created+datetime.timedelta(seconds=10) modified = created+datetime.timedelta(seconds=10)

View File

@ -122,7 +122,7 @@ class ValidationRules(ValidationRuleFunctions):
returns bool, whether a notification should be triggered returns bool, whether a notification should be triggered
""" """
# state_old is always considered at least 'Green' (1) # state_old is always considered at least 'Green' (1)
state_old = max(copy.copy(self.notification_state) if "notification_state" in list(self.__dict__.keys()) else StatusFlags.NONE, StatusFlags.GREEN.value) state_old = max(copy.copy(self.notification_state) if "notification_state" in list(self.__dict__.keys()) else StatusFlags.UNDEFINED, StatusFlags.GREEN.value)
return state_new.value > state_old.value return state_new.value > state_old.value
def undefined_method(self) -> str: def undefined_method(self) -> str:

View File

@ -18,7 +18,7 @@ def test_validation_rule_state_order():
# red>yellow>green>none # red>yellow>green>none
assert StatusFlags.RED.value>StatusFlags.YELLOW.value assert StatusFlags.RED.value>StatusFlags.YELLOW.value
assert StatusFlags.YELLOW.value>StatusFlags.GREEN.value assert StatusFlags.YELLOW.value>StatusFlags.GREEN.value
assert StatusFlags.GREEN.value>StatusFlags.NONE.value assert StatusFlags.GREEN.value>StatusFlags.UNDEFINED.value
return return
if __name__=="__main__": if __name__=="__main__":