-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
30 lines (26 loc) · 1.06 KB
/
Main.hs
File metadata and controls
30 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Main where
import Control.Applicative ((<$>), (<*>))
import qualified Data.ByteString.Lazy as BSL
import Data.Csv (decodeByName)
import qualified Data.Foldable as F
import qualified Data.Map as M
import Data.Maybe (fromJust)
import qualified Data.Vector as V
import Tally
import Types
import Parse
main :: IO ()
main = do
listFile <- BSL.readFile "List.csv"
rankFile <- BSL.readFile "Rank.csv"
case tally listFile rankFile of
Left s -> putStrLn $ "Error: " ++ s
Right t -> putStrLn $ show t
tally :: BSL.ByteString -> BSL.ByteString -> Either String Tally
tally listFile rankFile = do
(listHeader,listVotes) <- decodeByName listFile
(rankHeader,rankVotes) <- decodeByName rankFile
let label = M.fromList . V.toList . fmap ((,) <$> username <*> id)
return $ F.foldMap voteToTally
$ M.unionWith (fmap fromJust . reconcile)
(label listVotes) (label rankVotes)