/
liquid_feedback_core-v2.0.11.solon-v0.1.diff
1185 lines (1162 loc) · 56.5 KB
/
liquid_feedback_core-v2.0.11.solon-v0.1.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Pur liquid_feedback_core-v2.0.11.orig/core.sql liquid_feedback_core-v2.0.11.cryptonize/core.sql
--- liquid_feedback_core-v2.0.11.orig/core.sql 2012-06-20 22:22:02.000000000 +0300
+++ liquid_feedback_core-v2.0.11.cryptonize/core.sql 2012-08-23 23:17:34.000000000 +0300
@@ -55,13 +55,15 @@
CREATE TABLE "system_setting" (
- "member_ttl" INTERVAL );
+ "member_ttl" INTERVAL,
+ "ext_voting_service" BOOLEAN NOT NULL DEFAULT FALSE );
CREATE UNIQUE INDEX "system_setting_singleton_idx" ON "system_setting" ((1));
COMMENT ON TABLE "system_setting" IS 'This table contains only one row with different settings in each column.';
COMMENT ON INDEX "system_setting_singleton_idx" IS 'This index ensures that "system_setting" only contains one row maximum.';
COMMENT ON COLUMN "system_setting"."member_ttl" IS 'Time after members get their "active" flag set to FALSE, if they do not show any activity.';
+COMMENT ON COLUMN "system_setting"."ext_voting_service" IS 'If set to true, an external voting module is used for voting phase. (Typically one based on cryptographically secure voting algorithms.)';
CREATE TABLE "contingent" (
@@ -331,6 +333,7 @@
"admission_time" INTERVAL NOT NULL,
"discussion_time" INTERVAL NOT NULL,
"verification_time" INTERVAL NOT NULL,
+ "public_voting_time" INTERVAL,
"voting_time" INTERVAL NOT NULL,
"issue_quorum_num" INT4 NOT NULL,
"issue_quorum_den" INT4 NOT NULL,
@@ -347,9 +350,29 @@
"indirect_majority_positive" INT4 NOT NULL DEFAULT 0,
"indirect_majority_non_negative" INT4 NOT NULL DEFAULT 0,
"no_reverse_beat_path" BOOLEAN NOT NULL DEFAULT TRUE,
- "no_multistage_majority" BOOLEAN NOT NULL DEFAULT FALSE );
+ "no_multistage_majority" BOOLEAN NOT NULL DEFAULT FALSE,
+ CONSTRAINT "public_voting_time_lte_private_voting_time"
+ CHECK ( "public_voting_time" <= "voting_time" )
+ );
CREATE INDEX "policy_active_idx" ON "policy" ("active");
+CREATE FUNCTION "autofill_public_voting_time_trigger"()
+ RETURNS TRIGGER
+ LANGUAGE 'plpgsql' VOLATILE AS $$
+ BEGIN
+ IF
+ NEW."public_voting_time" ISNULL
+ THEN
+ NEW."public_voting_time" := NEW."voting_time";
+ END IF;
+ RETURN NULL;
+ END;
+ $$;
+
+CREATE TRIGGER "autofill_public_voting_time"
+ AFTER INSERT OR UPDATE ON "policy" FOR EACH ROW EXECUTE PROCEDURE
+ "autofill_public_voting_time_trigger"();
+
COMMENT ON TABLE "policy" IS 'Policies for a particular proceeding type (timelimits, quorum)';
COMMENT ON COLUMN "policy"."index" IS 'Determines the order in listings';
@@ -357,6 +380,7 @@
COMMENT ON COLUMN "policy"."admission_time" IS 'Maximum duration of issue state ''admission''; Maximum time an issue stays open without being "accepted"';
COMMENT ON COLUMN "policy"."discussion_time" IS 'Duration of issue state ''discussion''; Regular time until an issue is "half_frozen" after being "accepted"';
COMMENT ON COLUMN "policy"."verification_time" IS 'Duration of issue state ''verification''; Regular time until an issue is "fully_frozen" (e.g. entering issue state ''voting'') after being "half_frozen"';
+COMMENT ON COLUMN "policy"."public_voting_time" IS 'When system_setting.ext_voting_service=true, members can cast both a publicly visible vote and a private (encrypted) vote. The ''public_voting_time'' will typically be shorter than ''voting_time'', which is the duration for casting the private (encrypted) vote.';
COMMENT ON COLUMN "policy"."voting_time" IS 'Duration of issue state ''voting''; Time after an issue is "fully_frozen" but not "closed" (duration of issue state ''voting'')';
COMMENT ON COLUMN "policy"."issue_quorum_num" IS 'Numerator 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"."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''';
@@ -375,6 +399,9 @@
COMMENT ON COLUMN "policy"."no_reverse_beat_path" IS 'Causes initiatives with "reverse_beat_path" flag to not be "eligible", thus disallowing them to be winner. See comment on column "initiative"."reverse_beat_path". This option ensures both that a winning initiative is never tied in a (weak) condorcet paradox with the status quo and a winning initiative always beats the status quo directly with a simple majority.';
COMMENT ON COLUMN "policy"."no_multistage_majority" IS 'Causes initiatives with "multistage_majority" flag to not be "eligible", thus disallowing them to be winner. See comment on column "initiative"."multistage_majority". This disqualifies initiatives which could cause an instable result. An instable result in this meaning is a result such that repeating the ballot with same preferences but with the winner of the first ballot as status quo would lead to a different winner in the second ballot. If there are no direct majorities required for the winner, or if in direct comparison only simple majorities are required and "no_reverse_beat_path" is true, then results are always stable and this flag does not have any effect on the winner (but still affects the "eligible" flag of an "initiative").';
+COMMENT ON FUNCTION "autofill_public_voting_time_trigger"() IS 'Implementation of trigger "autofill_public_voting_time" on table "policy".';
+COMMENT ON TRIGGER "autofill_public_voting_time" ON "policy" IS 'If "public_voting_time" is not set, set it equal to "voting_time".';
+
CREATE TABLE "unit" (
"id" SERIAL4 PRIMARY KEY,
@@ -465,6 +492,7 @@
CREATE TYPE "issue_state" AS ENUM (
'admission', 'discussion', 'verification', 'voting',
+ 'public_voting_closed', 'private_voting_closed',
'canceled_revoked_before_accepted',
'canceled_issue_not_accepted',
'canceled_after_revocation_during_discussion',
@@ -485,16 +513,20 @@
"accepted" TIMESTAMPTZ,
"half_frozen" TIMESTAMPTZ,
"fully_frozen" TIMESTAMPTZ,
+ "public_voting_closed" TIMESTAMPTZ,
+ "private_voting_closed" TIMESTAMPTZ,
"closed" TIMESTAMPTZ,
"ranks_available" BOOLEAN NOT NULL DEFAULT FALSE,
"cleaned" TIMESTAMPTZ,
"admission_time" INTERVAL NOT NULL,
"discussion_time" INTERVAL NOT NULL,
"verification_time" INTERVAL NOT NULL,
+ "public_voting_time" INTERVAL,
"voting_time" INTERVAL NOT NULL,
"snapshot" TIMESTAMPTZ,
"latest_snapshot_event" "snapshot_event",
"population" INT4,
+ "public_voter_count" INT4,
"voter_count" INT4,
"status_quo_schulze_rank" INT4,
CONSTRAINT "valid_state" CHECK ((
@@ -511,6 +543,8 @@
("state" = 'discussion' AND "closed" ISNULL AND "accepted" NOTNULL AND "half_frozen" ISNULL) OR
("state" = 'verification' AND "closed" ISNULL AND "half_frozen" NOTNULL AND "fully_frozen" ISNULL) OR
("state" = 'voting' AND "closed" ISNULL AND "fully_frozen" NOTNULL) OR
+ ("state" = 'public_voting_closed' AND "public_voting_closed" NOTNULL AND "closed" ISNULL AND "fully_frozen" NOTNULL) OR
+ ("state" = 'private_voting_closed' AND "public_voting_closed" NOTNULL AND "private_voting_closed" NOTNULL AND "closed" ISNULL AND "fully_frozen" NOTNULL) OR
("state" = 'canceled_revoked_before_accepted' AND "closed" NOTNULL AND "accepted" ISNULL) OR
("state" = 'canceled_issue_not_accepted' AND "closed" NOTNULL AND "accepted" ISNULL) OR
("state" = 'canceled_after_revocation_during_discussion' AND "closed" NOTNULL AND "half_frozen" ISNULL) OR
@@ -548,16 +582,20 @@
COMMENT ON COLUMN "issue"."accepted" IS 'Point in time, when one initiative of issue reached the "issue_quorum"';
COMMENT ON COLUMN "issue"."half_frozen" IS 'Point in time, when "discussion_time" has elapsed; Frontends must ensure that for half_frozen issues a) initiatives are not revoked, b) no new drafts are created, c) no initiators are added or removed.';
COMMENT ON COLUMN "issue"."fully_frozen" IS 'Point in time, when "verification_time" has elapsed and voting has started; Frontends must ensure that for fully_frozen issues additionally to the restrictions for half_frozen issues a) initiatives are not created, b) no interest is created or removed, c) no supporters are added or removed, d) no opinions are created, changed or deleted.';
-COMMENT ON COLUMN "issue"."closed" IS 'Point in time, when "admission_time" or "voting_time" have elapsed, and issue is no longer active; Frontends must ensure that for closed issues additionally to the restrictions for half_frozen and fully_frozen issues a) no voter is added or removed to/from the direct_voter table, b) no votes are added, modified or removed.';
+COMMENT ON COLUMN "issue"."public_voting_closed" IS 'Point in time, when no more public votes can be cast, but it is still possible to cast private votes via the external voting service. (Doesn''t participate in valid_state constraint, cause could be anything depending on value of system_setting.ext_voting_service.)';
+COMMENT ON COLUMN "issue"."private_voting_closed" IS 'Point in time, when no more private votes can be cast in the external voting service, but the external voting service has not yet delivered back the results. (Doesn''t participate in valid_state constraint, cause could be anything depending on value of system_setting.ext_voting_service.)';
+COMMENT ON COLUMN "issue"."closed" IS 'Point in time, when "admission_time" or "voting_time" have elapsed, and issue is no longer active. In case of external voting service, this state means that results have been delivered back and ranks can now be calculated; Frontends must ensure that for closed issues additionally to the restrictions for half_frozen and fully_frozen issues a) no voter is added or removed to/from the direct_voter table, b) no votes are added, modified or removed.';
COMMENT ON COLUMN "issue"."ranks_available" IS 'TRUE = ranks have been calculated';
COMMENT ON COLUMN "issue"."cleaned" IS 'Point in time, when discussion data and votes had been deleted';
COMMENT ON COLUMN "issue"."admission_time" IS 'Copied from "policy" table at creation of issue';
COMMENT ON COLUMN "issue"."discussion_time" IS 'Copied from "policy" table at creation of issue';
COMMENT ON COLUMN "issue"."verification_time" IS 'Copied from "policy" table at creation of issue';
+COMMENT ON COLUMN "issue"."public_voting_time" IS 'Copied from "policy" table at creation of issue';
COMMENT ON COLUMN "issue"."voting_time" IS 'Copied from "policy" table at creation of issue';
COMMENT ON COLUMN "issue"."snapshot" IS 'Point in time, when snapshot tables have been updated and "population" and *_count values were precalculated';
COMMENT ON COLUMN "issue"."latest_snapshot_event" IS 'Event type of latest snapshot for issue; Can be used to select the latest snapshot data in the snapshot tables';
COMMENT ON COLUMN "issue"."population" IS 'Sum of "weight" column in table "direct_population_snapshot"';
+COMMENT ON COLUMN "issue"."public_voter_count" IS 'Total number of public votes cast, either directly or via public delegation; This value is related to the final voting, while "population" is related to snapshots before the final voting';
COMMENT ON COLUMN "issue"."voter_count" IS 'Total number of direct and delegating voters; This value is related to the final voting, while "population" is related to snapshots before the final voting';
COMMENT ON COLUMN "issue"."status_quo_schulze_rank" IS 'Schulze rank of status quo, as calculated by "calculate_ranks" function';
@@ -1547,6 +1585,9 @@
IF "issue_row"."closed" NOTNULL THEN
RAISE EXCEPTION 'Tried to modify data belonging to a closed issue.';
END IF;
+ IF "issue_row"."public_voting_closed" NOTNULL THEN
+ RAISE EXCEPTION 'Public voting on this issue is closed.';
+ END IF;
RETURN NULL;
END;
$$;
@@ -1643,6 +1684,9 @@
IF NEW."verification_time" ISNULL THEN
NEW."verification_time" := "policy_row"."verification_time";
END IF;
+ IF NEW."public_voting_time" ISNULL THEN
+ NEW."public_voting_time" := "policy_row"."public_voting_time";
+ END IF;
IF NEW."voting_time" ISNULL THEN
NEW."voting_time" := "policy_row"."voting_time";
END IF;
@@ -3771,6 +3815,107 @@
( "issue"."id"%TYPE )
IS 'Closes the voting on an issue, and calculates positive and negative votes for each initiative; The ranking is not calculated yet, to keep the (locking) transaction short.';
+-- This was copied from close_voting() and some functionality removed
+CREATE FUNCTION "close_public_voting"("issue_id_p" "issue"."id"%TYPE)
+ RETURNS VOID
+ LANGUAGE 'plpgsql' VOLATILE AS $$
+ DECLARE
+ "area_id_v" "area"."id"%TYPE;
+ "unit_id_v" "unit"."id"%TYPE;
+ "member_id_v" "member"."id"%TYPE;
+ BEGIN
+ PERFORM "lock_issue"("issue_id_p");
+ SELECT "area_id" INTO "area_id_v" FROM "issue" WHERE "id" = "issue_id_p";
+ SELECT "unit_id" INTO "unit_id_v" FROM "area" WHERE "id" = "area_id_v";
+ -- delete delegating votes (in cases of manual reset of issue state):
+ DELETE FROM "delegating_voter"
+ WHERE "issue_id" = "issue_id_p";
+ -- delete votes from non-privileged voters:
+ DELETE FROM "direct_voter"
+ USING (
+ SELECT
+ "direct_voter"."member_id"
+ FROM "direct_voter"
+ JOIN "member" ON "direct_voter"."member_id" = "member"."id"
+ LEFT JOIN "privilege"
+ ON "privilege"."unit_id" = "unit_id_v"
+ AND "privilege"."member_id" = "direct_voter"."member_id"
+ WHERE "direct_voter"."issue_id" = "issue_id_p" AND (
+ "member"."active" = FALSE OR
+ "privilege"."voting_right" ISNULL OR
+ "privilege"."voting_right" = FALSE
+ )
+ ) AS "subquery"
+ WHERE "direct_voter"."issue_id" = "issue_id_p"
+ AND "direct_voter"."member_id" = "subquery"."member_id";
+ -- consider delegations:
+ UPDATE "direct_voter" SET "weight" = 1
+ WHERE "issue_id" = "issue_id_p";
+ PERFORM "add_vote_delegations"("issue_id_p");
+ -- set voter count and mark issue as public voting closed (private voting continues):
+ UPDATE "issue" SET
+ "state" = 'public_voting_closed',
+ "public_voting_closed" = now(),
+ "public_voter_count" = (
+ SELECT coalesce(sum("weight"), 0)
+ FROM "direct_voter" WHERE "issue_id" = "issue_id_p"
+ )
+ WHERE "id" = "issue_id_p";
+ END;
+ $$;
+
+COMMENT ON FUNCTION "close_public_voting"
+ ( "issue"."id"%TYPE )
+ IS 'When using external voting service, closes the public voting on an issue, i.e. the votes stored in this system directly without encryption. Typically private voting phase will continue longer, so there is no calculation of votes here.';
+
+
+CREATE FUNCTION "close_private_voting"("issue_id_p" "issue"."id"%TYPE)
+ RETURNS VOID
+ LANGUAGE 'plpgsql' VOLATILE AS $$
+ BEGIN
+ UPDATE "issue" SET
+ "state" = 'private_voting_closed',
+ "private_voting_closed" = now()
+ WHERE "id" = "issue_id_p";
+ -- clean up battle table (in case there are some "old" results)
+ DELETE FROM "battle" WHERE "issue_id" = "issue_id_p";
+ END;
+ $$;
+
+COMMENT ON FUNCTION "close_private_voting"
+ ( "issue"."id"%TYPE )
+ IS 'When using external voting service, closes the private (external) voting on an issue. After this it is not possible to vote anymore, but results are not yet available in this database.';
+
+
+CREATE FUNCTION "ext_results_available"("issue_id_p" "issue"."id"%TYPE)
+ RETURNS VOID
+ LANGUAGE 'plpgsql' VOLATILE AS $$
+ BEGIN
+ PERFORM "lock_issue"("issue_id_p");
+ -- copy "positive_votes" and "negative_votes" from "battle" table:
+ UPDATE "initiative" SET
+ "positive_votes" = "battle_win"."count",
+ "negative_votes" = "battle_lose"."count"
+ FROM "battle" AS "battle_win", "battle" AS "battle_lose"
+ WHERE
+ "battle_win"."issue_id" = "issue_id_p" AND
+ "battle_win"."winning_initiative_id" = "initiative"."id" AND
+ "battle_win"."losing_initiative_id" ISNULL AND
+ "battle_lose"."issue_id" = "issue_id_p" AND
+ "battle_lose"."losing_initiative_id" = "initiative"."id" AND
+ "battle_lose"."winning_initiative_id" ISNULL;
+ -- mark issue as ready for calculate_ranks
+ UPDATE "issue" SET
+ "state" = 'calculation',
+ "closed" = now()
+ WHERE "id" = "issue_id_p";
+ END;
+ $$;
+
+COMMENT ON FUNCTION "ext_results_available"
+ ( "issue"."id"%TYPE )
+ IS 'External voting service has now stored results of the voting into battle table and also set issue.voter_count. The calculation of ranks will now proceed as normal.';
+
CREATE FUNCTION "defeat_strength"
( "positive_votes_p" INT4, "negative_votes_p" INT4 )
@@ -4104,7 +4249,6 @@
-- Automatic state changes --
-----------------------------
-
CREATE FUNCTION "check_issue"
( "issue_id_p" "issue"."id"%TYPE )
RETURNS VOID
@@ -4112,6 +4256,7 @@
DECLARE
"issue_row" "issue"%ROWTYPE;
"policy_row" "policy"%ROWTYPE;
+ "ext_voting_service_v" BOOLEAN;
BEGIN
PERFORM "lock_issue"("issue_id_p");
SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p";
@@ -4220,14 +4365,43 @@
-- NOTE: "issue" might change, thus "issue_row" has to be updated below
END IF;
SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p";
- -- close issue by calling close_voting(...) after voting time:
+
+ -- here the state machine is different if an external voting service is used
+ SELECT "ext_voting_service" INTO "ext_voting_service_v" FROM "system_setting" LIMIT 1;
+ IF "ext_voting_service_v" AND
+ "issue_row"."fully_frozen" NOTNULL AND
+ "issue_row"."public_voting_closed" ISNULL AND
+ "issue_row"."closed" ISNULL AND
+ now() >= "issue_row"."fully_frozen" + "issue_row"."public_voting_time"
+ THEN
+ -- using external voting service: close public voting after public_voting_time
+ PERFORM "close_public_voting"("issue_id_p");
+ END IF;
+ SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p";
+ IF
+ "ext_voting_service_v" AND
+ "issue_row"."closed" ISNULL AND
+ "issue_row"."fully_frozen" NOTNULL AND
+ "issue_row"."public_voting_closed" NOTNULL AND
+ "issue_row"."private_voting_closed" ISNULL AND
+ now() >= "issue_row"."fully_frozen" + "issue_row"."voting_time"
+ THEN
+ -- using external voting service: close private voting, but note that results do not become immediately available
+ -- they can now be supplied from the external service
+ PERFORM "close_private_voting"("issue_id_p");
+ END IF;
+ SELECT * INTO "issue_row" FROM "issue" WHERE "id" = "issue_id_p";
IF
+ ("ext_voting_service_v" ISNULL OR "ext_voting_service_v"=FALSE) AND
"issue_row"."closed" ISNULL AND
"issue_row"."fully_frozen" NOTNULL AND
now() >= "issue_row"."fully_frozen" + "issue_row"."voting_time"
THEN
+ -- normal, standalone operation
+ -- close issue by calling close_voting(...) after voting time:
PERFORM "close_voting"("issue_id_p");
-- calculate ranks will not consume much time and can be done now
+ -- TODO: isn't this supposed to be called separately in lf_update???
PERFORM "calculate_ranks"("issue_id_p");
END IF;
END IF;
diff -Pur liquid_feedback_core-v2.0.11.orig/test.sql liquid_feedback_core-v2.0.11.cryptonize/test.sql
--- liquid_feedback_core-v2.0.11.orig/test.sql 2012-06-20 22:22:02.000000000 +0300
+++ liquid_feedback_core-v2.0.11.cryptonize/test.sql 2012-08-23 23:21:21.000000000 +0300
@@ -1,5 +1,7 @@
-- NOTE: This file requires that sequence generators have not been used.
--- (All new rows need to start with id '1'.)
+-- All new rows need to start with id '1'. This is still true for the stuff
+-- before "issue_test"(), even if sql inside the function can handle any
+-- starting point.
BEGIN;
@@ -37,6 +39,7 @@
"admission_time",
"discussion_time",
"verification_time",
+ "public_voting_time",
"voting_time",
"issue_quorum_num", "issue_quorum_den",
"initiative_quorum_num", "initiative_quorum_den",
@@ -45,7 +48,7 @@
) VALUES (
1,
'Default policy',
- '1 hour', '1 hour', '1 hour', '1 hour',
+ '1 hour', '1 hour', '1 hour', '1 hour', '1 hour',
25, 100,
20, 100,
1, 2, TRUE,
@@ -55,11 +58,12 @@
LANGUAGE 'plpgsql' VOLATILE AS $$
BEGIN
UPDATE "issue" SET
- "snapshot" = "snapshot" - '1 hour 1 minute'::INTERVAL,
- "created" = "created" - '1 hour 1 minute'::INTERVAL,
- "accepted" = "accepted" - '1 hour 1 minute'::INTERVAL,
- "half_frozen" = "half_frozen" - '1 hour 1 minute'::INTERVAL,
- "fully_frozen" = "fully_frozen" - '1 hour 1 minute'::INTERVAL;
+ "snapshot" = "snapshot" - '1 hour 1 minute'::INTERVAL,
+ "created" = "created" - '1 hour 1 minute'::INTERVAL,
+ "accepted" = "accepted" - '1 hour 1 minute'::INTERVAL,
+ "half_frozen" = "half_frozen" - '1 hour 1 minute'::INTERVAL,
+ "fully_frozen" = "fully_frozen" - '1 hour 1 minute'::INTERVAL,
+ "public_voting_closed" = "public_voting_closed" - '1 hour 1 minute'::INTERVAL;
PERFORM "check_everything"();
RETURN;
END;
@@ -130,281 +134,542 @@
(4, 5, 'area', 13),
(4, 12, 'area', 22);
-INSERT INTO "issue" ("area_id", "policy_id") VALUES
- (3, 1); -- id 1
+-- Create a new issue, related initiatives, supporters and eventual votes
+-- Can be run several times after each other, doesn't depend on id sequences starting from 1
+-- TODO: verify results (correct winner, etc)
+CREATE FUNCTION "issue_test"() RETURNS VOID
+ LANGUAGE 'plpgsql' VOLATILE AS $$
+ DECLARE
+ "issue_id_1_v" INT4;
+ "issue_id_2_v" INT4;
+ "initiative_id_base1_v" INT4;
+ "initiative_id_base2_v" INT4;
+ "draft_id_base1_v" INT4;
+ "draft_id_base2_v" INT4;
+ "suggestion_id_base1_v" INT4;
+ "suggestion_id_base2_v" INT4;
+ "ext_voting_service_v" BOOLEAN;
+ BEGIN
-INSERT INTO "initiative" ("issue_id", "name") VALUES
- (1, 'Initiative #1'), -- id 1
- (1, 'Initiative #2'), -- id 2
- (1, 'Initiative #3'), -- id 3
- (1, 'Initiative #4'), -- id 4
- (1, 'Initiative #5'), -- id 5
- (1, 'Initiative #6'), -- id 6
- (1, 'Initiative #7'); -- id 7
-
-INSERT INTO "draft" ("initiative_id", "author_id", "content") VALUES
- (1, 17, 'Lorem ipsum...'), -- id 1
- (2, 20, 'Lorem ipsum...'), -- id 2
- (3, 20, 'Lorem ipsum...'), -- id 3
- (4, 20, 'Lorem ipsum...'), -- id 4
- (5, 14, 'Lorem ipsum...'), -- id 5
- (6, 11, 'Lorem ipsum...'), -- id 6
- (7, 12, 'Lorem ipsum...'); -- id 7
+ INSERT INTO "issue" ("area_id", "policy_id") VALUES
+ (3, 1); -- id 1
-INSERT INTO "initiator" ("initiative_id", "member_id") VALUES
- (1, 17),
- (1, 19),
- (2, 20),
- (3, 20),
- (4, 20),
- (5, 14),
- (6, 11),
- (7, 12);
-
-INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES
- ( 7, 4, 4),
- ( 8, 2, 2),
- (11, 6, 6),
- (12, 7, 7),
- (14, 1, 1),
- (14, 2, 2),
- (14, 3, 3),
- (14, 4, 4),
- (14, 5, 5),
- (14, 6, 6),
- (14, 7, 7),
- (17, 1, 1),
- (17, 3, 3),
- (19, 1, 1),
- (19, 2, 2),
- (20, 1, 1),
- (20, 2, 2),
- (20, 3, 3),
- (20, 4, 4),
- (20, 5, 5);
-
-INSERT INTO "suggestion" ("initiative_id", "author_id", "name", "content") VALUES
- (1, 19, 'Suggestion #1', 'Lorem ipsum...'); -- id 1
-INSERT INTO "opinion" ("member_id", "suggestion_id", "degree", "fulfilled") VALUES
- (14, 1, 2, FALSE);
-INSERT INTO "opinion" ("member_id", "suggestion_id", "degree", "fulfilled") VALUES
- (19, 1, 2, FALSE);
-
-INSERT INTO "issue" ("area_id", "policy_id") VALUES
- (4, 1); -- id 2
-
-INSERT INTO "initiative" ("issue_id", "name") VALUES
- (2, 'Initiative A'), -- id 8
- (2, 'Initiative B'), -- id 9
- (2, 'Initiative C'), -- id 10
- (2, 'Initiative D'); -- id 11
-
-INSERT INTO "draft" ("initiative_id", "author_id", "content") VALUES
- ( 8, 1, 'Lorem ipsum...'), -- id 8
- ( 9, 2, 'Lorem ipsum...'), -- id 9
- (10, 3, 'Lorem ipsum...'), -- id 10
- (11, 4, 'Lorem ipsum...'); -- id 11
-
-INSERT INTO "initiator" ("initiative_id", "member_id") VALUES
- ( 8, 1),
- ( 9, 2),
- (10, 3),
- (11, 4);
-
-INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES
- (1, 8, 8),
- (1, 9, 9),
- (1, 10, 10),
- (1, 11, 11),
- (2, 8, 8),
- (2, 9, 9),
- (2, 10, 10),
- (2, 11, 11),
- (3, 8, 8),
- (3, 9, 9),
- (3, 10, 10),
- (3, 11, 11),
- (4, 8, 8),
- (4, 9, 9),
- (4, 10, 10),
- (4, 11, 11),
- (5, 8, 8),
- (5, 9, 9),
- (5, 10, 10),
- (5, 11, 11),
- (6, 8, 8),
- (6, 9, 9),
- (6, 10, 10),
- (6, 11, 11);
-
-SELECT "time_warp"();
-SELECT "time_warp"();
-SELECT "time_warp"();
-
-INSERT INTO "direct_voter" ("member_id", "issue_id") VALUES
- ( 8, 1),
- ( 9, 1),
- (11, 1),
- (12, 1),
- (14, 1),
- (19, 1),
- (20, 1),
- (21, 1);
-
-INSERT INTO "vote" ("member_id", "issue_id", "initiative_id", "grade") VALUES
- ( 8, 1, 1, 1),
- ( 8, 1, 2, 1),
- ( 8, 1, 3, 1),
- ( 8, 1, 4, 1),
- ( 8, 1, 5, 1),
- ( 8, 1, 6, -1),
- ( 8, 1, 7, -1),
- ( 9, 1, 1, -2),
- ( 9, 1, 2, -3),
- ( 9, 1, 3, -2),
- ( 9, 1, 4, -2),
- ( 9, 1, 5, -2),
- ( 9, 1, 6, -1),
- (11, 1, 1, -1),
- (11, 1, 2, -1),
- (11, 1, 3, -1),
- (11, 1, 4, -1),
- (11, 1, 5, -1),
- (11, 1, 6, 2),
- (11, 1, 7, 1),
- (12, 1, 1, -1),
- (12, 1, 3, -1),
- (12, 1, 4, -1),
- (12, 1, 5, -1),
- (12, 1, 6, -2),
- (12, 1, 7, 1),
- (14, 1, 1, 1),
- (14, 1, 2, 3),
- (14, 1, 3, 1),
- (14, 1, 4, 2),
- (14, 1, 5, 1),
- (14, 1, 6, 1),
- (14, 1, 7, 1),
- (19, 1, 1, 3),
- (19, 1, 2, 4),
- (19, 1, 3, 2),
- (19, 1, 4, 2),
- (19, 1, 5, 2),
- (19, 1, 7, 1),
- (20, 1, 1, 1),
- (20, 1, 2, 2),
- (20, 1, 3, 1),
- (20, 1, 4, 1),
- (20, 1, 5, 1),
- (21, 1, 5, -1);
-
-INSERT INTO "direct_voter" ("member_id", "issue_id") VALUES
- ( 1, 2),
- ( 2, 2),
- ( 3, 2),
- ( 4, 2),
- ( 5, 2),
- ( 6, 2),
- ( 7, 2),
- ( 8, 2),
- ( 9, 2),
- (10, 2),
- (11, 2),
- (12, 2),
- (13, 2),
- (14, 2),
- (15, 2),
- (16, 2),
- (17, 2),
- (18, 2),
- (19, 2),
- (20, 2);
-
-INSERT INTO "vote" ("member_id", "issue_id", "initiative_id", "grade") VALUES
- ( 1, 2, 8, 3),
- ( 1, 2, 9, 4),
- ( 1, 2, 10, 2),
- ( 1, 2, 11, 1),
- ( 2, 2, 8, 3),
- ( 2, 2, 9, 4),
- ( 2, 2, 10, 2),
- ( 2, 2, 11, 1),
- ( 3, 2, 8, 4),
- ( 3, 2, 9, 3),
- ( 3, 2, 10, 2),
- ( 3, 2, 11, 1),
- ( 4, 2, 8, 4),
- ( 4, 2, 9, 3),
- ( 4, 2, 10, 2),
- ( 4, 2, 11, 1),
- ( 5, 2, 8, 4),
- ( 5, 2, 9, 3),
- ( 5, 2, 10, 2),
- ( 5, 2, 11, 1),
- ( 6, 2, 8, 4),
- ( 6, 2, 9, 3),
- ( 6, 2, 10, 2),
- ( 6, 2, 11, 1),
- ( 7, 2, 8, 4),
- ( 7, 2, 9, 3),
- ( 7, 2, 10, 2),
- ( 7, 2, 11, 1),
- ( 8, 2, 8, 4),
- ( 8, 2, 9, 3),
- ( 8, 2, 10, 2),
- ( 8, 2, 11, 1),
- ( 9, 2, 8, -1),
- ( 9, 2, 9, 1),
- ( 9, 2, 10, 3),
- ( 9, 2, 11, 2),
- (10, 2, 8, -1),
- (10, 2, 9, 1),
- (10, 2, 10, 3),
- (10, 2, 11, 2),
- (11, 2, 8, -1),
- (11, 2, 9, 1),
- (11, 2, 10, 3),
- (11, 2, 11, 2),
- (12, 2, 8, -1),
- (12, 2, 9, 1),
- (12, 2, 10, 3),
- (12, 2, 11, 2),
- (13, 2, 8, -1),
- (13, 2, 9, 1),
- (13, 2, 10, 3),
- (13, 2, 11, 2),
- (14, 2, 8, -1),
- (14, 2, 9, 1),
- (14, 2, 10, 3),
- (14, 2, 11, 2),
- (15, 2, 8, -1),
- (15, 2, 9, -3),
- (15, 2, 10, -4),
- (15, 2, 11, -2),
- (16, 2, 8, -1),
- (16, 2, 9, -3),
- (16, 2, 10, -4),
- (16, 2, 11, -2),
- (17, 2, 8, -1),
- (17, 2, 9, -3),
- (17, 2, 10, -4),
- (17, 2, 11, -2),
- (18, 2, 8, -1),
- (18, 2, 9, 1),
- (18, 2, 10, -2),
- (18, 2, 11, 2),
- (19, 2, 8, -1),
- (19, 2, 9, 1),
- (19, 2, 10, -2),
- (19, 2, 11, 2),
- (20, 2, 8, 1),
- (20, 2, 9, 2),
- (20, 2, 10, -1),
- (20, 2, 11, 3);
+ SELECT MAX("id") INTO "issue_id_1_v" FROM "issue";
+
+ INSERT INTO "initiative" ("issue_id", "name") VALUES
+ ("issue_id_1_v", 'Initiative #1'), -- id 1
+ ("issue_id_1_v", 'Initiative #2'), -- id 2
+ ("issue_id_1_v", 'Initiative #3'), -- id 3
+ ("issue_id_1_v", 'Initiative #4'), -- id 4
+ ("issue_id_1_v", 'Initiative #5'), -- id 5
+ ("issue_id_1_v", 'Initiative #6'), -- id 6
+ ("issue_id_1_v", 'Initiative #7'); -- id 7
+
+ SELECT MAX("id")-6 INTO "initiative_id_base1_v" FROM "initiative";
+
+ INSERT INTO "draft" ("initiative_id", "author_id", "content") VALUES
+ ("initiative_id_base1_v" , 17, 'Lorem ipsum...'), -- id 1
+ ("initiative_id_base1_v"+1, 20, 'Lorem ipsum...'), -- id 2
+ ("initiative_id_base1_v"+2, 20, 'Lorem ipsum...'), -- id 3
+ ("initiative_id_base1_v"+3, 20, 'Lorem ipsum...'), -- id 4
+ ("initiative_id_base1_v"+4, 14, 'Lorem ipsum...'), -- id 5
+ ("initiative_id_base1_v"+5, 11, 'Lorem ipsum...'), -- id 6
+ ("initiative_id_base1_v"+6, 12, 'Lorem ipsum...'); -- id 7
+
+ SELECT MAX("id")-6 INTO "draft_id_base1_v" FROM "draft";
+
+ INSERT INTO "initiator" ("initiative_id", "member_id") VALUES
+ ("initiative_id_base1_v" , 17),
+ ("initiative_id_base1_v" , 19),
+ ("initiative_id_base1_v"+1, 20),
+ ("initiative_id_base1_v"+2, 20),
+ ("initiative_id_base1_v"+3, 20),
+ ("initiative_id_base1_v"+4, 14),
+ ("initiative_id_base1_v"+5, 11),
+ ("initiative_id_base1_v"+6, 12);
+
+ INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES
+ ( 7, "initiative_id_base1_v"+3, "draft_id_base1_v"+3),
+ ( 8, "initiative_id_base1_v"+1, "draft_id_base1_v"+1),
+ (11, "initiative_id_base1_v"+5, "draft_id_base1_v"+5),
+ (12, "initiative_id_base1_v"+6, "draft_id_base1_v"+6),
+ (14, "initiative_id_base1_v" , "draft_id_base1_v" ),
+ (14, "initiative_id_base1_v"+1, "draft_id_base1_v"+1),
+ (14, "initiative_id_base1_v"+2, "draft_id_base1_v"+2),
+ (14, "initiative_id_base1_v"+3, "draft_id_base1_v"+3),
+ (14, "initiative_id_base1_v"+4, "draft_id_base1_v"+4),
+ (14, "initiative_id_base1_v"+5, "draft_id_base1_v"+5),
+ (14, "initiative_id_base1_v"+6, "draft_id_base1_v"+6),
+ (17, "initiative_id_base1_v" , "draft_id_base1_v" ),
+ (17, "initiative_id_base1_v"+2, "draft_id_base1_v"+2),
+ (19, "initiative_id_base1_v" , "draft_id_base1_v" ),
+ (19, "initiative_id_base1_v"+1, "draft_id_base1_v"+1),
+ (20, "initiative_id_base1_v" , "draft_id_base1_v" ),
+ (20, "initiative_id_base1_v"+1, "draft_id_base1_v"+1),
+ (20, "initiative_id_base1_v"+2, "draft_id_base1_v"+2),
+ (20, "initiative_id_base1_v"+3, "draft_id_base1_v"+3),
+ (20, "initiative_id_base1_v"+4, "draft_id_base1_v"+4);
+
+ INSERT INTO "suggestion" ("initiative_id", "author_id", "name", "content") VALUES
+ ("initiative_id_base1_v", 19, 'Suggestion #1', 'Lorem ipsum...'); -- id 1
+
+ SELECT MAX("id") INTO "suggestion_id_base1_v" FROM "suggestion";
+
+ INSERT INTO "opinion" ("member_id", "suggestion_id", "degree", "fulfilled") VALUES
+ (14, "suggestion_id_base1_v", 2, FALSE);
+ INSERT INTO "opinion" ("member_id", "suggestion_id", "degree", "fulfilled") VALUES
+ (19, "suggestion_id_base1_v", 2, FALSE);
+
+
+
+ INSERT INTO "issue" ("area_id", "policy_id") VALUES
+ (3, 1); -- id 2
+
+ SELECT MAX("id") INTO "issue_id_2_v" FROM "issue";
+
+ INSERT INTO "initiative" ("issue_id", "name") VALUES
+ ("issue_id_2_v", 'Initiative A'), -- id 8
+ ("issue_id_2_v", 'Initiative B'), -- id 9
+ ("issue_id_2_v", 'Initiative C'), -- id 10
+ ("issue_id_2_v", 'Initiative D'); -- id 11
+
+ SELECT MAX("id")-3 INTO "initiative_id_base2_v" FROM "initiative";
+
+ INSERT INTO "draft" ("initiative_id", "author_id", "content") VALUES
+ ("initiative_id_base2_v" , 1, 'Lorem ipsum...'), -- id 8
+ ("initiative_id_base2_v"+1, 2, 'Lorem ipsum...'), -- id 9
+ ("initiative_id_base2_v"+2, 3, 'Lorem ipsum...'), -- id 10
+ ("initiative_id_base2_v"+3, 4, 'Lorem ipsum...'); -- id 11
+
+ SELECT MAX("id")-3 INTO "draft_id_base2_v" FROM "draft";
+
+ INSERT INTO "initiator" ("initiative_id", "member_id") VALUES
+ ("initiative_id_base2_v" , 1),
+ ("initiative_id_base2_v"+1, 2),
+ ("initiative_id_base2_v"+2, 3),
+ ("initiative_id_base2_v"+3, 4);
+
+ INSERT INTO "supporter" ("member_id", "initiative_id", "draft_id") VALUES
+ (1, "initiative_id_base2_v" , "draft_id_base2_v" ),
+ (1, "initiative_id_base2_v"+1, "draft_id_base2_v"+1),
+ (1, "initiative_id_base2_v"+2, "draft_id_base2_v"+2),
+ (1, "initiative_id_base2_v"+3, "draft_id_base2_v"+3),
+ (2, "initiative_id_base2_v" , "draft_id_base2_v" ),
+ (2, "initiative_id_base2_v"+1, "draft_id_base2_v"+1),
+ (2, "initiative_id_base2_v"+2, "draft_id_base2_v"+2),
+ (2, "initiative_id_base2_v"+3, "draft_id_base2_v"+3),
+ (3, "initiative_id_base2_v" , "draft_id_base2_v" ),
+ (3, "initiative_id_base2_v"+1, "draft_id_base2_v"+1),
+ (3, "initiative_id_base2_v"+2, "draft_id_base2_v"+2),
+ (3, "initiative_id_base2_v"+3, "draft_id_base2_v"+3),
+ (4, "initiative_id_base2_v" , "draft_id_base2_v" ),
+ (4, "initiative_id_base2_v"+1, "draft_id_base2_v"+1),
+ (4, "initiative_id_base2_v"+2, "draft_id_base2_v"+2),
+ (4, "initiative_id_base2_v"+3, "draft_id_base2_v"+3),
+ (5, "initiative_id_base2_v" , "draft_id_base2_v" ),
+ (5, "initiative_id_base2_v"+1, "draft_id_base2_v"+1),
+ (5, "initiative_id_base2_v"+2, "draft_id_base2_v"+2),
+ (5, "initiative_id_base2_v"+3, "draft_id_base2_v"+3),
+ (6, "initiative_id_base2_v" , "draft_id_base2_v" ),
+ (6, "initiative_id_base2_v"+1, "draft_id_base2_v"+1),
+ (6, "initiative_id_base2_v"+2, "draft_id_base2_v"+2),
+ (6, "initiative_id_base2_v"+3, "draft_id_base2_v"+3);
+
+ PERFORM "time_warp"();
+ PERFORM "time_warp"();
+ -- NOTE: When system_setting.ext_voting_service=TRUE this last time warp
+ -- does nothing. But there is a point in testing that it really does nothing.
+ PERFORM "time_warp"();
+
+ -- NOTE: When system_setting.ext_voting_service=TRUE, the public votes
+ -- are stored into these tables just the same as real votes when it is =FALSE.
+ INSERT INTO "direct_voter" ("member_id", "issue_id") VALUES
+ ( 8, "issue_id_1_v"),
+ ( 9, "issue_id_1_v"),
+ (11, "issue_id_1_v"),
+ (12, "issue_id_1_v"),
+ (14, "issue_id_1_v"),
+ (19, "issue_id_1_v"),
+ (20, "issue_id_1_v"),
+ (21, "issue_id_1_v");
+
+ INSERT INTO "vote" ("member_id", "issue_id", "initiative_id", "grade") VALUES
+ ( 8, "issue_id_1_v", "initiative_id_base1_v" , 1),
+ ( 8, "issue_id_1_v", "initiative_id_base1_v"+1, 1),
+ ( 8, "issue_id_1_v", "initiative_id_base1_v"+2, 1),
+ ( 8, "issue_id_1_v", "initiative_id_base1_v"+3, 1),
+ ( 8, "issue_id_1_v", "initiative_id_base1_v"+4, 1),
+ ( 8, "issue_id_1_v", "initiative_id_base1_v"+5, -1),
+ ( 8, "issue_id_1_v", "initiative_id_base1_v"+6, -1),
+ ( 9, "issue_id_1_v", "initiative_id_base1_v" , -2),
+ ( 9, "issue_id_1_v", "initiative_id_base1_v"+1, -3),
+ ( 9, "issue_id_1_v", "initiative_id_base1_v"+2, -2),
+ ( 9, "issue_id_1_v", "initiative_id_base1_v"+3, -2),
+ ( 9, "issue_id_1_v", "initiative_id_base1_v"+4, -2),
+ ( 9, "issue_id_1_v", "initiative_id_base1_v"+5, -1),
+ (11, "issue_id_1_v", "initiative_id_base1_v" , -1),
+ (11, "issue_id_1_v", "initiative_id_base1_v"+1, -1),
+ (11, "issue_id_1_v", "initiative_id_base1_v"+2, -1),
+ (11, "issue_id_1_v", "initiative_id_base1_v"+3, -1),
+ (11, "issue_id_1_v", "initiative_id_base1_v"+4, -1),
+ (11, "issue_id_1_v", "initiative_id_base1_v"+5, 2),
+ (11, "issue_id_1_v", "initiative_id_base1_v"+6, 1),
+ (12, "issue_id_1_v", "initiative_id_base1_v" , -1),
+ (12, "issue_id_1_v", "initiative_id_base1_v"+2, -1),
+ (12, "issue_id_1_v", "initiative_id_base1_v"+3, -1),
+ (12, "issue_id_1_v", "initiative_id_base1_v"+4, -1),
+ (12, "issue_id_1_v", "initiative_id_base1_v"+5, -2),
+ (12, "issue_id_1_v", "initiative_id_base1_v"+6, 1),
+ (14, "issue_id_1_v", "initiative_id_base1_v" , 1),
+ (14, "issue_id_1_v", "initiative_id_base1_v"+1, 3),
+ (14, "issue_id_1_v", "initiative_id_base1_v"+2, 1),
+ (14, "issue_id_1_v", "initiative_id_base1_v"+3, 2),
+ (14, "issue_id_1_v", "initiative_id_base1_v"+4, 1),
+ (14, "issue_id_1_v", "initiative_id_base1_v"+5, 1),
+ (14, "issue_id_1_v", "initiative_id_base1_v"+6, 1),
+ (19, "issue_id_1_v", "initiative_id_base1_v" , 3),
+ (19, "issue_id_1_v", "initiative_id_base1_v"+1, 4),
+ (19, "issue_id_1_v", "initiative_id_base1_v"+2, 2),
+ (19, "issue_id_1_v", "initiative_id_base1_v"+3, 2),
+ (19, "issue_id_1_v", "initiative_id_base1_v"+4, 2),
+ (19, "issue_id_1_v", "initiative_id_base1_v"+6, 1),
+ (20, "issue_id_1_v", "initiative_id_base1_v" , 1),
+ (20, "issue_id_1_v", "initiative_id_base1_v"+1, 2),
+ (20, "issue_id_1_v", "initiative_id_base1_v"+2, 1),
+ (20, "issue_id_1_v", "initiative_id_base1_v"+3, 1),
+ (20, "issue_id_1_v", "initiative_id_base1_v"+4, 1),
+ (21, "issue_id_1_v", "initiative_id_base1_v"+4, -1);
+
+ INSERT INTO "direct_voter" ("member_id", "issue_id") VALUES
+ ( 1, "issue_id_2_v"),
+ ( 2, "issue_id_2_v"),
+ ( 3, "issue_id_2_v"),
+ ( 4, "issue_id_2_v"),
+ ( 5, "issue_id_2_v"),
+ ( 6, "issue_id_2_v"),
+ ( 7, "issue_id_2_v"),
+ ( 8, "issue_id_2_v"),
+ ( 9, "issue_id_2_v"),
+ (10, "issue_id_2_v"),
+ (11, "issue_id_2_v"),
+ (12, "issue_id_2_v"),
+ (13, "issue_id_2_v"),
+ (14, "issue_id_2_v"),
+ (15, "issue_id_2_v"),
+ (16, "issue_id_2_v"),
+ (17, "issue_id_2_v"),
+ (18, "issue_id_2_v"),
+ (19, "issue_id_2_v"),
+ (20, "issue_id_2_v");
+
+ INSERT INTO "vote" ("member_id", "issue_id", "initiative_id", "grade") VALUES
+ ( 1, "issue_id_2_v", "initiative_id_base2_v" , 3),
+ ( 1, "issue_id_2_v", "initiative_id_base2_v"+1, 4),
+ ( 1, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 1, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 2, "issue_id_2_v", "initiative_id_base2_v" , 3),
+ ( 2, "issue_id_2_v", "initiative_id_base2_v"+1, 4),
+ ( 2, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 2, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 3, "issue_id_2_v", "initiative_id_base2_v" , 4),
+ ( 3, "issue_id_2_v", "initiative_id_base2_v"+1, 3),
+ ( 3, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 3, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 4, "issue_id_2_v", "initiative_id_base2_v" , 4),
+ ( 4, "issue_id_2_v", "initiative_id_base2_v"+1, 3),
+ ( 4, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 4, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 5, "issue_id_2_v", "initiative_id_base2_v" , 4),
+ ( 5, "issue_id_2_v", "initiative_id_base2_v"+1, 3),
+ ( 5, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 5, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 6, "issue_id_2_v", "initiative_id_base2_v" , 4),
+ ( 6, "issue_id_2_v", "initiative_id_base2_v"+1, 3),
+ ( 6, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 6, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 7, "issue_id_2_v", "initiative_id_base2_v" , 4),
+ ( 7, "issue_id_2_v", "initiative_id_base2_v"+1, 3),
+ ( 7, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 7, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 8, "issue_id_2_v", "initiative_id_base2_v" , 4),
+ ( 8, "issue_id_2_v", "initiative_id_base2_v"+1, 3),
+ ( 8, "issue_id_2_v", "initiative_id_base2_v"+2, 2),
+ ( 8, "issue_id_2_v", "initiative_id_base2_v"+3, 1),
+ ( 9, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ ( 9, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ ( 9, "issue_id_2_v", "initiative_id_base2_v"+2, 3),
+ ( 9, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (10, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (10, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (10, "issue_id_2_v", "initiative_id_base2_v"+2, 3),
+ (10, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (11, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (11, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (11, "issue_id_2_v", "initiative_id_base2_v"+2, 3),
+ (11, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (12, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (12, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (12, "issue_id_2_v", "initiative_id_base2_v"+2, 3),
+ (12, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (13, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (13, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (13, "issue_id_2_v", "initiative_id_base2_v"+2, 3),
+ (13, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (14, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (14, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (14, "issue_id_2_v", "initiative_id_base2_v"+2, 3),
+ (14, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (15, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (15, "issue_id_2_v", "initiative_id_base2_v"+1, -3),
+ (15, "issue_id_2_v", "initiative_id_base2_v"+2, -4),
+ (15, "issue_id_2_v", "initiative_id_base2_v"+3, -2),
+ (16, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (16, "issue_id_2_v", "initiative_id_base2_v"+1, -3),
+ (16, "issue_id_2_v", "initiative_id_base2_v"+2, -4),
+ (16, "issue_id_2_v", "initiative_id_base2_v"+3, -2),
+ (17, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (17, "issue_id_2_v", "initiative_id_base2_v"+1, -3),
+ (17, "issue_id_2_v", "initiative_id_base2_v"+2, -4),
+ (17, "issue_id_2_v", "initiative_id_base2_v"+3, -2),
+ (18, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (18, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (18, "issue_id_2_v", "initiative_id_base2_v"+2, -2),
+ (18, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (19, "issue_id_2_v", "initiative_id_base2_v" , -1),
+ (19, "issue_id_2_v", "initiative_id_base2_v"+1, 1),
+ (19, "issue_id_2_v", "initiative_id_base2_v"+2, -2),
+ (19, "issue_id_2_v", "initiative_id_base2_v"+3, 2),
+ (20, "issue_id_2_v", "initiative_id_base2_v" , 1),
+ (20, "issue_id_2_v", "initiative_id_base2_v"+1, 2),
+ (20, "issue_id_2_v", "initiative_id_base2_v"+2, -1),
+ (20, "issue_id_2_v", "initiative_id_base2_v"+3, 3);
+
+ -- When system_setting.ext_voting_service=FALSE, this closes voting and
+ -- calculates results. In this case we are done.
+ -- When it is =TRUE, this closes both private and public voting time.
+ PERFORM "time_warp"();
+ -- Extra check_issue does nothing...
+ PERFORM "check_everything"();
+
+ -- For system_setting.ext_voting_service=TRUE we now provide voting
+ -- results "from the external system", and then calculate ranks.
+ -- The results here are identical to what the public voting above ends up to,
+ -- although in reality that may not be the case.
+ SELECT "ext_voting_service" INTO "ext_voting_service_v" FROM "system_setting";
+ IF "ext_voting_service_v" = TRUE THEN
+ INSERT INTO battle ("issue_id", "winning_initiative_id", "losing_initiative_id", "count")
+ VALUES
+ ("issue_id_1_v", "initiative_id_base1_v"+2, "initiative_id_base1_v"+1, 4),
+ ("issue_id_1_v", "initiative_id_base1_v"+2, "initiative_id_base1_v"+5, 10),
+ ("issue_id_1_v", "initiative_id_base1_v"+5, "initiative_id_base1_v"+6, 2),
+ ("issue_id_1_v", "initiative_id_base1_v"+5, "initiative_id_base1_v"+4, 7),
+ ("issue_id_1_v", "initiative_id_base1_v"+1, "initiative_id_base1_v"+5, 13),
+ ("issue_id_1_v", "initiative_id_base1_v"+4, "initiative_id_base1_v"+3, 0),
+ ("issue_id_1_v", "initiative_id_base1_v"+2, "initiative_id_base1_v"+4, 1),
+ ("issue_id_1_v", "initiative_id_base1_v"+1, "initiative_id_base1_v"+6, 11),
+ ("issue_id_1_v", "initiative_id_base1_v"+1, "initiative_id_base1_v"+4, 11),
+ ("issue_id_1_v", "initiative_id_base1_v"+2, "initiative_id_base1_v"+6, 8),
+ ("issue_id_1_v", "initiative_id_base1_v"+5, "initiative_id_base1_v"+1, 6),
+ ("issue_id_1_v", NULL , "initiative_id_base1_v"+1, 6),
+ ("issue_id_1_v", "initiative_id_base1_v"+5, "initiative_id_base1_v"+2, 6),
+ ("issue_id_1_v", NULL , "initiative_id_base1_v"+2, 8),
+ ("issue_id_1_v", "initiative_id_base1_v"+3, NULL , 11),
+ ("issue_id_1_v", "initiative_id_base1_v"+6, "initiative_id_base1_v"+3, 8),
+ ("issue_id_1_v", "initiative_id_base1_v"+5, "initiative_id_base1_v"+3, 6),
+ ("issue_id_1_v", NULL , "initiative_id_base1_v"+3, 8),
+ ("issue_id_1_v", "initiative_id_base1_v"+3, "initiative_id_base1_v"+4, 4),
+ ("issue_id_1_v", "initiative_id_base1_v"+6, "initiative_id_base1_v"+2, 8),
+ ("issue_id_1_v", "initiative_id_base1_v"+3, "initiative_id_base1_v"+6, 11),
+ ("issue_id_1_v", "initiative_id_base1_v"+6, "initiative_id_base1_v"+1, 8),
+ ("issue_id_1_v", "initiative_id_base1_v"+4, "initiative_id_base1_v"+5, 10),
+ ("issue_id_1_v", "initiative_id_base1_v"+4, "initiative_id_base1_v"+2, 0),
+ ("issue_id_1_v", "initiative_id_base1_v"+4, "initiative_id_base1_v"+1, 4),
+ ("issue_id_1_v", "initiative_id_base1_v"+6, "initiative_id_base1_v"+5, 9),
+ ("issue_id_1_v", "initiative_id_base1_v"+2, NULL , 11),
+ ("issue_id_1_v", "initiative_id_base1_v"+1, NULL , 11),
+ ("issue_id_1_v", "initiative_id_base1_v"+6, "initiative_id_base1_v"+4, 9),