summaryrefslogtreecommitdiff
path: root/src/stv.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-02-06 13:34:23 +1100
committerJed Barber <jjbarber@y7mail.com>2017-02-06 13:34:23 +1100
commit8f2f6a5e2074a5da684f9f1a5f5e8f3c51a82b76 (patch)
tree2b11d86d759867e35db6489743355d2761c5bb53 /src/stv.adb
parentc2f324ac23ea143dfea308229f0ac0376ed4f745 (diff)
More or less completed main procedure, fixed some bugs
Diffstat (limited to 'src/stv.adb')
-rw-r--r--src/stv.adb64
1 files changed, 59 insertions, 5 deletions
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;