-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlbionMarketParser.elm
167 lines (124 loc) · 3.76 KB
/
AlbionMarketParser.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
module AlbionMarketParser exposing (..)
import Json.Decode exposing (string, int, float, list, Decoder)
import Json.Decode.Pipeline exposing (decode, required, optional)
type alias Resources =
{ resources : List MarketDataItem }
type alias MarketDataItem =
{ stats : Stats
, item : Item
}
type alias Stats =
{ buy : BuySell
, sell : BuySell
}
type alias BuySell =
{ total_volume : Int
, price_average : Float
, price_minimum : Int
, price_maximum : Int
, order_count : Int
}
type alias Item =
{ id : String
, name : String
, category_id : String
, category_name : String
, sub_category_id : String
, sub_category_name : String
, tier : Int
}
type alias SimpleItems =
{ items : List SimpleItem }
type alias SimpleItem =
{ id : String
, name : String
, category_id : String
, sub_category_id : String
, tier : Int
}
itemListDecoder : Decoder SimpleItems
itemListDecoder =
decode buildSimpleItems
|> required "items" (list simpleItemDecoder)
buildSimpleItems : List SimpleItem -> SimpleItems
buildSimpleItems simpleItems =
{ items = simpleItems }
simpleItemDecoder : Decoder SimpleItem
simpleItemDecoder =
decode buildSimpleItem
|> required "id" string
|> required "name" string
|> required "category_id" string
|> required "sub_category_id" string
|> required "tier" int
buildSimpleItem : String -> String -> String -> String -> Int -> SimpleItem
buildSimpleItem id name category_id sub_category_id tier =
{ id = id
, name = name
, category_id = category_id
, sub_category_id = sub_category_id
, tier = tier
}
resourcesDecoder : Decoder Resources
resourcesDecoder =
decode buildResources
|> required "resources" (list marketItemDecoder)
buildResources : List MarketDataItem -> Resources
buildResources marketDataItems =
{ resources = marketDataItems }
marketItemDecoder : Decoder MarketDataItem
marketItemDecoder =
decode buildMarketItem
|> required "stats" statsDecoder
|> required "item" itemDecoder
statsDecoder : Decoder Stats
statsDecoder =
decode buildStats
|> required "buy" buySellDecoder
|> required "sell" buySellDecoder
buySellDecoder : Decoder BuySell
buySellDecoder =
decode buildBuySell
|> required "total_volume" int
|> required "price_average" float
|> required "price_minimum" int
|> required "price_maximum" int
|> required "order_count" int
itemDecoder : Decoder Item
itemDecoder =
decode Item
|> required "id" string
|> required "name" string
|> required "category_id" string
|> required "category_name" string
|> required "sub_category_id" string
|> required "sub_category_name" string
|> required "tier" int
buildMarketItem : Stats -> Item -> MarketDataItem
buildMarketItem stats item =
{ stats = stats
, item = item
}
buildStats : BuySell -> BuySell -> Stats
buildStats buy sell =
{ buy = buy
, sell = sell
}
buildBuySell : Int -> Float -> Int -> Int -> Int -> BuySell
buildBuySell total_volume price_average price_minimum price_maximum order_count =
{ total_volume = total_volume
, price_average = price_average
, price_minimum = price_minimum
, price_maximum = price_maximum
, order_count = order_count
}
buildItem : String -> String -> String -> String -> String -> String -> Int -> Item
buildItem id name category_id category_name sub_category_id sub_category_name tier =
{ id = id
, name = name
, category_id = category_id
, category_name = category_name
, sub_category_id = sub_category_id
, sub_category_name = sub_category_name
, tier = tier
}