# HG changeset patch # User jbe # Date 1397082003 -7200 # Node ID 73c2ab2d068f7ef0ea7e8383da01e372d287a9f8 # Parent 8972bf3d3cb36c8c1f9b477a342f47f111a6d3a4 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 diff -r 8972bf3d3cb3 -r 73c2ab2d068f core.sql --- a/core.sql Sat Apr 05 23:06:25 2014 +0200 +++ b/core.sql Thu Apr 10 00:20:03 2014 +0200 @@ -7,7 +7,7 @@ BEGIN; CREATE VIEW "liquid_feedback_version" AS - SELECT * FROM (VALUES ('3.0.1', 3, 0, 1)) + SELECT * FROM (VALUES ('3.0.2', 3, 0, 2)) AS "subquery"("string", "major", "minor", "revision"); @@ -348,6 +348,10 @@ COMMENT ON COLUMN "session"."lang" IS 'Language code of the selected language'; +CREATE TYPE "schulze_complexity" AS ENUM ('simple', 'tuple', 'full'); + +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'; + CREATE TABLE "policy" ( "id" SERIAL4 PRIMARY KEY, "index" INT4 NOT NULL, @@ -363,6 +367,7 @@ "issue_quorum_den" INT4, "initiative_quorum_num" INT4 NOT NULL, "initiative_quorum_den" INT4 NOT NULL, + "schulze_complexity" "schulze_complexity" NOT NULL DEFAULT 'full', "direct_majority_num" INT4 NOT NULL DEFAULT 1, "direct_majority_den" INT4 NOT NULL DEFAULT 2, "direct_majority_strict" BOOLEAN NOT NULL DEFAULT TRUE, @@ -403,6 +408,7 @@ 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'''; COMMENT ON COLUMN "policy"."initiative_quorum_num" IS 'Numerator of satisfied supporter quorum to be reached by an initiative to be "admitted" for voting'; COMMENT ON COLUMN "policy"."initiative_quorum_den" IS 'Denominator of satisfied supporter quorum to be reached by an initiative to be "admitted" for voting'; +COMMENT ON COLUMN "policy"."schulze_complexity" IS 'Variant of Schulze method to use; see type "schulze_complexity"'; COMMENT ON COLUMN "policy"."direct_majority_num" IS 'Numerator of fraction of neccessary direct majority for initiatives to be attainable as winner'; COMMENT ON COLUMN "policy"."direct_majority_den" IS 'Denominator of fraction of neccessary direct majority for initaitives to be attainable as winner'; 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.'; @@ -3838,6 +3844,28 @@ 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'; +CREATE FUNCTION "secondary_link_strength" + ( "initiative_id1_p" "initiative"."id"%TYPE, + "initiative_id2_p" "initiative"."id"%TYPE ) + RETURNS INT8 + LANGUAGE 'plpgsql' IMMUTABLE AS $$ + BEGIN + IF "initiative_id1_p" = "initiative_id2_p" THEN + RAISE EXCEPTION 'Identical initiative ids passed to "secondary_link_strength" function (should not happen)'; + END IF; + RETURN ( + CASE WHEN "initiative_id1_p" < "initiative_id2_p" THEN + 1::INT8 << 62 + ELSE 0 END + - ("initiative_id1_p"::INT8 << 31) + + "initiative_id2_p"::INT8 + ); + END; + $$; + +COMMENT ON FUNCTION "secondary_link_strength"(INT4, INT4) IS 'Calculates a secondary criterion for the defeat strength (tie-breaking of the links)'; + + CREATE FUNCTION "calculate_ranks"("issue_id_p" "issue"."id"%TYPE) RETURNS VOID LANGUAGE 'plpgsql' VOLATILE AS $$ diff -r 8972bf3d3cb3 -r 73c2ab2d068f update/core-update.v3.0.1-v3.0.2.sql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/update/core-update.v3.0.1-v3.0.2.sql Thu Apr 10 00:20:03 2014 +0200 @@ -0,0 +1,9 @@ +BEGIN; + +CREATE OR REPLACE VIEW "liquid_feedback_version" AS + SELECT * FROM (VALUES ('3.0.2', 3, 0, 2)) + AS "subquery"("string", "major", "minor", "revision"); + +TODO + +COMMIT;