summaryrefslogtreecommitdiff
path: root/src/stv.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-02-10 18:41:36 +1100
committerJed Barber <jjbarber@y7mail.com>2017-02-10 18:41:36 +1100
commit60b2207a469a5a1e7a7e5619a8eb1b01c67f314a (patch)
treec928299d78242f2b36798e8c1802914552626352 /src/stv.adb
parent964a28e91593c4bf1e1c132536828d87f8d12c84 (diff)
Preference data reads into Bundles properly, with packed memory and a few fixed bugs
Diffstat (limited to 'src/stv.adb')
-rw-r--r--src/stv.adb77
1 files changed, 51 insertions, 26 deletions
diff --git a/src/stv.adb b/src/stv.adb
index 65537c7..e6df17e 100644
--- a/src/stv.adb
+++ b/src/stv.adb
@@ -8,7 +8,9 @@ with Ada.Directories;
with Ada.Strings.Unbounded;
with Simple_Time;
with CSV;
-with Candidates;
+with Candidates.Containers;
+with Preferences;
+with Bundles.Containers;
procedure STV is
@@ -53,9 +55,9 @@ procedure STV is
Log_File : File_Type;
- Candidate_List : Candidates.Candidate_Vector;
- Above_Ballot : Candidates.Above_Line_Ballot;
- Below_Ballot : Candidates.Below_Line_Ballot;
+ Candidate_Data : Candidates.Containers.Candidate_Map;
+ Above_Ballot : Candidates.Containers.Above_Line_Ballot;
+ Below_Ballot : Candidates.Containers.Below_Line_Ballot;
begin
@@ -209,32 +211,55 @@ begin
if Verbose then
Put_Line (Standard_Error, "Reading candidate data...");
end if;
- Candidates.Read_Candidates (Candidate_File.all, State, Candidate_List);
- Candidates.Generate_Ballots (Candidate_List, Above_Ballot, Below_Ballot);
+ Candidates.Containers.Read_Candidates (Candidate_File.all, State, Candidate_Data);
+ Candidates.Containers.Generate_Ballots (Candidate_Data, Above_Ballot, Below_Ballot);
- if Verbose then
- Put_Line (Standard_Error, "Reading preference data...");
- end if;
- -- read in preference data here
- 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;
+ declare
+ package Given_Prefs is new Preferences
+ (Pref_Size => Integer (Below_Ballot.Length),
+ Above_Ballot => Above_Ballot,
+ Below_Ballot => Below_Ballot);
+ package Vote_Bundles is new Bundles
+ (Given_Prefs => Given_Prefs);
- -- 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;
+ package Vote_Bundle_Containers is new Vote_Bundles.Containers;
+
+ Initial_Bundles : Vote_Bundle_Containers.Bundle_Maps.Map;
+ 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;
+ end;
-- finish up logging