summaryrefslogtreecommitdiff
path: root/src/stv.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-02-12 23:07:52 +1100
committerJed Barber <jjbarber@y7mail.com>2017-02-12 23:07:52 +1100
commit348dc88775fac78f5c1afa30c4f00d6d14dff592 (patch)
treeb96db643d0642edf54242da5c672f3096bb98e22 /src/stv.adb
parent60b2207a469a5a1e7a7e5619a8eb1b01c67f314a (diff)
Election counting now works, logging improved from Haskell version, still need to fix exhausted paper collection
Diffstat (limited to 'src/stv.adb')
-rw-r--r--src/stv.adb55
1 files changed, 22 insertions, 33 deletions
diff --git a/src/stv.adb b/src/stv.adb
index e6df17e..4f8ef5a 100644
--- a/src/stv.adb
+++ b/src/stv.adb
@@ -11,6 +11,7 @@ with CSV;
with Candidates.Containers;
with Preferences;
with Bundles.Containers;
+with Election;
procedure STV is
@@ -183,6 +184,14 @@ begin
end if;
+ -- check number to elect option is valid
+ if Number_To_Elect < 1 then
+ Put_Line ("Number of candidates to be elected too low." & ASCII.LF & Further_Help);
+ ACom.Set_Exit_Status (ACom.Failure);
+ return;
+ end if;
+
+
-- check state option is valid
begin
State := Candidates.State_Name'Value (State_String.all);
@@ -207,7 +216,7 @@ begin
end if;
- -- set up the election processing
+ -- read in candidate data, which is necessary for further setup
if Verbose then
Put_Line (Standard_Error, "Reading candidate data...");
end if;
@@ -215,6 +224,7 @@ begin
Candidates.Containers.Generate_Ballots (Candidate_Data, Above_Ballot, Below_Ballot);
+ -- set up and run the election singleton
declare
package Given_Prefs is new Preferences
(Pref_Size => Integer (Below_Ballot.Length),
@@ -226,39 +236,18 @@ begin
package Vote_Bundle_Containers is new Vote_Bundles.Containers;
- Initial_Bundles : Vote_Bundle_Containers.Bundle_Maps.Map;
+ package This_Election is new Election
+ (Given_Bundles => Vote_Bundles,
+ Bundle_Containers => Vote_Bundle_Containers);
begin
- if Verbose then
- Put_Line (Standard_Error, "Reading preference data...");
- end if;
- Vote_Bundle_Containers.Read_Bundles (Preference_File.all, Initial_Bundles);
- if Verbose then
- Put_Line (Standard_Error, "Done." & ASCII.LF);
- Put_Line (Standard_Error, "Setting up election...");
- end if;
- -- set up election here
- if Verbose then
- Put_Line (Standard_Error, "Done." & ASCII.LF);
- end if;
-
-
- -- test output to check that votes were parsed correctly
- for Cursor in Initial_Bundles.Iterate loop
- Put_Line
- (Candidates.CandidateID'Image (Vote_Bundle_Containers.Bundle_Maps.Key (Cursor)) &
- " " &
- Integer'Image (Vote_Bundles.Count_Votes (Vote_Bundle_Containers.Bundle_Maps.Element (Cursor).Element (1))));
- end loop;
-
-
- -- run the show
- if Verbose then
- Put_Line (Standard_Error, "Running..." & ASCII.LF);
- end if;
- -- run election here
- if Verbose then
- New_Line (Standard_Error);
- end if;
+ This_Election.Setup
+ (Candidate_Data => Candidate_Data,
+ Preference_File => Preference_File.all,
+ Output_Dir => Output_Dir.all,
+ Main_Logfile => "log.txt",
+ Number_To_Elect => Number_To_Elect,
+ Is_Verbose => Verbose);
+ This_Election.Run;
end;