From 348dc88775fac78f5c1afa30c4f00d6d14dff592 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 12 Feb 2017 23:07:52 +1100 Subject: Election counting now works, logging improved from Haskell version, still need to fix exhausted paper collection --- src/stv.adb | 55 ++++++++++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'src/stv.adb') 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; -- cgit