diff options
-rw-r--r-- | notes.txt | 5 | ||||
-rw-r--r-- | readme.txt | 1 | ||||
-rw-r--r-- | src/Election.hs | 15 | ||||
-rw-r--r-- | src/main.hs | 22 |
4 files changed, 36 insertions, 7 deletions
@@ -1,6 +1,5 @@ - future direction ---------------- @@ -22,5 +21,9 @@ group votes by uniqueness to reduce memory requirements, speed things up, and ac make the goddamn results correct are they correct now? it's a bit murky with how the AEC records transfers in DOP logs does the AEC use floats or exact ratios for transfer values? +does the AEC check for candidates having quota when transfers are only partially done? +why do the paper amounts go negative in AEC counts sometimes? + +place candidate IDs and party designations into different fields in logfiles @@ -19,6 +19,7 @@ Aside from base, the cabal packages required to compile this program are: parsec vector array + time diff --git a/src/Election.hs b/src/Election.hs index a475f0e..8a0e4d0 100644 --- a/src/Election.hs +++ b/src/Election.hs @@ -80,8 +80,8 @@ data Transfer = Transfer -createElection :: FilePath -> Sen.SenateCounter -> Int -> Bool -> IO Election -createElection outDir counter numToElect verbosity = do +createElection :: FilePath -> FilePath -> Sen.SenateCounter -> Int -> Bool -> IO Election +createElection outDir mainLog counter numToElect verbosity = do entries <- mapM (candToEntry counter) (Sen.getBallot counter) return (Election { getEntries = entries @@ -89,7 +89,7 @@ createElection outDir counter numToElect verbosity = do , getLogDir = outDir , getTotalPapers = Sen.getTotal counter , getQuota = droopQuota (Sen.getTotal counter) numToElect - , getMainLog = outDir ++ "/" ++ "log.txt" + , getMainLog = mainLog , getNextLogNum = 1 , getSeats = numToElect , getVacancies = numToElect @@ -360,7 +360,14 @@ excludeCandidates e = do let v1 = v + i n1 = n + 1 if (v1 > appliedBreakpoint) - then n > 0 ? ET.left e $ ET.left r + then if (n > 0) + then do + MIO.liftIO $ Con.when (n > 1) $ do + let logmsg = "Bulk exclusion at logfile #" ++ show (getNextLogNum e) + IO.appendFile (getMainLog e) (logmsg ++ "\n") + Con.when (isVerbose e) (IO.hPutStrLn IO.stderr logmsg) + ET.left e + else ET.left r else excludeLoop n1 v1 r if (length running > 0 && all (< getQuota e) (map getTotalVotes running)) 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) |