-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualization.elm
63 lines (55 loc) · 2 KB
/
Visualization.elm
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
60
61
62
63
port module Visualization exposing (..)
import Dict exposing (Dict)
import OutageDetection exposing (NodeOutage)
import Time
import VegaLite exposing (..)
port elmToJS : Spec -> Cmd msg
allSummaryVisualizations : List NodeOutage -> Dict String Int -> Spec
allSummaryVisualizations outages outagesPerNode =
combineSpecs [
("outages-counts-summary", outagesCountsPerNodeVisualization outagesPerNode),
("outages-lengths-summary", outagesLenghtsPerNodeVisualization outages)
]
outagesCountsPerNodeVisualization : Dict String Int -> Spec
outagesCountsPerNodeVisualization outagesPerNode =
let
outagesPerNodeList : List DataRow
outagesPerNodeList = outagesPerNode
|> Dict.toList
|> List.foldl (\(nodeId, numOutages) acc ->
dataRow [ ("node id", str nodeId), ("outages count", num (toFloat numOutages)) ] acc
) []
data =
dataFromRows [] outagesPerNodeList
enc =
encoding
<< position X [ pName "node id", pOrdinal ]
<< position Y [ pName "outages count", pQuant ]
in
toVegaLite
[ title "Number of outages per node" []
, data
, enc []
, bar []
]
outagesLenghtsPerNodeVisualization : List NodeOutage -> Spec
outagesLenghtsPerNodeVisualization outages =
let
outagesPerNodeList : List DataRow
outagesPerNodeList = outages
|> List.foldl (\{affectedNodeId, duration} acc ->
dataRow [ ("node id", str affectedNodeId), ("outage duration", num (toFloat (Time.posixToMillis duration // 1000))) ] acc
) []
data =
dataFromRows [] outagesPerNodeList
enc =
encoding
<< position X [ pName "node id", pOrdinal ]
<< position Y [ pName "outage duration", pAggregate opSum, pQuant ]
in
toVegaLite
[ title "Outage duration per node (in seconds)" []
, data
, enc []
, bar []
]