liquid_feedback_core

diff core.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 978950dd9e32
children 98c14d8d07f1
line diff
     1.1 --- a/core.sql	Sat Mar 09 16:36:04 2013 +0100
     1.2 +++ b/core.sql	Sat Mar 09 20:20:48 2013 +0100
     1.3 @@ -2876,6 +2876,19 @@
     1.4  COMMENT ON VIEW "remaining_harmonic_initiative_weight_summands" IS 'Helper view for function "set_harmonic_initiative_weights"';
     1.5  
     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 +
    1.17 +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.18 +    
    1.19 +
    1.20  CREATE FUNCTION "set_harmonic_initiative_weights"
    1.21    ( "issue_id_p" "issue"."id"%TYPE )
    1.22    RETURNS VOID
    1.23 @@ -2907,6 +2920,17 @@
    1.24                AND coalesce("admitted", FALSE) = FALSE
    1.25              )
    1.26            )
    1.27 +          UNION ALL  -- needed for corner cases
    1.28 +          SELECT * FROM "remaining_harmonic_initiative_weight_dummies"
    1.29 +          WHERE "issue_id" = "issue_id_p"
    1.30 +          AND (
    1.31 +            coalesce("admitted", FALSE) = FALSE OR NOT EXISTS (
    1.32 +              SELECT NULL FROM "initiative"
    1.33 +              WHERE "issue_id" = "issue_id_p"
    1.34 +              AND "harmonic_weight" ISNULL
    1.35 +              AND coalesce("admitted", FALSE) = FALSE
    1.36 +            )
    1.37 +          )
    1.38            ORDER BY "initiative_id" DESC, "weight_den" DESC
    1.39            -- NOTE: non-admitted initiatives placed first (at last positions),
    1.40            --       latest initiatives treated worse in case of tie

Impressum / About Us