liquid_feedback_core

changeset 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 c6e59e0db6ce
children 49c25dbc27bc
files core.sql update/core-update.v2.1.0-v2.2.0.sql
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
     2.1 --- a/update/core-update.v2.1.0-v2.2.0.sql	Sat Mar 09 16:36:04 2013 +0100
     2.2 +++ b/update/core-update.v2.1.0-v2.2.0.sql	Sat Mar 09 20:20:48 2013 +0100
     2.3 @@ -447,6 +447,17 @@
     2.4      "remaining_harmonic_supporter_weight"."weight_den";
     2.5  COMMENT ON VIEW "remaining_harmonic_initiative_weight_summands" IS 'Helper view for function "set_harmonic_initiative_weights"';
     2.6  
     2.7 +CREATE VIEW "remaining_harmonic_initiative_weight_dummies" AS
     2.8 +  SELECT
     2.9 +    "issue_id",
    2.10 +    "id" AS "initiative_id",
    2.11 +    "admitted",
    2.12 +    0 AS "weight_num",
    2.13 +    1 AS "weight_den"
    2.14 +  FROM "initiative"
    2.15 +  WHERE "harmonic_weight" ISNULL;
    2.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';
    2.17 +
    2.18  CREATE FUNCTION "set_harmonic_initiative_weights"
    2.19    ( "issue_id_p" "issue"."id"%TYPE )
    2.20    RETURNS VOID
    2.21 @@ -478,6 +489,17 @@
    2.22                AND coalesce("admitted", FALSE) = FALSE
    2.23              )
    2.24            )
    2.25 +          UNION ALL  -- needed for corner cases
    2.26 +          SELECT * FROM "remaining_harmonic_initiative_weight_dummies"
    2.27 +          WHERE "issue_id" = "issue_id_p"
    2.28 +          AND (
    2.29 +            coalesce("admitted", FALSE) = FALSE OR NOT EXISTS (
    2.30 +              SELECT NULL FROM "initiative"
    2.31 +              WHERE "issue_id" = "issue_id_p"
    2.32 +              AND "harmonic_weight" ISNULL
    2.33 +              AND coalesce("admitted", FALSE) = FALSE
    2.34 +            )
    2.35 +          )
    2.36            ORDER BY "initiative_id" DESC, "weight_den" DESC
    2.37            -- NOTE: non-admitted initiatives placed first (at last positions),
    2.38            --       latest initiatives treated worse in case of tie

Impressum / About Us