Files
to-hen/onomastics-ng/cli/Main.hs

53 lines
1.8 KiB
Haskell
Raw Normal View History

2022-04-17 21:04:13 +02:00
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import Data.Text (Text)
2022-04-19 23:11:06 +02:00
import qualified Data.Text.IO as Text
2022-04-17 21:04:13 +02:00
import Network.HTTP.Client.TLS (newTlsManager)
2022-04-19 23:11:06 +02:00
import Onomap.Stoepel
import Onomap.Svg
import Onomap.Types
2022-04-17 21:04:13 +02:00
import Options.Applicative
data Options = Options
{ mode :: Mode
2022-10-07 02:21:34 +02:00
, surnames :: [Text]
, colorPalette :: [Text]
2022-04-17 21:04:13 +02:00
, areaMode :: AreaKind
}
parseOptions :: Parser Options
parseOptions =
Options
<$> flag Absolute Relative (long "relative" <> help "Relative numbers (instead of absolute)")
2022-10-07 02:21:34 +02:00
<*> some (strArgument (metavar "SURNAME" <> help "Surname"))
<*> many (strOption (long "color" <> metavar "COLOR" <> help "Color palette for the SVG"))
2022-04-17 21:04:13 +02:00
<*> flag District State (long "states" <> help "Analyze by state (instead of district)")
opts :: ParserInfo Options
opts = info (parseOptions <**> helper) (fullDesc <> progDesc "Map your German surname")
main :: IO ()
main = do
options <- execParser opts
manager' <- newTlsManager
let computeFunction =
case mode options of
Relative -> relativeCount
Absolute -> absoluteCount
2022-10-07 02:40:01 +02:00
colors = colorPalette options ++ defaultColorPalette
2022-10-07 02:21:34 +02:00
svgSettings = SvgSettings{scaleToMaximum = Global}
2022-04-17 21:04:13 +02:00
res <- runStoepel manager' $ do
2022-10-07 02:21:34 +02:00
let theNames = map Just (surnames options)
2022-04-19 23:11:06 +02:00
ds <- case areaMode options of
State -> states
District -> districts
theStats <- case areaMode options of
2022-10-07 02:21:34 +02:00
State -> mapM stateStatistics theNames
District -> mapM districtStatistics theNames
let stats = map (computeAreaStatistics computeFunction ds) theStats
return $ renderMap svgSettings colors ds (zip (surnames options) stats)
2022-04-19 23:11:06 +02:00
Text.putStrLn res