summaryrefslogtreecommitdiff
path: root/src/Election.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2017-01-26 21:11:21 +1100
committerJed Barber <jjbarber@y7mail.com>2017-01-26 21:11:21 +1100
commite7dbb4348d17f44c0f9162bea68738f3e2dc72f8 (patch)
tree5d0c2908c72f28b548c8ef4c18d32aba55f84401 /src/Election.hs
parentd07277cf6b1ae0d94fa3bf3829ddf1a2357e3d9d (diff)
Moving some code to Miscellaneous
Diffstat (limited to 'src/Election.hs')
-rw-r--r--src/Election.hs19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/Election.hs b/src/Election.hs
index be4fe05..39bcb22 100644
--- a/src/Election.hs
+++ b/src/Election.hs
@@ -19,6 +19,7 @@ import qualified Data.Either.Unwrap as Either
import qualified Counter as Sen
import qualified Candidate as Typ
import qualified CSV as CSV
+import qualified Miscellaneous as Misc
@@ -203,7 +204,7 @@ doElectCandidate :: Election -> ET.EitherT Election IO Election
doElectCandidate e = do
let (running, notRunning) = List.partition ((== Running) . getStatus) (getEntries e)
electedEntry = List.maximumBy compareVotes running
- (beforeEntries, afterEntries) = partBeforeAfter electedEntry (getEntries e)
+ (beforeEntries, afterEntries) = Misc.partBeforeAfter electedEntry (getEntries e)
newTransferValue = (fromIntegral (getTotalVotes electedEntry - getQuota e)) /
(fromIntegral (getTotalVotes electedEntry))
@@ -258,7 +259,7 @@ doVoteTransfer :: Election -> ET.EitherT Election IO Election
doVoteTransfer e = do
let (currentTransfer:remainingTransfers) = getTransferQueue e
fromEntry = Maybe.fromJust (List.find ((== getWhoFrom currentTransfer) . getID) (getEntries e))
- (beforeEntries, afterEntries) = partBeforeAfter fromEntry (getEntries e)
+ (beforeEntries, afterEntries) = Misc.partBeforeAfter fromEntry (getEntries e)
mapKeys = map getID (beforeEntries ++ afterEntries)
notRunningKeys = map getID (filter ((/= Running) . getStatus) (getEntries e))
@@ -371,7 +372,7 @@ checkNoQuota :: Election -> ET.EitherT Election IO Election
checkNoQuota e = do
let (running, notRunning) = List.partition ((== Running) . getStatus) (getEntries e)
minimumEntry = List.minimumBy compareVotes running
- (beforeEntries, afterEntries) = partBeforeAfter minimumEntry (getEntries e)
+ (beforeEntries, afterEntries) = Misc.partBeforeAfter minimumEntry (getEntries e)
makeElect x = x
{ getStatus = Elected
@@ -401,7 +402,7 @@ excludeSomeone :: Election -> ET.EitherT Election IO Election
excludeSomeone e = do
let (running, notRunning) = List.partition ((== Running) . getStatus) (getEntries e)
excludedEntry = List.minimumBy compareVotes running
- (beforeEntries, afterEntries) = partBeforeAfter excludedEntry (getEntries e)
+ (beforeEntries, afterEntries) = Misc.partBeforeAfter excludedEntry (getEntries e)
newTransfer = Transfer
{ getWhoFrom = getID excludedEntry
@@ -422,16 +423,6 @@ excludeSomeone e = do
-partBeforeAfter :: (Eq a) => a -> [a] -> ([a],[a])
-partBeforeAfter item list =
- let (x,y) = List.break (== item) list
- in if (length y <= 1)
- then (x,[])
- else (x,tail y)
-
-
-
-
compareVotes :: Entry -> Entry -> Ordering
compareVotes x y = compare (getTotalVotes x) (getTotalVotes y)