diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Counter.hs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/Counter.hs b/src/Counter.hs index 48429ef..021ac45 100644 --- a/src/Counter.hs +++ b/src/Counter.hs @@ -37,10 +37,9 @@ data SenateCounter = SenateCounter createSenateCounter :: FilePath -> Typ.AboveLineBallot -> Typ.BelowLineBallot -> IO SenateCounter createSenateCounter f a b = do - -- numLines <- File.countLines f arrayData <- Vec.createStore numLines (length b) - -- + h <- IO.openFile f IO.ReadMode let readFunc n p = if (n > numLines) then return p else do t0 <- IO.hGetLine h @@ -54,7 +53,7 @@ createSenateCounter f a b = do else readFunc (n + 1) p p <- readFunc 1 0 IO.hClose h - -- + return (SenateCounter arrayData b p) @@ -62,15 +61,14 @@ createSenateCounter f a b = do doCount :: SenateCounter -> Criteria -> IO Int doCount sen criteria = do - -- let isValidCriteria = all (\(x,y) -> y `List.elem` (ballotMap sen)) criteria - -- + let critToPref (a,b) = (Maybe.fromJust (List.elemIndex b (ballotMap sen)) + 1, a) neededPrefs = map critToPref criteria - checkFunc n r = if (n > (numBallots sen)) then return r else do + checkFunc n r = if (n > numBallots sen) then return r else do t <- Con.liftM and (mapM (Vec.checkPref (prefData sen) n) neededPrefs) if t then checkFunc (n + 1) (r + 1) else checkFunc (n + 1) r - -- + if isValidCriteria then checkFunc 1 0 else return 0 |