lorries and ships

This commit is contained in:
shoopea 2021-12-08 22:19:35 +08:00
parent 4688c5d8e4
commit e7f47ca243
2 changed files with 153 additions and 6 deletions

151
bot.go
View File

@ -1079,8 +1079,6 @@ func botGraphValueDelta(m *tb.Message) {
unitName = ""
}
logInfoDebug("botGraphValueDelta : unit set to %s (factor : %f)", unitName, unitFactor)
for coID, v := range vals {
for i := 0; i < len(v); i++ {
v[i].Y = v[i].Y / unitFactor
@ -1171,6 +1169,7 @@ func botGraphPlanes(m *tb.Message) {
p.Title.Text = "Planes summary"
p.X.Label.Text = "Year"
p.Y.Label.Text = "Planes"
p.Y.Min = 0
i := 0
for coID, xys := range planes {
@ -1243,6 +1242,7 @@ func botGraphBusses(m *tb.Message) {
p.Title.Text = "Busses summary"
p.X.Label.Text = "Year"
p.Y.Label.Text = "Busses"
p.Y.Min = 0
i := 0
for coID, xys := range busses {
@ -1315,6 +1315,7 @@ func botGraphTrains(m *tb.Message) {
p.Title.Text = "Trains summary"
p.X.Label.Text = "Year"
p.Y.Label.Text = "Trains"
p.Y.Min = 0
i := 0
for coID, xys := range trains {
@ -1351,6 +1352,152 @@ func botGraphTrains(m *tb.Message) {
return
}
func botGraphLorries(m *tb.Message) {
var lorries, lorriesStations map[uint8]plotter.XYs
lorries = make(map[uint8]plotter.XYs)
lorriesStations = make(map[uint8]plotter.XYs)
for coID, dStats := range cfg.Stats {
if cfg.CompanyIsRegistered(coID) {
lorries[coID] = make(plotter.XYs, 0)
for dStr, stat := range dStats {
d, err := time.Parse("20060102", dStr)
logErrorDebug(err, "botGraphLorries : 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.Lorries),
}
lorries[coID] = append(lorries[coID], pt)
pt = plotter.XY{
X: dateFloat,
Y: float64(stat.LorryStations),
}
lorriesStations[coID] = append(lorriesStations[coID], pt)
}
sort.Slice(lorries[coID], func(i, j int) bool { return lorries[coID][i].X < lorries[coID][j].X })
sort.Slice(lorriesStations[coID], func(i, j int) bool { return lorriesStations[coID][i].X < lorriesStations[coID][j].X })
}
}
p := plot.New()
p.Title.Text = "Lorries summary"
p.X.Label.Text = "Year"
p.Y.Label.Text = "Lorries"
p.Y.Min = 0
i := 0
for coID, xys := range lorries {
cc := cfg.GetCompanyClient(coID)
l, s, err := plotter.NewLinePoints(xys)
logErrorDebug(err, "botGraphLorries : 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, "botGraphLorries : 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 botGraphShips(m *tb.Message) {
var ships, harbours map[uint8]plotter.XYs
ships = make(map[uint8]plotter.XYs)
harbours = make(map[uint8]plotter.XYs)
for coID, dStats := range cfg.Stats {
if cfg.CompanyIsRegistered(coID) {
ships[coID] = make(plotter.XYs, 0)
for dStr, stat := range dStats {
d, err := time.Parse("20060102", dStr)
logErrorDebug(err, "botGraphShips : 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.Ships),
}
ships[coID] = append(ships[coID], pt)
pt = plotter.XY{
X: dateFloat,
Y: float64(stat.Harbours),
}
harbours[coID] = append(harbours[coID], pt)
}
sort.Slice(ships[coID], func(i, j int) bool { return ships[coID][i].X < ships[coID][j].X })
sort.Slice(harbours[coID], func(i, j int) bool { return harbours[coID][i].X < harbours[coID][j].X })
}
}
p := plot.New()
p.Title.Text = "Ships summary"
p.X.Label.Text = "Year"
p.Y.Label.Text = "Ships"
p.Y.Min = 0
i := 0
for coID, xys := range ships {
cc := cfg.GetCompanyClient(coID)
l, s, err := plotter.NewLinePoints(xys)
logErrorDebug(err, "botGraphShips : 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, "botGraphShips : 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

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "55fa6be"
var buildstamp = "2021-12-08_14:08:01"
var commits = "244"
var version = "55fa6be-b244 - 2021-12-08_14:08:01"
var githash = "4688c5d"
var buildstamp = "2021-12-08_14:19:25"
var commits = "245"
var version = "4688c5d-b245 - 2021-12-08_14:19:25"