From 13be1986f21544723ab62707eee63f3da8c49f16 Mon Sep 17 00:00:00 2001 From: AlessioZeni Date: Wed, 18 Oct 2023 15:10:18 +0200 Subject: [PATCH 1/2] some small sql changes --- Insigno.toml | 2 +- migrations/2023-10-09-143951_verify_verdict/up.sql | 2 +- migrations/2023-10-16-090225_get_near/up.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Insigno.toml b/Insigno.toml index 37da4cd..cb542b9 100644 --- a/Insigno.toml +++ b/Insigno.toml @@ -22,4 +22,4 @@ intro_images = [] [default.databases.db] url = "postgres://mindshub:test@localhost:5432/insignorocketdb" timeout = 5 - pool_size = 5 + pool_size = 5 \ No newline at end of file diff --git a/migrations/2023-10-09-143951_verify_verdict/up.sql b/migrations/2023-10-09-143951_verify_verdict/up.sql index de55c5a..6fbdb76 100644 --- a/migrations/2023-10-09-143951_verify_verdict/up.sql +++ b/migrations/2023-10-09-143951_verify_verdict/up.sql @@ -36,7 +36,7 @@ CREATE OR REPLACE FUNCTION verify_set_verdict( -- update the score of the marker image UPDATE marker_images SET verify_number = verify_number + 1, - verify_average = (verify_average * verify_number + CASE WHEN verdict_inp = TRUE THEN 1.0 ELSE 0.0 END)/verify_number + verify_average = (verify_average * verify_number + CASE WHEN verdict_inp = TRUE THEN 1.0 ELSE 0.0 END)/GREATEST(verify_number, 1) WHERE marker_images.id = image_id_inp; -- check if the remaining images in the session are down to 0 diff --git a/migrations/2023-10-16-090225_get_near/up.sql b/migrations/2023-10-16-090225_get_near/up.sql index 02f5cd3..dd334d4 100644 --- a/migrations/2023-10-16-090225_get_near/up.sql +++ b/migrations/2023-10-16-090225_get_near/up.sql @@ -22,7 +22,7 @@ CREATE OR REPLACE FUNCTION get_near( AND (SELECT COUNT (*) FROM marker_reports WHERE markers.id = reported_marker)<1 AND ( (SELECT COUNT (*) FROM marker_images WHERE markers.id = marker_images.refers_to AND (marker_images.verify_average>0.5 OR marker_images.approved) )>0 - OR ((user_id_inp IS NOT NULL) OR markers.created_by =user_id_inp) + OR ((user_id_inp IS NOT NULL) AND markers.created_by =user_id_inp) ); END; $$ LANGUAGE plpgsql; \ No newline at end of file From 95dd95947a55dc5f2b161036483828829d1d236b Mon Sep 17 00:00:00 2001 From: AlessioZeni Date: Wed, 18 Oct 2023 19:39:04 +0200 Subject: [PATCH 2/2] solved --- migrations/2023-10-09-143951_verify_verdict/up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/2023-10-09-143951_verify_verdict/up.sql b/migrations/2023-10-09-143951_verify_verdict/up.sql index 6fbdb76..dd6559c 100644 --- a/migrations/2023-10-09-143951_verify_verdict/up.sql +++ b/migrations/2023-10-09-143951_verify_verdict/up.sql @@ -36,7 +36,7 @@ CREATE OR REPLACE FUNCTION verify_set_verdict( -- update the score of the marker image UPDATE marker_images SET verify_number = verify_number + 1, - verify_average = (verify_average * verify_number + CASE WHEN verdict_inp = TRUE THEN 1.0 ELSE 0.0 END)/GREATEST(verify_number, 1) + verify_average = (verify_average * verify_number + CASE WHEN verdict_inp = TRUE THEN 1.0 ELSE 0.0 END)/COALESCE(verify_number+1, 1) WHERE marker_images.id = image_id_inp; -- check if the remaining images in the session are down to 0