Update metrics_trigger_fn, Add validation check for speedOverGround.

Ignore if speedOverGround is over 40.
This commit is contained in:
xbgmsharp
2023-09-19 23:29:00 +02:00
parent 35940917e0
commit e8a899f36c

View File

@@ -357,7 +357,7 @@ CREATE FUNCTION metrics_trigger_fn() RETURNS trigger AS $metrics$
END IF; END IF;
IF previous_time > NEW.time THEN IF previous_time > NEW.time THEN
-- Ignore entry if new time is later than previous time -- Ignore entry if new time is later than previous time
RAISE WARNING 'Metrics Ignoring metric, vessel_id [%], new time is older [%] > [%]', NEW.vessel_id, previous_time, NEW.time; RAISE WARNING 'Metrics Ignoring metric, vessel_id [%], new time is older than previous_time [%] > [%]', NEW.vessel_id, previous_time, NEW.time;
RETURN NULL; RETURN NULL;
END IF; END IF;
-- Check if latitude or longitude are null -- Check if latitude or longitude are null
@@ -396,6 +396,12 @@ CREATE FUNCTION metrics_trigger_fn() RETURNS trigger AS $metrics$
RAISE WARNING 'Metrics Ignoring metric, invalid status [%]', NEW.status; RAISE WARNING 'Metrics Ignoring metric, invalid status [%]', NEW.status;
RETURN NULL; RETURN NULL;
END IF; END IF;
-- Check if speedOverGround is valid value
IF NEW.speedoverground >= 40 THEN
-- Ignore entry as speedOverGround is invalid
RAISE WARNING 'Metrics Ignoring metric, vessel_id [%], speedOverGround is invalid, over 40 < [%]', NEW.vessel_id, NEW.speedoverground;
RETURN NULL;
END IF;
-- Check the state and if any previous/current entry -- Check the state and if any previous/current entry
-- If change of state and new status is sailing or motoring -- If change of state and new status is sailing or motoring