# HG changeset patch # User jbe # Date 1306308265 -7200 # Node ID 4c3a5d0c4c8227d61c53ec92983423f26c3a0039 # Parent bd0cd909189dc16a3eebbdbbeac5b2a66de8892c Changed definition/behaviour of "promising" attribute (see COMMENT ON COLUMN "initiative"."promising") diff -r bd0cd909189d -r 4c3a5d0c4c82 core.sql --- a/core.sql Tue May 24 23:35:29 2011 +0200 +++ b/core.sql Wed May 25 09:24:25 2011 +0200 @@ -592,7 +592,7 @@ COMMENT ON COLUMN "initiative"."eligible" IS 'TRUE, if initiative is "attainable" and "favored"'; COMMENT ON COLUMN "initiative"."rank" IS 'Schulze-Ranking after tie-breaking'; COMMENT ON COLUMN "initiative"."winner" IS 'TRUE, if initiative is final winner (best ranked initiative being "eligible")'; -COMMENT ON COLUMN "initiative"."promising" IS 'TRUE, if initiative would win against current winner, when voting is repeated with ballots based on same preferences. Non "attainable" initiatives may never be "winner", but they can be "promising".'; +COMMENT ON COLUMN "initiative"."promising" IS 'TRUE, if and only if this initiative is not a winner and there is a number n>0, such that repeating the calculation of the winner n times with the previous winner as status quo causes this initiative to win. The calculations use the same preferences and include the previous status quo as an explicit option. Non "attainable" initiatives may never be "winner", but they can be "promising".'; CREATE TABLE "battle" ( @@ -3835,9 +3835,8 @@ UPDATE "initiative" SET "winner" = TRUE WHERE "id" = "initiative_id_v"; -- determine promising initiatives: LOOP - "promising_added_v" := FALSE; - FOR "initiative_id_v" IN - SELECT "new_initiative"."id" + -- NOTE: non-straightened ranks are used + SELECT "new_initiative"."id" INTO "initiative_id_v" FROM "issue" JOIN "policy" ON "issue"."policy_id" = "policy"."id" JOIN "initiative" "old_initiative" @@ -3847,6 +3846,7 @@ JOIN "initiative" "new_initiative" ON "new_initiative"."issue_id" = "issue_id_p" AND "new_initiative"."admitted" + AND "new_initiative"."favored" AND NOT ("new_initiative"."winner" OR "new_initiative"."promising") JOIN "battle" "battle_win" ON "battle_win"."issue_id" = "issue_id_p" @@ -3858,7 +3858,6 @@ AND "battle_lose"."winning_initiative_id" = "old_initiative"."id" WHERE "issue"."id" = "issue_id_p" AND "new_initiative"."rank" < "old_initiative"."rank" - -- NOTE: non-straightened ranks are used AND CASE WHEN "policy"."majority_strict" THEN "battle_win"."count" * "policy"."majority_den" > "policy"."majority_num" * @@ -3868,12 +3867,14 @@ "policy"."majority_num" * ("battle_win"."count"+"battle_lose"."count") END - LOOP + ORDER BY "new_initiative"."rank" + LIMIT 1; + IF FOUND THEN UPDATE "initiative" SET "promising" = TRUE WHERE "id" = "initiative_id_v"; - "promising_added_v" := TRUE; - END LOOP; - EXIT WHEN NOT "promising_added_v"; + ELSE + EXIT; + END IF; END LOOP; -- straighten ranks (start counting with 1, no equal ranks): "rank_v" := 1;