-
Notifications
You must be signed in to change notification settings - Fork 41
/
GetData.hs
51 lines (47 loc) · 2.15 KB
/
GetData.hs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE OverloadedStrings #-}
import Codec.Archive.Zip
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe (fromJust)
import Data.Monoid (First(..))
import Network.HTTP.Client
import Network.HTTP.Client.TLS (tlsManagerSettings)
import System.Directory (createDirectoryIfMissing)
getPrestige :: IO ()
getPrestige = do m <- newManager tlsManagerSettings
httpLbs req m >>=
B.writeFile "data/prestige.csv" . responseBody
where Just req = parseUrlThrow "https://vincentarelbundock.github.io/Rdatasets/csv/carData/Prestige.csv"
getFLinsurance :: IO ()
getFLinsurance = do m <- newManager defaultManagerSettings
httpLbs req m >>=
B.writeFile "data/FL2.csv"
. B.map fixup . fromEntry . fromJust
. findEntryByPath "FL_insurance_sample.csv"
. toArchive
. responseBody
where fixup '\r' = '\n'
fixup c = c
Just req = parseUrlThrow "http://spatialkeydocs.s3.amazonaws.com/FL_insurance_sample.csv.zip"
getAdultIncome :: IO ()
getAdultIncome = do m <- newManager defaultManagerSettings
httpLbs req m >>=
B.writeFile "data/adult.csv"
. B.append colNames
. B.unlines
. map (\ln -> maybe ln id
. getFirst
$ foldMap (First . ($ ln))
[ B.stripSuffix ", <=50K"
, B.stripSuffix ", >50K" ])
. B.lines
. responseBody
where Just req = parseUrlThrow "http://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data"
colNames = "age, workclass, fnlwgt, education, education-num, \
\marital-status, occupation, relationship, race, sex, \
\capital-gain, capital-loss, hours-per-week, \
\native-country\n"
main :: IO ()
main = do createDirectoryIfMissing False "data"
getPrestige
getFLinsurance
getAdultIncome