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

View File

@ -2,7 +2,7 @@ from enum import Enum
class ParticipantType(Enum):
"""determines the type of a participant"""
NONE = 0
UNDEFINED = 0
BSMD = 1
TERMINAL = 2
PILOT = 4
@ -11,8 +11,13 @@ class ParticipantType(Enum):
PORT_ADMINISTRATION = 32
TUG = 64
class ParticipantFlag(Enum):
UNDEFINED = 0
ALLOW_BSMD = 1
class ShipcallType(Enum):
"""determines the type of a shipcall, as this changes the applicable validation rules"""
UNDEFINED = 0
INCOMING = 1
OUTGOING = 2
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
the necessity of notifications.
"""
NONE = 0
UNDEFINED = 0
GREEN = 1
YELLOW = 2
RED = 3

View File

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

View File

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

View File

@ -2,6 +2,7 @@ import datetime
from BreCal.stubs import generate_uuid1_int
from BreCal.schemas.model import Shipcall
from dataclasses import field
from BreCal.database.enums import ShipcallType, StatusFlags
def get_shipcall_simple():
# only used for the stub
@ -11,7 +12,7 @@ def get_shipcall_simple():
ship_id = generate_uuid1_int()
eta = base_time+datetime.timedelta(hours=3, minutes=12)
role_type = 1
role_type = ShipcallType.INCOMING
voyage = "987654321"
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'
canceled = False
evaluation = None
evaluation = StatusFlags.UNDEFINED
evaluation_message = ""
created = datetime.datetime.now()
modified = created+datetime.timedelta(seconds=10)

View File

@ -122,7 +122,7 @@ class ValidationRules(ValidationRuleFunctions):
returns bool, whether a notification should be triggered
"""
# 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
def undefined_method(self) -> str:

View File

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