trains and busses, rework value_delta
This commit is contained in:
parent
2a1bf10054
commit
456f17474b
152
bot.go
152
bot.go
@ -110,6 +110,8 @@ func (b *Bot) BotHandlers() {
|
||||
b.bot.Handle("/value", botGraphValue)
|
||||
b.bot.Handle("/value_delta", botGraphValueDelta)
|
||||
b.bot.Handle("/planes", botGraphPlanes)
|
||||
b.bot.Handle("/busses", botGraphPlanes)
|
||||
b.bot.Handle("/trains", botGraphPlanes)
|
||||
|
||||
b.bot.Handle(tb.OnPhoto, botPhoto)
|
||||
b.bot.Handle(tb.OnChannelPost, botChannelPost)
|
||||
@ -999,11 +1001,9 @@ func botGraphValueDelta(m *tb.Message) {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("time.Parse : %s", err))
|
||||
return
|
||||
}
|
||||
dateFloat := float64(d.Year()) + float64(d.Month()-1)/12
|
||||
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||
pt := plotter.XY{
|
||||
X: dateFloat,
|
||||
Y: valueFloat / unitFactor,
|
||||
X: float64(d.Year()) + float64(d.Month()-1)/12,
|
||||
Y: float64(stat.CompanyValueLastQuarter),
|
||||
}
|
||||
vals[coID] = append(vals[coID], pt)
|
||||
}
|
||||
@ -1160,6 +1160,150 @@ func botGraphPlanes(m *tb.Message) {
|
||||
return
|
||||
}
|
||||
|
||||
func botGraphBusses(m *tb.Message) {
|
||||
var busses, busStops map[uint8]plotter.XYs
|
||||
busses = make(map[uint8]plotter.XYs)
|
||||
busStops = make(map[uint8]plotter.XYs)
|
||||
for coID, dStats := range cfg.Stats {
|
||||
if cfg.CompanyIsRegistered(coID) {
|
||||
busses[coID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
logErrorDebug(err, "botGraphBusses : time.Parse")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("time.Parse : %s", err))
|
||||
return
|
||||
}
|
||||
dateFloat := float64(d.Year()) + float64(d.Month()-1)/12
|
||||
pt := plotter.XY{
|
||||
X: dateFloat,
|
||||
Y: float64(stat.Busses),
|
||||
}
|
||||
busses[coID] = append(busses[coID], pt)
|
||||
pt = plotter.XY{
|
||||
X: dateFloat,
|
||||
Y: float64(stat.BusStops),
|
||||
}
|
||||
busStops[coID] = append(busStops[coID], pt)
|
||||
}
|
||||
sort.Slice(busses[coID], func(i, j int) bool { return busses[coID][i].X < busses[coID][j].X })
|
||||
sort.Slice(busStops[coID], func(i, j int) bool { return busStops[coID][i].X < busStops[coID][j].X })
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
p := plot.New()
|
||||
p.Title.Text = "Busses summary"
|
||||
p.X.Label.Text = "Year"
|
||||
p.Y.Label.Text = "Busses"
|
||||
|
||||
i := 0
|
||||
for coID, xys := range busses {
|
||||
cc := cfg.GetCompanyClient(coID)
|
||||
|
||||
l, s, err := plotter.NewLinePoints(xys)
|
||||
logErrorDebug(err, "botGraphBusses : 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(6*vg.Inch, 4*vg.Inch, "/app/data/points.png")
|
||||
logErrorDebug(err, "botGraphBusses : plot.Save")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("plot.Save : %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
bot.SendChatImage(m.Chat.ID, "/app/data/points.png")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func botGraphTrains(m *tb.Message) {
|
||||
var trains, trainStations map[uint8]plotter.XYs
|
||||
trains = make(map[uint8]plotter.XYs)
|
||||
trainStations = make(map[uint8]plotter.XYs)
|
||||
for coID, dStats := range cfg.Stats {
|
||||
if cfg.CompanyIsRegistered(coID) {
|
||||
trains[coID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
logErrorDebug(err, "botGraphTrains : time.Parse")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("time.Parse : %s", err))
|
||||
return
|
||||
}
|
||||
dateFloat := float64(d.Year()) + float64(d.Month()-1)/12
|
||||
pt := plotter.XY{
|
||||
X: dateFloat,
|
||||
Y: float64(stat.Trains),
|
||||
}
|
||||
trains[coID] = append(trains[coID], pt)
|
||||
pt = plotter.XY{
|
||||
X: dateFloat,
|
||||
Y: float64(stat.TrainStations),
|
||||
}
|
||||
trainStations[coID] = append(trainStations[coID], pt)
|
||||
}
|
||||
sort.Slice(trains[coID], func(i, j int) bool { return trains[coID][i].X < trains[coID][j].X })
|
||||
sort.Slice(trainStations[coID], func(i, j int) bool { return trainStations[coID][i].X < trainStations[coID][j].X })
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
p := plot.New()
|
||||
p.Title.Text = "Trains summary"
|
||||
p.X.Label.Text = "Year"
|
||||
p.Y.Label.Text = "Trains"
|
||||
|
||||
i := 0
|
||||
for coID, xys := range trains {
|
||||
cc := cfg.GetCompanyClient(coID)
|
||||
|
||||
l, s, err := plotter.NewLinePoints(xys)
|
||||
logErrorDebug(err, "botGraphTrains : 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(6*vg.Inch, 4*vg.Inch, "/app/data/points.png")
|
||||
logErrorDebug(err, "botGraphTrains : plot.Save")
|
||||
if err != nil {
|
||||
bot.SendChat(m.Chat.ID, fmt.Sprintf("plot.Save : %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
bot.SendChatImage(m.Chat.ID, "/app/data/points.png")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func PrintText(m *tb.Message) {
|
||||
logInfoDebug("[%d] %s(%d) | %s(%d) : %s\n", m.ID, m.Chat.Title, m.Chat.ID, m.Sender.Username, m.Sender.ID, m.Text)
|
||||
return
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||
package main
|
||||
var githash = "7c1c067"
|
||||
var buildstamp = "2021-12-06_14:11:07"
|
||||
var commits = "234"
|
||||
var version = "7c1c067-b234 - 2021-12-06_14:11:07"
|
||||
var githash = "2a1bf10"
|
||||
var buildstamp = "2021-12-06_14:22:55"
|
||||
var commits = "235"
|
||||
var version = "2a1bf10-b235 - 2021-12-06_14:22:55"
|
||||
|
Loading…
x
Reference in New Issue
Block a user