essential bugfixes

This commit is contained in:
Daniel Schick 2024-09-20 09:46:48 +02:00
parent 12c1fc59b1
commit ed6f5ab648
7 changed files with 61 additions and 32 deletions

View File

@ -544,8 +544,9 @@
<data name="textTidalBothValues" xml:space="preserve"> <data name="textTidalBothValues" xml:space="preserve">
<value>Für das Tidenfenster müssen beide Zeiten angegeben werden</value> <value>Für das Tidenfenster müssen beide Zeiten angegeben werden</value>
</data> </data>
<data name="textTooFarInTheFuture" xml:space="preserve"> <data name="textTooFarInTheFuture" xml:space="preserve">
<value>Eine Zeiteingabe ist zu weit in der Zukunft</value> <value>Eine Zeiteingabe ist zu weit in der Zukunft</value>
</data>
<data name="textHarbour" xml:space="preserve"> <data name="textHarbour" xml:space="preserve">
<value>Hafen</value> <value>Hafen</value>
</data> </data>

View File

@ -52,7 +52,7 @@ def create_app(test_config=None, instance_path=None):
try: try:
import os import os
print(f'Instance path = {app.instance_path}') print(f'Instance path = {app.instance_path}')
os.makedirs(app.instance_path) os.makedirs(app.instance_path, exist_ok=True)
except OSError: except OSError:
pass pass

View File

@ -10,22 +10,38 @@ def create_sql_query_shipcall_get(options:dict)->str:
options : dict. A dictionary, which must contains the 'past_days' key (int). Determines the range options : dict. A dictionary, which must contains the 'past_days' key (int). Determines the range
by which shipcalls are filtered. by which shipcalls are filtered.
""" """
query = ("SELECT s.id as id, ship_id, port_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " + if "participant_id" not in options: # if no participant_id is given, all shipcalls are selected
"flags, s.pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, " + query = ("SELECT s.id as id, ship_id, port_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " +
"tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, " + "flags, s.pier_side, bunkering, replenishing_terminal, replenishing_lock, draft, tidal_window_from, " +
"evaluation_message, evaluation_time, evaluation_notifications_sent, s.created as created, s.modified as modified, time_ref_point " + "tidal_window_to, rain_sensitive_cargo, recommended_tugs, anchored, moored_lock, canceled, evaluation, " +
"FROM shipcall s " + "evaluation_message, evaluation_time, evaluation_notifications_sent, s.created as created, s.modified as modified, time_ref_point " +
"LEFT JOIN times t ON t.shipcall_id = s.id AND t.participant_type = 8 " + "FROM shipcall s " +
"WHERE " + "LEFT JOIN times t ON t.shipcall_id = s.id AND t.participant_type = 8 " +
"port_id in (SELECT port_id FROM participant_port_map WHERE participant_id = %d)" + "WHERE " +
" AND (" + "(type = 1 AND " +
"(type = 1 AND " + "((t.id IS NOT NULL AND t.eta_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " +
"((t.id IS NOT NULL AND t.eta_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " + "(eta >= DATE(NOW() - INTERVAL %d DAY)))) OR " +
"(eta >= DATE(NOW() - INTERVAL %d DAY)))) OR " + "((type = 2 OR type = 3) AND " +
"((type = 2 OR type = 3) AND " + "((t.id IS NOT NULL AND t.etd_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " +
"((t.id IS NOT NULL AND t.etd_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " + "(etd >= DATE(NOW() - INTERVAL %d DAY)))) " +
"(etd >= DATE(NOW() - INTERVAL %d DAY))))) " + "ORDER BY eta") % (options["past_days"], options["past_days"], options["past_days"], options["past_days"])
"ORDER BY eta") % (options["participant_id"], options["past_days"], options["past_days"], options["past_days"], options["past_days"]) else:
query = ("SELECT s.id as id, ship_id, port_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, time_ref_point " +
"FROM shipcall s " +
"LEFT JOIN times t ON t.shipcall_id = s.id AND t.participant_type = 8 " +
"WHERE " +
"port_id in (SELECT port_id FROM participant_port_map WHERE participant_id = %d)" +
" AND (" +
"(type = 1 AND " +
"((t.id IS NOT NULL AND t.eta_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " +
"(eta >= DATE(NOW() - INTERVAL %d DAY)))) OR " +
"((type = 2 OR type = 3) AND " +
"((t.id IS NOT NULL AND t.etd_berth >= DATE(NOW() - INTERVAL %d DAY)) OR " +
"(etd >= DATE(NOW() - INTERVAL %d DAY))))) " +
"ORDER BY eta") % (options["participant_id"], options["past_days"], options["past_days"], options["past_days"], options["past_days"])
return query return query

