liquid_feedback_core
diff update/core-update.v2.1.0-v2.2.0.sql @ 349:a5d4df7f4e22
Bugfix for calculation of harmonic_weight, when there are initiatives without supporters
author | jbe |
---|---|
date | Sat Mar 09 20:20:48 2013 +0100 (2013-03-09) |
parents | 77d9eccc167c |
children |
line diff
1.1 --- a/update/core-update.v2.1.0-v2.2.0.sql Sat Mar 09 16:36:04 2013 +0100 1.2 +++ b/update/core-update.v2.1.0-v2.2.0.sql Sat Mar 09 20:20:48 2013 +0100 1.3 @@ -447,6 +447,17 @@ 1.4 "remaining_harmonic_supporter_weight"."weight_den"; 1.5 COMMENT ON VIEW "remaining_harmonic_initiative_weight_summands" IS 'Helper view for function "set_harmonic_initiative_weights"'; 1.6 1.7 +CREATE VIEW "remaining_harmonic_initiative_weight_dummies" AS 1.8 + SELECT 1.9 + "issue_id", 1.10 + "id" AS "initiative_id", 1.11 + "admitted", 1.12 + 0 AS "weight_num", 1.13 + 1 AS "weight_den" 1.14 + FROM "initiative" 1.15 + WHERE "harmonic_weight" ISNULL; 1.16 +COMMENT ON VIEW "remaining_harmonic_initiative_weight_dummies" IS 'Helper view for function "set_harmonic_initiative_weights" providing dummy weights of zero value, which are needed for corner cases where there are no supporters for an initiative at all'; 1.17 + 1.18 CREATE FUNCTION "set_harmonic_initiative_weights" 1.19 ( "issue_id_p" "issue"."id"%TYPE ) 1.20 RETURNS VOID 1.21 @@ -478,6 +489,17 @@ 1.22 AND coalesce("admitted", FALSE) = FALSE 1.23 ) 1.24 ) 1.25 + UNION ALL -- needed for corner cases 1.26 + SELECT * FROM "remaining_harmonic_initiative_weight_dummies" 1.27 + WHERE "issue_id" = "issue_id_p" 1.28 + AND ( 1.29 + coalesce("admitted", FALSE) = FALSE OR NOT EXISTS ( 1.30 + SELECT NULL FROM "initiative" 1.31 + WHERE "issue_id" = "issue_id_p" 1.32 + AND "harmonic_weight" ISNULL 1.33 + AND coalesce("admitted", FALSE) = FALSE 1.34 + ) 1.35 + ) 1.36 ORDER BY "initiative_id" DESC, "weight_den" DESC 1.37 -- NOTE: non-admitted initiatives placed first (at last positions), 1.38 -- latest initiatives treated worse in case of tie