From 8f2f6a5e2074a5da684f9f1a5f5e8f3c51a82b76 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 6 Feb 2017 13:34:23 +1100 Subject: More or less completed main procedure, fixed some bugs --- src/stv.adb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 5 deletions(-) (limited to 'src/stv.adb') diff --git a/src/stv.adb b/src/stv.adb index 01c7a38..4d2691a 100644 --- a/src/stv.adb +++ b/src/stv.adb @@ -23,6 +23,7 @@ procedure STV is use type File.File_Kind; use type SU.Unbounded_String; + use type Simple_Time.Time; Config : GCom.Command_Line_Configuration; @@ -31,6 +32,7 @@ procedure STV is Further_Help : String := "Try ""stv --help"" for more information."; + -- I'm not fond of accesses to string accesses Verbose : aliased Boolean; Version : aliased Boolean; Help : aliased Boolean; @@ -41,12 +43,19 @@ procedure STV is State_String : aliased GStr.String_Access; - type State_Name is (ACT, NT, TAS, SA, WA, VIC, QLD, NSW); - State : State_Name; + State : Candidates.State_Name; Start_Time, Finish_Time : Simple_Time.Time; + + Main_Log, Log_Msg : SU.Unbounded_String; + Log_File : File_Type; + + + Candidate_List : Candidates.Candidate_Vector; + Above_Ballot : Candidates.Above_Line_Ballot; + Below_Ballot : Candidates.Below_Line_Ballot; begin @@ -174,7 +183,7 @@ begin -- check state option is valid begin - State := State_Name'Value (State_String.all); + State := Candidates.State_Name'Value (State_String.all); exception when Constraint_Error => Put_Line ("Invalid State/Territory or State/Territory not provided." & ASCII.LF & Further_Help); @@ -184,14 +193,59 @@ begin -- set up logging - --File.Create_Directory (Output_Dir.all); + File.Create_Directory (Output_Dir.all); Start_Time := Simple_Time.Now; Main_Log := SU.To_Unbounded_String (Output_Dir.all & "/" & "log.txt"); Log_Msg := SU.To_Unbounded_String ("Started election count at " & Simple_Time.To_String (Start_Time)); - Put_Line (SU.To_String (Log_Msg)); + Create (Log_File, Append_File, SU.To_String (Main_Log)); + Put_Line (Log_File, SU.To_String (Log_Msg)); + Close (Log_File); + if Verbose then + Put_Line (Standard_Error, SU.To_String (Log_Msg)); + end if; + + + -- set up the election processing + 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); + 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; + + -- 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; + + -- finish up logging Finish_Time := Simple_Time.Now; + Log_Msg := SU.To_Unbounded_String + ("Finished election count at " & Simple_Time.To_String (Finish_Time) & ASCII.LF & + Duration'Image (Finish_Time - Start_Time) & " seconds elapsed." & ASCII.LF); + Open (Log_File, Append_File, SU.To_String (Main_Log)); + Put_Line (Log_File, SU.To_String (Log_Msg)); + Close (Log_File); + if Verbose then + Put_Line (Standard_Error, SU.To_String (Log_Msg)); + end if; end STV; -- cgit