View File

@ -15,10 +15,15 @@ def GetBerths(options):
commands = pydapper.using(pooledConnection) commands = pydapper.using(pooledConnection)
# only load berths to ports that the participant is assigned to # only load berths to ports that the participant is assigned to
query = ("SELECT id, name, `lock`, owner_id, port_id, authority_id, created, modified, deleted FROM berth WHERE " + if "participant_id" in options:
"deleted = 0 AND + " query = ("SELECT id, name, `lock`, owner_id, port_id, authority_id, created, modified, deleted FROM berth WHERE " +
"port_id IN (SELECT port_id FROM participant_port_map WHERE participant_id = %d) " + "deleted = 0 AND + "
"ORDER BY name") % (options["participant_id"]) "port_id IN (SELECT port_id FROM participant_port_map WHERE participant_id = %d) " +
"ORDER BY name") % (options["participant_id"])
else:
query = ("SELECT id, name, `lock`, owner_id, port_id, authority_id, created, modified, deleted FROM berth WHERE " +
"deleted = 0 ORDER BY name")
data = commands.query(query, model=model.Berth) data = commands.query(query, model=model.Berth)
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'} return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}

View File

@ -23,15 +23,21 @@ def GetParticipant(options):
data = commands.query(query, model=model.Participant) data = commands.query(query, model=model.Participant)
else: else:
# query = SQLQuery.get_participants() # query = SQLQuery.get_participants()
if "participant_id" in options:
# list only participants that are assigned to the same ports than participant of caller # list only participants that are assigned to the same ports than participant of caller
query = ("SELECT p.id as id, name, street, postal_code, city, type, flags, p.created, p.modified, p.deleted " + query = ("SELECT p.id as id, name, street, postal_code, city, type, flags, p.created, p.modified, p.deleted " +
"FROM participant p " + "FROM participant p " +
"JOIN participant_port_map ON p.id = participant_port_map.participant_id " + "JOIN participant_port_map ON p.id = participant_port_map.participant_id " +
"WHERE participant_port_map.port_id IN " + "WHERE participant_port_map.port_id IN " +
"(SELECT port_id FROM participant_port_map where participant_id = %d) " + "(SELECT port_id FROM participant_port_map where participant_id = %d) " +
"GROUP BY id " + "GROUP BY id " +
"ORDER BY p.name") % options["participant_id"] "ORDER BY p.name") % options["participant_id"]
else:
query = ("SELECT p.id as id, name, street, postal_code, city, type, flags, p.created, p.modified, p.deleted " +
"FROM participant p " +
"JOIN participant_port_map ON p.id = participant_port_map.participant_id " +
"GROUP BY id " +
"ORDER BY p.name")
data = commands.query(query, model=model.Participant) data = commands.query(query, model=model.Participant)
for participant in data: for participant in data:

View File

@ -216,6 +216,7 @@ class ShipcallSchema(Schema):
id = fields.Integer(required=True) id = fields.Integer(required=True)
ship_id = fields.Integer(required=True) ship_id = fields.Integer(required=True)
port_id = fields.Integer(required=True)
type = fields.Enum(ShipcallType, default=ShipcallType.undefined) type = fields.Enum(ShipcallType, default=ShipcallType.undefined)
eta = fields.DateTime(required=False, allow_none=True) eta = fields.DateTime(required=False, allow_none=True)
voyage = fields.String(allow_none=True, required=False, validate=[validate.Length(max=16)]) voyage = fields.String(allow_none=True, required=False, validate=[validate.Length(max=16)])

View File

@ -26,7 +26,7 @@ def get_participant_id_dictionary():
def get_berth_id_dictionary(): def get_berth_id_dictionary():
# get all berths # get all berths
response,status_code,header = GetBerths(token=None) response,status_code,header = GetBerths(options={})
# build a dictionary of id:item pairs, so one can select the respective participant # build a dictionary of id:item pairs, so one can select the respective participant
berths = json.loads(response) berths = json.loads(response)