-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimpletest.hs
62 lines (40 loc) · 1.48 KB
/
simpletest.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
52
53
54
55
56
57
58
59
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
import Data.Aeson
import Data.Aeson.Types (Pair)
import qualified Data.Text as T
import Data.Aeson.Encode.Pretty
import qualified Data.ByteString.Lazy.Char8 as BL
import KpiStructure
instance ToJSON KpiStruct where
toJSON KpiStruct{..} = object [kpiName .= kpiData]
instance ToJSON ServStruct where
toJSON ServStruct{..} = object [servName .= kpis]
main = BL.putStrLn.servToBS $ services
servToBS :: Services -> BL.ByteString
servToBS = encode . map toJSON
services :: Services
services = map toServStruct servList
toServStruct :: T.Text -> ServStruct
toServStruct s = ServStruct s (getKpitStruct s)
-- value test
servList :: [T.Text]
servList = ["BIV","BTIC","BIC"]
mos = toJSON ([4.3,2.3,4.9]::[Double])
comment = rowDataToValue (["Bon","Mauvais","Tres Bon"]::[String])
kpiTup :: [Pair]
kpiTup = zip ["mos","CommentMos"] [mos,comment]
toKpiStruct dict = [KpiStruct x y |(x,y) <- dict ]
kpiTupToValue :: [Pair] -> Value
kpiTupToValue dict = object.map (uncurry (.=)) $ dict
servToVal :: T.Text -> [Pair] -> Value
servToVal s kpitup = object [s.= kpiTupToValue kpitup]
----test
getKpitStruct :: T.Text -> [KpiStruct]
getKpitStruct s = toKpiStruct kpiTup
rowDataToValue :: ToJSON a => a -> Value
rowDataToValue = toJSON
----test
--kpisBIV = ServStruct "BIV" (toKpiStruct kpiTup)
--kpisBIC = ServStruct "BIC" (toKpiStruct kpiTup)
--kpisBTIC = ServStruct "BTIC" (toKpiStruct kpiTup)
--services = [kpisBIV,kpisBIC, kpisBTIC]