summaryrefslogtreecommitdiff
path: root/src/main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.hs')
-rw-r--r--src/main.hs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main.hs b/src/main.hs
index 8ed8bb8..c66dc6e 100644
--- a/src/main.hs
+++ b/src/main.hs
@@ -18,6 +18,7 @@ import qualified System.Exit as Ex
import qualified System.Directory as Dir
import qualified System.IO as IO
import qualified Control.Monad as Con
+import qualified Data.Time.Clock as Time
import qualified Data.Maybe as Maybe
import qualified Counter as Sen
import qualified Candidate as Cand
@@ -174,20 +175,37 @@ main = do
Ex.die ("Invalid state/territory or state/territory not provided.\n\n" ++ furtherHelp)
+ -- set up logging
+ Dir.createDirectory outputDir
+ startTime <- Time.getCurrentTime
+ let mainLog = outputDir ++ "/" ++ "log.txt"
+ startmsg = "Started election count at " ++ show startTime ++ "\n"
+ IO.appendFile mainLog startmsg
+ Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr startmsg
+
+
-- set up the election processing
Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr "Reading candidate data..."
(aboveBallot, belowBallot) <- Cand.readCandidates candidateFile state
Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr "Reading preference data..."
counter <- Sen.createSenateCounter preferenceFile aboveBallot belowBallot
Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr "Done.\n"
- Dir.createDirectory outputDir
Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr "Setting up election..."
- election <- Elt.createElection outputDir counter numToElect (isVerbose options)
+ election <- Elt.createElection outputDir mainLog counter numToElect (isVerbose options)
Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr "Done.\n"
-- run the show
Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr "Running...\n"
Elt.doCount election
+ Con.when (isVerbose options) $ IO.hPutStr IO.stderr "\n"
+
+
+ -- finish up logging
+ endTime <- Time.getCurrentTime
+ let endmsg = "Finished election count at " ++ show endTime ++ "\n"
+ elapsedmsg = show (Time.diffUTCTime endTime startTime) ++ " elapsed\n"
+ IO.appendFile mainLog (endmsg ++ elapsedmsg)
+ Con.when (isVerbose options) $ IO.hPutStrLn IO.stderr (endmsg ++ elapsedmsg)