Compare commits

...

1 Commits

Author SHA1 Message Date
d6becc43ea Create notifications for each shipcall in the list 2025-12-12 09:16:52 +01:00

View File

@ -87,47 +87,54 @@ class ValidationRules(ValidationRuleFunctions):
# build the list of evaluation times ('now', as isoformat) # build the list of evaluation times ('now', as isoformat)
#evaluation_time = self.get_notification_times(evaluation_states_new) #evaluation_time = self.get_notification_times(evaluation_states_new)
send_notification = False
if evaluation_states_old is not None and evaluation_states_new is not None: if evaluation_states_old is not None and evaluation_states_new is not None:
if len(evaluation_states_old) == 1 and len(evaluation_states_new) == 1: pooledConnection = None
if evaluation_states_old[0] != evaluation_states_new[0]: try:
pooledConnection = None pooledConnection = getPoolConnection()
try: commands = pydapper.using(pooledConnection)
pooledConnection = getPoolConnection()
commands = pydapper.using(pooledConnection)
notification_type = 3 # RED (mapped to time_conflict)
if evaluation_states_new[0] == 2:
match evaluation_states_old[0]:
case 0:
send_notification = True
case 1:
send_notification = True
notification_type = 6 # YELLOW (mapped to missing_data)
if evaluation_states_new[0] == 3:
match evaluation_states_old[0]:
case 0:
send_notification = True
case 1:
send_notification = True
case 2:
send_notification = True
if send_notification: for shipcall_id, state_old_raw, state_new_raw, violation in zip(shipcall_df.index, evaluation_states_old, evaluation_states_new, violations):
query = f"INSERT INTO notification (shipcall_id, type, level, message) VALUES (?shipcall_id?, {notification_type}, 0, ?message?)" state_old = int(state_old_raw) if state_old_raw is not None else 0
commands.execute(query, param={"shipcall_id" : int(shipcall_df.index[0]), "message" : violations[0]}) state_new = int(state_new_raw) if state_new_raw is not None else 0
if evaluation_states_new[0] == 1 and evaluation_states_old[0] != 0: # this resolves the conflict if state_old == state_new:
query = f"SELECT * from notification where shipcall_id = ?shipcall_id? and type = {notification_type} and level = 0" continue
existing_notification = commands.query(query, param={"shipcall_id" : int(shipcall_df.index[0])})
if len(existing_notification) > 0: notification_type = 3 # RED (mapped to time_conflict)
query = "DELETE from notification where id = ?id?" send_notification = False
commands.execute(query, param={"id" : existing_notification[0]["id"]})
else: if state_new == 2:
query = "INSERT INTO notification (shipcall_id, type, level) VALUES (?shipcall_id?, 4, 0)" match state_old:
commands.execute(query, param={"shipcall_id" : int(shipcall_df.index[0])}) case 0:
finally: send_notification = True
if pooledConnection is not None: case 1:
pooledConnection.close() send_notification = True
notification_type = 6 # YELLOW (mapped to missing_data)
elif state_new == 3:
match state_old:
case 0:
send_notification = True
case 1:
send_notification = True
case 2:
send_notification = True
if send_notification:
query = f"INSERT INTO notification (shipcall_id, type, level, message) VALUES (?shipcall_id?, {notification_type}, 0, ?message?)"
commands.execute(query, param={"shipcall_id" : int(shipcall_id), "message" : violation})
if state_new == 1 and state_old != 0: # this resolves the conflict
query = f"SELECT * from notification where shipcall_id = ?shipcall_id? and type = {notification_type} and level = 0"
existing_notification = commands.query(query, param={"shipcall_id" : int(shipcall_id)})
if len(existing_notification) > 0:
query = "DELETE from notification where id = ?id?"
commands.execute(query, param={"id" : existing_notification[0]["id"]})
else:
query = "INSERT INTO notification (shipcall_id, type, level) VALUES (?shipcall_id?, 4, 0)"
commands.execute(query, param={"shipcall_id" : int(shipcall_id)})
finally:
if pooledConnection is not None:
pooledConnection.close()
# build the list of 'evaluation_notifications_sent'. The value is 'False', when a notification should be created # build the list of 'evaluation_notifications_sent'. The value is 'False', when a notification should be created