From 60b2207a469a5a1e7a7e5619a8eb1b01c67f314a Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Fri, 10 Feb 2017 18:41:36 +1100 Subject: Preference data reads into Bundles properly, with packed memory and a few fixed bugs --- src/stv.adb | 77 ++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 26 deletions(-) (limited to 'src/stv.adb') 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 -- cgit