This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
chart.go
154 lines (143 loc) · 3.19 KB
/
chart.go
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
package main
import (
"context"
"errors"
"sort"
)
type Dataset struct {
Name string
Data []string
Color string
AxisID string
Hidden bool
Sealed bool
}
type scraperConfig struct {
PublicName string
ScraperName string
KindName string
Color string
Hidden bool
HasSealed bool
OnlySealed bool
}
/*
red: 'rgb(255, 99, 132)'
orange: 'rgb(255, 159, 64)'
yellow: 'rgb(255, 205, 86)'
green: 'rgb(75, 192, 192)'
blue: 'rgb(54, 162, 235)'
purple: 'rgb(153, 102, 255)'
grey: 'rgb(201, 203, 207)'
darkblue: 'rgb(23,42,72)'
*/
var enabledDatasets = []scraperConfig{
{
PublicName: "TCGplayer Low",
ScraperName: "tcg_index",
KindName: TCG_LOW,
Color: "rgb(255, 99, 132)",
HasSealed: true,
},
{
PublicName: "TCGplayer Market",
ScraperName: "tcg_index",
KindName: TCG_MARKET,
Color: "rgb(255, 159, 64)",
Hidden: true,
},
{
PublicName: "Card Kingdom Retail",
ScraperName: "cardkingdom",
KindName: "retail",
Color: "rgb(162, 235, 54)",
HasSealed: true,
},
{
PublicName: "Card Kingdom Buylist",
ScraperName: "cardkingdom",
KindName: "buylist",
Color: "rgb(54, 162, 235)",
HasSealed: true,
},
{
PublicName: "Cardmarket Low",
ScraperName: "cardmarket",
KindName: MKM_LOW,
Color: "rgb(235, 205, 86)",
HasSealed: true,
},
{
PublicName: "Cardmarket Trend",
ScraperName: "cardmarket",
KindName: MKM_TREND,
Color: "rgb(201, 203, 207)",
Hidden: true,
},
{
PublicName: "Star City Games Buylist",
ScraperName: "starcitygames",
KindName: "buylist",
Color: "rgb(23,42,72)",
},
{
PublicName: "ABU Games Buylist",
ScraperName: "abugames",
KindName: "buylist",
Color: "rgb(153, 102, 255)",
},
{
PublicName: "Sealed EV Median",
ScraperName: "sealed_ev",
KindName: "TCG Low EV Median",
Color: "rgb(201, 203, 207)",
HasSealed: true,
OnlySealed: true,
},
}
// Get all the keys that will be used as x asis labels
func getDateAxisValues(cardId string) ([]string, error) {
db := ScraperOptions["tcg_index"].RDBs[TCG_MARKET]
keys, err := db.HKeys(context.Background(), cardId).Result()
if err != nil {
return nil, err
}
if len(keys) == 0 {
db = ScraperOptions["tcg_index"].RDBs[TCG_LOW]
keys, err = db.HKeys(context.Background(), cardId).Result()
if err != nil {
return nil, err
}
if len(keys) == 0 {
return nil, errors.New("no data available")
}
}
// Sort labels from older to newer
sort.Slice(keys, func(i, j int) bool {
return keys[i] < keys[j]
})
return keys, nil
}
func getDataset(cardId string, labels []string, config scraperConfig) (*Dataset, error) {
db := ScraperOptions[config.ScraperName].RDBs[config.KindName]
results, err := db.HGetAll(context.Background(), cardId).Result()
if err != nil {
return nil, err
}
// Fill in missing points with NaNs so that the values
// can be mapped consistently on the chart
data := make([]string, len(labels))
for i := range labels {
val, found := results[labels[i]]
if !found {
val = "Number.NaN"
}
data[i] = val
}
return &Dataset{
Name: config.PublicName,
Data: data,
Color: config.Color,
Hidden: config.Hidden,
}, nil
}