liquid_feedback_core

changeset 423:73c2ab2d068f

Work on configuration of complexity of counting of the votes (extent of tie-breaking):
- added configuration field in "policy" table
- calculation of secondary criterion for the defeat strength (tie-breaking of the links) based on initiative id's
author jbe
date Thu Apr 10 00:20:03 2014 +0200 (2014-04-10)
parents 8972bf3d3cb3
children 7fbf614ca8cb
files core.sql update/core-update.v3.0.1-v3.0.2.sql
line diff
     1.1 --- a/core.sql	Sat Apr 05 23:06:25 2014 +0200
     1.2 +++ b/core.sql	Thu Apr 10 00:20:03 2014 +0200
     1.3 @@ -7,7 +7,7 @@
     1.4  BEGIN;
     1.5  
     1.6  CREATE VIEW "liquid_feedback_version" AS
     1.7 -  SELECT * FROM (VALUES ('3.0.1', 3, 0, 1))
     1.8 +  SELECT * FROM (VALUES ('3.0.2', 3, 0, 2))
     1.9    AS "subquery"("string", "major", "minor", "revision");
    1.10  
    1.11  
    1.12 @@ -348,6 +348,10 @@
    1.13  COMMENT ON COLUMN "session"."lang"              IS 'Language code of the selected language';
    1.14  
    1.15  
    1.16 +CREATE TYPE "schulze_complexity" AS ENUM ('simple', 'tuple', 'full');
    1.17 +
    1.18 +COMMENT ON TYPE "schulze_complexity" IS 'Variant of Schulze method to use: ''simple'' = only the number of winning votes in a pairwise comparison is considered, ''tuple'' = the number of winning votes (primarily) as well as the number of losing votes (secondarily) are considered, ''full'' = same as ''tuple'' but with additional tie-breaking';
    1.19 +
    1.20  CREATE TABLE "policy" (
    1.21          "id"                    SERIAL4         PRIMARY KEY,
    1.22          "index"                 INT4            NOT NULL,
    1.23 @@ -363,6 +367,7 @@
    1.24          "issue_quorum_den"      INT4,
    1.25          "initiative_quorum_num" INT4            NOT NULL,
    1.26          "initiative_quorum_den" INT4            NOT NULL,
    1.27 +        "schulze_complexity"    "schulze_complexity" NOT NULL DEFAULT 'full',
    1.28          "direct_majority_num"           INT4    NOT NULL DEFAULT 1,
    1.29          "direct_majority_den"           INT4    NOT NULL DEFAULT 2,
    1.30          "direct_majority_strict"        BOOLEAN NOT NULL DEFAULT TRUE,
    1.31 @@ -403,6 +408,7 @@
    1.32  COMMENT ON COLUMN "policy"."issue_quorum_den"      IS 'Denominator of potential supporter quorum to be reached by one initiative of an issue to be "accepted" and enter issue state ''discussion''';
    1.33  COMMENT ON COLUMN "policy"."initiative_quorum_num" IS   'Numerator of satisfied supporter quorum  to be reached by an initiative to be "admitted" for voting';
    1.34  COMMENT ON COLUMN "policy"."initiative_quorum_den" IS 'Denominator of satisfied supporter quorum to be reached by an initiative to be "admitted" for voting';
    1.35 +COMMENT ON COLUMN "policy"."schulze_complexity"    IS 'Variant of Schulze method to use; see type "schulze_complexity"';
    1.36  COMMENT ON COLUMN "policy"."direct_majority_num"            IS 'Numerator of fraction of neccessary direct majority for initiatives to be attainable as winner';
    1.37  COMMENT ON COLUMN "policy"."direct_majority_den"            IS 'Denominator of fraction of neccessary direct majority for initaitives to be attainable as winner';
    1.38  COMMENT ON COLUMN "policy"."direct_majority_strict"         IS 'If TRUE, then the direct majority must be strictly greater than "direct_majority_num"/"direct_majority_den", otherwise it may also be equal.';
    1.39 @@ -3838,6 +3844,28 @@
    1.40  COMMENT ON FUNCTION "defeat_strength"(INT4, INT4) IS 'Calculates defeat strength (INT8!) of a pairwise defeat primarily by the absolute number of votes for the winner and secondarily by the absolute number of votes for the loser';
    1.41  
    1.42  
    1.43 +CREATE FUNCTION "secondary_link_strength"
    1.44 +  ( "initiative_id1_p" "initiative"."id"%TYPE,
    1.45 +    "initiative_id2_p" "initiative"."id"%TYPE )
    1.46 +  RETURNS INT8
    1.47 +  LANGUAGE 'plpgsql' IMMUTABLE AS $$
    1.48 +    BEGIN
    1.49 +      IF "initiative_id1_p" = "initiative_id2_p" THEN
    1.50 +        RAISE EXCEPTION 'Identical initiative ids passed to "secondary_link_strength" function (should not happen)';
    1.51 +      END IF;
    1.52 +      RETURN (
    1.53 +        CASE WHEN "initiative_id1_p" < "initiative_id2_p" THEN
    1.54 +          1::INT8 << 62
    1.55 +        ELSE 0 END
    1.56 +        - ("initiative_id1_p"::INT8 << 31)
    1.57 +        + "initiative_id2_p"::INT8
    1.58 +      );
    1.59 +    END;
    1.60 +  $$;
    1.61 +
    1.62 +COMMENT ON FUNCTION "secondary_link_strength"(INT4, INT4) IS 'Calculates a secondary criterion for the defeat strength (tie-breaking of the links)';
    1.63 +
    1.64 +
    1.65  CREATE FUNCTION "calculate_ranks"("issue_id_p" "issue"."id"%TYPE)
    1.66    RETURNS VOID
    1.67    LANGUAGE 'plpgsql' VOLATILE AS $$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/update/core-update.v3.0.1-v3.0.2.sql	Thu Apr 10 00:20:03 2014 +0200
     2.3 @@ -0,0 +1,9 @@
     2.4 +BEGIN;
     2.5 +
     2.6 +CREATE OR REPLACE VIEW "liquid_feedback_version" AS
     2.7 +  SELECT * FROM (VALUES ('3.0.2', 3, 0, 2))
     2.8 +  AS "subquery"("string", "major", "minor", "revision");
     2.9 +
    2.10 +TODO
    2.11 +
    2.12 +COMMIT;

Impressum / About Us