-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlignmentAesonPretty.hs
78 lines (68 loc) · 3.16 KB
/
AlignmentAesonPretty.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{-# LANGUAGE OverloadedStrings #-}
module AlignmentAesonPretty (
historyPersistentsEncode,
historyPersistentsEncodePrefixed,
transformPersistentsEncodePrefixed,
fudPersistentsEncode,
fudPersistentsEncodePrefixed,
decompFudsPersistentsEncode,
decompFudsPersistentsEncode_1
)
where
import Data.List as List
import qualified Data.Set as Set
import qualified Data.Map as Map
import qualified Data.Vector as Vector
import Control.Applicative
import Control.Monad
import Data.Aeson hiding (Value)
import Data.ByteString.Lazy.Char8
import Data.ByteString.Builder
import Data.Monoid
import GHC.Real
import GHC.Generics
import AlignmentUtil
import Alignment hiding (derived)
import AlignmentAeson
historyPersistentsEncode :: HistoryPersistent -> ByteString
historyPersistentsEncode hh =
mconcat $ ["{\n\t\"hsystem\":[\n"] ++
List.intersperse ",\n" ["\t\t" <> Data.Aeson.encode vv | let SystemPersistent uu = hsystem hh, vv <- uu] ++
["\n\t],\n\t\"hstates\":[\n"] ++
List.intersperse ",\n" ["\t\t" <> Data.Aeson.encode ss | ss <- hstates hh] ++ ["\n\t]\n}"]
historyPersistentsEncodePrefixed :: Int -> HistoryPersistent -> ByteString
historyPersistentsEncodePrefixed i hh =
mconcat $ ["{\n",p,"\t\"hsystem\":[\n"] ++
List.intersperse ",\n" [p <> "\t\t" <> Data.Aeson.encode vv | let SystemPersistent uu = hsystem hh, vv <- uu] ++
["\n",p,"\t],\n",p,"\t\"hstates\":[\n"] ++
List.intersperse ",\n" [p <> "\t\t" <> Data.Aeson.encode ss | ss <- hstates hh] ++ ["\n",p,"\t]\n",p,"}"]
where
p = pack $ List.replicate i '\t'
transformPersistentsEncodePrefixed :: Int -> TransformPersistent -> ByteString
transformPersistentsEncodePrefixed i hh =
mconcat $ ["{\n", p, "\t\"derived\":["] ++ List.intersperse "," (List.map Data.Aeson.encode (derived hh)) ++ ["],\n", p, "\t\"history\":", historyPersistentsEncodePrefixed (i+1) (history hh), "\n", p, "}"]
where
p = pack $ List.replicate i '\t'
fudPersistentsEncode :: FudPersistent -> ByteString
fudPersistentsEncode = fudPersistentsEncodePrefixed 0
fudPersistentsEncodePrefixed :: Int -> FudPersistent -> ByteString
fudPersistentsEncodePrefixed i (FudPersistent ff) =
mconcat $ ["[\n"] ++
List.intersperse ",\n" [p <> "\t" <> transformPersistentsEncodePrefixed (i+1) tt | tt <- ff] ++
["\n", p, "]"]
where
p = pack $ List.replicate i '\t'
decompFudsPersistentsEncode :: DecompFudPersistent -> ByteString
decompFudsPersistentsEncode df =
mconcat $ ["{\n\t\"paths\":[\n"] ++
List.intersperse ",\n" ["\t\t" <> Data.Aeson.encode ss | ss <- paths df] ++
["\n\t],\n\t\"nodes\":[\n"] ++
List.intersperse ",\n" ["\t\t[\n\t\t\t" <> historyPersistentsEncodePrefixed 3 hh <> ",\n\t\t\t" <> fudPersistentsEncodePrefixed 3 ff <> "\n\t\t]" | (hh,ff) <- nodes df] ++
["\n\t]\n}"]
decompFudsPersistentsEncode_1 :: DecompFudPersistent -> ByteString
decompFudsPersistentsEncode_1 df =
mconcat $ ["{\n\t\"paths\":[\n"] ++
List.intersperse ",\n" ["\t\t" <> Data.Aeson.encode ss | ss <- paths df] ++
["\n\t],\n\t\"nodes\":[\n"] ++
List.intersperse ",\n" ["\t[" <> historyPersistentsEncodePrefixed 2 hh <> ",\n\t" <> fudPersistentsEncodePrefixed 1 ff <> "]" | (hh,ff) <- nodes df] ++
["\t]\n}"]