-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfgi.go
66 lines (58 loc) · 1.38 KB
/
fgi.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
package main
import "fmt"
type VVT struct {
Value int
ValueText string
}
type FgiResult struct {
LastUpdated struct {
EpochUnixSeconds int
HumanDate string
}
Fgi Fgi // XXX: Why just Fgi is not working?
}
type Fgi struct {
Now VVT
PreviousClose VVT
OneWeekAgo VVT
OneMonthAgo VVT
OneYearAgo VVT
}
func valueToColor(v int) string {
if 0 <= v && v <= 24 {
return "🔵"
} else if 25 <= v && v <= 39 {
return "🟢"
} else if 40 <= v && v <= 59 {
return "🟡"
} else if 60 <= v && v <= 74 {
return "🟠"
} else { // it's over 75!
return "🔴"
}
}
func (v VVT) toString() string {
color := valueToColor(v.Value)
return fmt.Sprintf("%s %d (%s)", color, v.Value, v.ValueText)
}
func (fr FgiResult) toString() string {
return fmt.Sprintf(`[lastUpdate: %s]
- now: %s
- prev: %s
- 1w ago: %s
- 1m ago: %s
- 1y ago: %s`, fr.LastUpdated.HumanDate,
fr.Fgi.Now.toString(),
fr.Fgi.PreviousClose.toString(),
fr.Fgi.OneWeekAgo.toString(),
fr.Fgi.OneMonthAgo.toString(),
fr.Fgi.OneYearAgo.toString())
}
func (fr FgiResult) toJson() string {
return fmt.Sprintf(`{"lastUpdate": "%s", "now": "%s", "prev": "%s", "1w ago": "%s", "1m ago": "%s", "1y ago": "%s"}`, fr.LastUpdated.HumanDate,
fr.Fgi.Now.toString(),
fr.Fgi.PreviousClose.toString(),
fr.Fgi.OneWeekAgo.toString(),
fr.Fgi.OneMonthAgo.toString(),
fr.Fgi.OneYearAgo.toString())
}