From e8a899f36c76c02d32d3facfd8e88e7dd741727a Mon Sep 17 00:00:00 2001 From: xbgmsharp Date: Tue, 19 Sep 2023 23:29:00 +0200 Subject: [PATCH] Update metrics_trigger_fn, Add validation check for speedOverGround. Ignore if speedOverGround is over 40. --- initdb/02_1_1_signalk_api_tables.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/initdb/02_1_1_signalk_api_tables.sql b/initdb/02_1_1_signalk_api_tables.sql index d97b0b4..c65e4d9 100644 --- a/initdb/02_1_1_signalk_api_tables.sql +++ b/initdb/02_1_1_signalk_api_tables.sql @@ -357,7 +357,7 @@ CREATE FUNCTION metrics_trigger_fn() RETURNS trigger AS $metrics$ END IF; IF previous_time > NEW.time THEN -- 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; END IF; -- 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; RETURN NULL; 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 -- If change of state and new status is sailing or motoring