summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-01-31 14:54:02 +1100
committerJed Barber <jjbarber@y7mail.com>2017-01-31 14:54:02 +1100
commitca7337e57786a0db79865d63e797b574942795e0 (patch)
tree7f46e4ae14eb8816c195bd09cb9076a25a074c5e /src
parent0e233d7687bf121c48727cf4ff06767b4ab04d4c (diff)
Improved CSV unparsing and more checks on doCount input
Diffstat (limited to 'src')
-rw-r--r--src/CSV.hs5
-rw-r--r--src/Counter.hs11
2 files changed, 14 insertions, 2 deletions
diff --git a/src/CSV.hs b/src/CSV.hs
index dd56961..b4850b4 100644
--- a/src/CSV.hs
+++ b/src/CSV.hs
@@ -55,7 +55,10 @@ specialChars s = (separator s):(quote s):(escape s):[]
unParseRecord :: Settings -> [String] -> String
unParseRecord settings record =
let escFunc c = if (c == escape settings || c == quote settings) then (escape settings):c:[] else c:[]
- escapeField s = ((quote settings) : (concatMap escFunc s)) ++ ((quote settings):[])
+ escapeField s =
+ if ((escape settings) `elem` s || (quote settings) `elem` s || (separator settings) `elem` s)
+ then ((quote settings) : (concatMap escFunc s)) ++ ((quote settings):[])
+ else s
in List.intercalate [separator settings] (map escapeField record)
diff --git a/src/Counter.hs b/src/Counter.hs
index 2bcd2d7..bf2ee7e 100644
--- a/src/Counter.hs
+++ b/src/Counter.hs
@@ -113,7 +113,9 @@ doCount sen criteria = do
r <- testFunc n 1 1
if r then tailFunc (n + 1) (p + 1) else tailFunc (n + 1) p
- tailFunc 1 0
+ if (all (isValid (ballotMap sen)) criteria)
+ then tailFunc 1 0
+ else return 0
@@ -130,6 +132,13 @@ toInternal ballot (Right cs) =
+isValid :: Typ.BelowLineBallot -> Either Typ.CandidateID [Typ.CandidateID] -> Bool
+isValid ballot (Left x) = x `elem` ballot
+isValid ballot (Right xs) = all (`elem` ballot) xs
+
+
+
+
getBallot :: SenateCounter -> Typ.BelowLineBallot
getBallot = ballotMap