update value graph
This commit is contained in:
parent
76dacf33d9
commit
4a5b82000a
68
bot.go
68
bot.go
@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -882,6 +883,32 @@ func botRegister(m *tb.Message) {
|
||||
}
|
||||
|
||||
func botGraphValue(m *tb.Message) {
|
||||
var (
|
||||
maxVal float64
|
||||
unitFactor float64
|
||||
unitName string
|
||||
)
|
||||
for coID, dStats := range cfg.Stats {
|
||||
if cfg.CompanyIsRegistered(coID) {
|
||||
for _, stat := range dStats {
|
||||
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||
if math.Abs(valueFloat) > maxVal {
|
||||
maxVal = math.Abs(valueFloat)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if maxVal > 1000000000 {
|
||||
unitFactor = 1000000000
|
||||
unitName = "billion"
|
||||
} else if maxVal > 1000000 {
|
||||
unitFactor = 1000000
|
||||
unitName = "million"
|
||||
} else {
|
||||
unitFactor = 1
|
||||
unitName = ""
|
||||
}
|
||||
|
||||
var vals map[uint8]plotter.XYs
|
||||
vals = make(map[uint8]plotter.XYs)
|
||||
for coID, dStats := range cfg.Stats {
|
||||
@ -898,7 +925,7 @@ func botGraphValue(m *tb.Message) {
|
||||
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||
pt := plotter.XY{
|
||||
X: dateFloat,
|
||||
Y: valueFloat,
|
||||
Y: valueFloat / unitFactor,
|
||||
}
|
||||
vals[coID] = append(vals[coID], pt)
|
||||
}
|
||||
@ -908,19 +935,36 @@ func botGraphValue(m *tb.Message) {
|
||||
p := plot.New()
|
||||
p.Title.Text = "Company Values"
|
||||
p.X.Label.Text = "Year"
|
||||
p.Y.Label.Text = "Value"
|
||||
|
||||
for coID, xys := range vals {
|
||||
cc := cfg.GetCompanyClient(coID)
|
||||
err := plotutil.AddLinePoints(p, cc.Username, xys)
|
||||
logErrorDebug(err, "Stats.ValueGraph : plotutil.AddLinePoints")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("plotutil.AddLinePoints : %s", err))
|
||||
return
|
||||
}
|
||||
if unitName != "" {
|
||||
p.Y.Label.Text = fmt.Sprintf("Value (%s)", unitName)
|
||||
} else {
|
||||
p.Y.Label.Text = "Value"
|
||||
}
|
||||
|
||||
err := p.Save(4*vg.Inch, 4*vg.Inch, "/app/data/points.png")
|
||||
i := 0
|
||||
for coID, xys := range vals {
|
||||
cc := cfg.GetCompanyClient(coID)
|
||||
|
||||
l, s, err := plotter.NewLinePoints(xys)
|
||||
logErrorDebug(err, "Stats.ValueGraph : plotter.NewLinePoints")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("plotter.NewLinePoints : %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
l.Color = plotutil.Color(i)
|
||||
l.Dashes = plotutil.Dashes(2)
|
||||
s.Color = plotutil.Color(i)
|
||||
s.Shape = plotutil.Shape(0)
|
||||
|
||||
p.Add(l)
|
||||
p.Add(s)
|
||||
p.Legend.Add(cc.Username, l, s)
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
err := p.Save(4*vg.Inch, 6*vg.Inch, "/app/data/points.png")
|
||||
logErrorDebug(err, "Stats.ValueGraph : plot.Save")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("plot.Save : %s", err))
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||
package main
|
||||
var githash = "40c4261"
|
||||
var buildstamp = "2021-12-05_10:22:54"
|
||||
var commits = "229"
|
||||
var version = "40c4261-b229 - 2021-12-05_10:22:54"
|
||||
var githash = "76dacf3"
|
||||
var buildstamp = "2021-12-05_13:46:48"
|
||||
var commits = "230"
|
||||
var version = "76dacf3-b230 - 2021-12-05_13:46:48"
|
||||
|
Loading…
x
Reference in New Issue
Block a user