add all stats and tie stats to user rather than company
This commit is contained in:
parent
be1712b066
commit
4cecee1a0f
555
bot.go
555
bot.go
@ -110,6 +110,10 @@ func (b *Bot) BotHandlers() {
|
|||||||
|
|
||||||
b.bot.Handle("/value", botGraphValue)
|
b.bot.Handle("/value", botGraphValue)
|
||||||
b.bot.Handle("/value_delta", botGraphValueDelta)
|
b.bot.Handle("/value_delta", botGraphValueDelta)
|
||||||
|
b.bot.Handle("/money", botGraphMoney)
|
||||||
|
b.bot.Handle("/income", botGraphIncome)
|
||||||
|
b.bot.Handle("/loan", botGraphLoan)
|
||||||
|
b.bot.Handle("/perf", botGraphPerf)
|
||||||
b.bot.Handle("/planes", botGraphPlanes)
|
b.bot.Handle("/planes", botGraphPlanes)
|
||||||
b.bot.Handle("/busses", botGraphBusses)
|
b.bot.Handle("/busses", botGraphBusses)
|
||||||
b.bot.Handle("/trains", botGraphTrains)
|
b.bot.Handle("/trains", botGraphTrains)
|
||||||
@ -151,9 +155,15 @@ func botHelp(m *tb.Message) {
|
|||||||
msg = fmt.Sprintf("%s/offline - set player offline\r\n", msg)
|
msg = fmt.Sprintf("%s/offline - set player offline\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/value - value graph\r\n", msg)
|
msg = fmt.Sprintf("%s/value - value graph\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/value_delta - delta value graph\r\n", msg)
|
msg = fmt.Sprintf("%s/value_delta - delta value graph\r\n", msg)
|
||||||
|
msg = fmt.Sprintf("%s/money - money graph\r\n", msg)
|
||||||
|
msg = fmt.Sprintf("%s/income - income graph\r\n", msg)
|
||||||
|
msg = fmt.Sprintf("%s/loan - loan graph\r\n", msg)
|
||||||
|
msg = fmt.Sprintf("%s/perf - perf graph\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/busses - busses graph\r\n", msg)
|
msg = fmt.Sprintf("%s/busses - busses graph\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/trains - trains graph\r\n", msg)
|
msg = fmt.Sprintf("%s/trains - trains graph\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/planes - planes graph\r\n", msg)
|
msg = fmt.Sprintf("%s/planes - planes graph\r\n", msg)
|
||||||
|
msg = fmt.Sprintf("%s/lorries - lorries graph\r\n", msg)
|
||||||
|
msg = fmt.Sprintf("%s/ships - ships graph\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/version - version\r\n", msg)
|
msg = fmt.Sprintf("%s/version - version\r\n", msg)
|
||||||
msg = fmt.Sprintf("%s/help - this\r\n", msg)
|
msg = fmt.Sprintf("%s/help - this\r\n", msg)
|
||||||
|
|
||||||
@ -379,7 +389,7 @@ func botActuallyReset(m *tb.Message) {
|
|||||||
} else {
|
} else {
|
||||||
cfg.Save("backup." + *configFlag)
|
cfg.Save("backup." + *configFlag)
|
||||||
cfg.Game.Started = false
|
cfg.Game.Started = false
|
||||||
cfg.Stats = make(map[uint8]map[string]*Stat)
|
cfg.Stats = make(map[int]map[string]*Stat)
|
||||||
for _, cc := range cfg.Clients {
|
for _, cc := range cfg.Clients {
|
||||||
cc.Ready = false
|
cc.Ready = false
|
||||||
cc.CompanyID = 255
|
cc.CompanyID = 255
|
||||||
@ -933,8 +943,7 @@ func botGraphValue(m *tb.Message) {
|
|||||||
unitFactor float64
|
unitFactor float64
|
||||||
unitName string
|
unitName string
|
||||||
)
|
)
|
||||||
for coID, dStats := range cfg.Stats {
|
for _, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
|
||||||
for _, stat := range dStats {
|
for _, stat := range dStats {
|
||||||
valueFloat := float64(stat.CompanyValueLastQuarter)
|
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||||
if math.Abs(valueFloat) > maxVal {
|
if math.Abs(valueFloat) > maxVal {
|
||||||
@ -942,7 +951,6 @@ func botGraphValue(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if maxVal > 1000000000 {
|
if maxVal > 1000000000 {
|
||||||
unitFactor = 1000000000
|
unitFactor = 1000000000
|
||||||
unitName = "billion"
|
unitName = "billion"
|
||||||
@ -954,11 +962,10 @@ func botGraphValue(m *tb.Message) {
|
|||||||
unitName = ""
|
unitName = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var vals map[uint8]plotter.XYs
|
var vals map[int]plotter.XYs
|
||||||
vals = make(map[uint8]plotter.XYs)
|
vals = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
vals[ccID] = make(plotter.XYs, 0)
|
||||||
vals[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphValue : time.Parse")
|
logErrorDebug(err, "botGraphValue : time.Parse")
|
||||||
@ -972,10 +979,9 @@ func botGraphValue(m *tb.Message) {
|
|||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: valueFloat / unitFactor,
|
Y: valueFloat / unitFactor,
|
||||||
}
|
}
|
||||||
vals[coID] = append(vals[coID], pt)
|
vals[ccID] = append(vals[ccID], pt)
|
||||||
}
|
|
||||||
sort.Slice(vals[coID], func(i, j int) bool { return vals[coID][i].X < vals[coID][j].X })
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(vals[ccID], func(i, j int) bool { return vals[ccID][i].X < vals[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -988,8 +994,8 @@ func botGraphValue(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range vals {
|
for ccID, xys := range vals {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphValue : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphValue : plotter.NewLinePoints")
|
||||||
@ -1029,11 +1035,10 @@ func botGraphValueDelta(m *tb.Message) {
|
|||||||
unitName string
|
unitName string
|
||||||
)
|
)
|
||||||
|
|
||||||
var vals map[uint8]plotter.XYs
|
var vals map[int]plotter.XYs
|
||||||
vals = make(map[uint8]plotter.XYs)
|
vals = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
vals[ccID] = make(plotter.XYs, 0)
|
||||||
vals[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphValueDelta : time.Parse")
|
logErrorDebug(err, "botGraphValueDelta : time.Parse")
|
||||||
@ -1045,21 +1050,20 @@ func botGraphValueDelta(m *tb.Message) {
|
|||||||
X: float64(d.Year()) + float64(d.Month()-1)/12,
|
X: float64(d.Year()) + float64(d.Month()-1)/12,
|
||||||
Y: float64(stat.CompanyValuePreviousQuarter),
|
Y: float64(stat.CompanyValuePreviousQuarter),
|
||||||
}
|
}
|
||||||
vals[coID] = append(vals[coID], pt)
|
vals[ccID] = append(vals[ccID], pt)
|
||||||
}
|
|
||||||
sort.Slice(vals[coID], func(i, j int) bool { return vals[coID][i].X < vals[coID][j].X })
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(vals[ccID], func(i, j int) bool { return vals[ccID][i].X < vals[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
for coID, v := range vals {
|
for ccID, v := range vals {
|
||||||
v2 := make(plotter.XYs, 0)
|
v2 := make(plotter.XYs, 0)
|
||||||
for i := 0; i < len(v); i = i + 3 {
|
for i := 0; i < len(v); i = i + 3 {
|
||||||
v2 = append(v2, v[i])
|
v2 = append(v2, v[i])
|
||||||
}
|
}
|
||||||
vals[coID] = v2
|
vals[ccID] = v2
|
||||||
}
|
}
|
||||||
|
|
||||||
for coID, v := range vals {
|
for ccID, v := range vals {
|
||||||
v0 := v[0].Y
|
v0 := v[0].Y
|
||||||
for i := 1; i < len(v); i++ {
|
for i := 1; i < len(v); i++ {
|
||||||
v[i].Y, v0 = v[i].Y-v0, v[i].Y
|
v[i].Y, v0 = v[i].Y-v0, v[i].Y
|
||||||
@ -1067,7 +1071,7 @@ func botGraphValueDelta(m *tb.Message) {
|
|||||||
maxVal = math.Abs(v[i].Y)
|
maxVal = math.Abs(v[i].Y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vals[coID] = v[1:]
|
vals[ccID] = v[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
if maxVal > 1000000000 {
|
if maxVal > 1000000000 {
|
||||||
@ -1081,14 +1085,14 @@ func botGraphValueDelta(m *tb.Message) {
|
|||||||
unitName = ""
|
unitName = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for coID, v := range vals {
|
for ccID, v := range vals {
|
||||||
for i := 0; i < len(v); i++ {
|
for i := 0; i < len(v); i++ {
|
||||||
v[i].Y = v[i].Y / unitFactor
|
v[i].Y = v[i].Y / unitFactor
|
||||||
if math.IsNaN(v[i].Y) {
|
if math.IsNaN(v[i].Y) {
|
||||||
logInfoDebug("botGraphValueDelta : NaN : %d / %f", coID, v[i].X)
|
logInfoDebug("botGraphValueDelta : NaN : %d / %f", ccID, v[i].X)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vals[coID] = v
|
vals[ccID] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -1101,8 +1105,8 @@ func botGraphValueDelta(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range vals {
|
for ccID, xys := range vals {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphValueDelta : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphValueDelta : plotter.NewLinePoints")
|
||||||
@ -1135,13 +1139,376 @@ func botGraphValueDelta(m *tb.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func botGraphMoney(m *tb.Message) {
|
||||||
|
var (
|
||||||
|
maxVal float64
|
||||||
|
unitFactor float64
|
||||||
|
unitName string
|
||||||
|
)
|
||||||
|
for _, dStats := range cfg.Stats {
|
||||||
|
for _, stat := range dStats {
|
||||||
|
valueFloat := float64(stat.Money)
|
||||||
|
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[int]plotter.XYs
|
||||||
|
vals = make(map[int]plotter.XYs)
|
||||||
|
for ccID, dStats := range cfg.Stats {
|
||||||
|
vals[ccID] = make(plotter.XYs, 0)
|
||||||
|
for dStr, stat := range dStats {
|
||||||
|
d, err := time.Parse("20060102", dStr)
|
||||||
|
logErrorDebug(err, "botGraphMoney : 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
|
||||||
|
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||||
|
pt := plotter.XY{
|
||||||
|
X: dateFloat,
|
||||||
|
Y: valueFloat / unitFactor,
|
||||||
|
}
|
||||||
|
vals[ccID] = append(vals[ccID], pt)
|
||||||
|
}
|
||||||
|
sort.Slice(vals[ccID], func(i, j int) bool { return vals[ccID][i].X < vals[ccID][j].X })
|
||||||
|
}
|
||||||
|
|
||||||
|
p := plot.New()
|
||||||
|
p.Title.Text = "Company Money"
|
||||||
|
p.X.Label.Text = "Year"
|
||||||
|
if unitName != "" {
|
||||||
|
p.Y.Label.Text = fmt.Sprintf("Value (%s)", unitName)
|
||||||
|
} else {
|
||||||
|
p.Y.Label.Text = "Value"
|
||||||
|
}
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for ccID, xys := range vals {
|
||||||
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
|
logErrorDebug(err, "botGraphMoney : 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, "botGraphMoney : 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 botGraphIncome(m *tb.Message) {
|
||||||
|
var (
|
||||||
|
maxVal float64
|
||||||
|
unitFactor float64
|
||||||
|
unitName string
|
||||||
|
)
|
||||||
|
for _, dStats := range cfg.Stats {
|
||||||
|
for _, stat := range dStats {
|
||||||
|
valueFloat := float64(stat.Income)
|
||||||
|
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[int]plotter.XYs
|
||||||
|
vals = make(map[int]plotter.XYs)
|
||||||
|
for ccID, dStats := range cfg.Stats {
|
||||||
|
vals[ccID] = make(plotter.XYs, 0)
|
||||||
|
for dStr, stat := range dStats {
|
||||||
|
d, err := time.Parse("20060102", dStr)
|
||||||
|
logErrorDebug(err, "botGraphIncome : 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
|
||||||
|
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||||
|
pt := plotter.XY{
|
||||||
|
X: dateFloat,
|
||||||
|
Y: valueFloat / unitFactor,
|
||||||
|
}
|
||||||
|
vals[ccID] = append(vals[ccID], pt)
|
||||||
|
}
|
||||||
|
sort.Slice(vals[ccID], func(i, j int) bool { return vals[ccID][i].X < vals[ccID][j].X })
|
||||||
|
}
|
||||||
|
|
||||||
|
p := plot.New()
|
||||||
|
p.Title.Text = "Company Income"
|
||||||
|
p.X.Label.Text = "Year"
|
||||||
|
if unitName != "" {
|
||||||
|
p.Y.Label.Text = fmt.Sprintf("Value (%s)", unitName)
|
||||||
|
} else {
|
||||||
|
p.Y.Label.Text = "Value"
|
||||||
|
}
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for ccID, xys := range vals {
|
||||||
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
|
logErrorDebug(err, "botGraphIncome : 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, "botGraphIncome : 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 botGraphLoan(m *tb.Message) {
|
||||||
|
var (
|
||||||
|
maxVal float64
|
||||||
|
unitFactor float64
|
||||||
|
unitName string
|
||||||
|
)
|
||||||
|
for _, dStats := range cfg.Stats {
|
||||||
|
for _, stat := range dStats {
|
||||||
|
valueFloat := float64(stat.Loan)
|
||||||
|
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[int]plotter.XYs
|
||||||
|
vals = make(map[int]plotter.XYs)
|
||||||
|
for ccID, dStats := range cfg.Stats {
|
||||||
|
vals[ccID] = make(plotter.XYs, 0)
|
||||||
|
for dStr, stat := range dStats {
|
||||||
|
d, err := time.Parse("20060102", dStr)
|
||||||
|
logErrorDebug(err, "botGraphLoan : 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
|
||||||
|
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||||
|
pt := plotter.XY{
|
||||||
|
X: dateFloat,
|
||||||
|
Y: valueFloat / unitFactor,
|
||||||
|
}
|
||||||
|
vals[ccID] = append(vals[ccID], pt)
|
||||||
|
}
|
||||||
|
sort.Slice(vals[ccID], func(i, j int) bool { return vals[ccID][i].X < vals[ccID][j].X })
|
||||||
|
}
|
||||||
|
|
||||||
|
p := plot.New()
|
||||||
|
p.Title.Text = "Company Loan"
|
||||||
|
p.X.Label.Text = "Year"
|
||||||
|
if unitName != "" {
|
||||||
|
p.Y.Label.Text = fmt.Sprintf("Value (%s)", unitName)
|
||||||
|
} else {
|
||||||
|
p.Y.Label.Text = "Value"
|
||||||
|
}
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for ccID, xys := range vals {
|
||||||
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
|
logErrorDebug(err, "botGraphLoan : 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, "botGraphLoan : 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 botGraphPerf(m *tb.Message) {
|
||||||
|
var (
|
||||||
|
maxVal float64
|
||||||
|
unitFactor float64
|
||||||
|
unitName string
|
||||||
|
)
|
||||||
|
for _, dStats := range cfg.Stats {
|
||||||
|
for _, stat := range dStats {
|
||||||
|
valueFloat := float64(stat.PerformancePreviousQuarter)
|
||||||
|
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[int]plotter.XYs
|
||||||
|
vals = make(map[int]plotter.XYs)
|
||||||
|
for ccID, dStats := range cfg.Stats {
|
||||||
|
vals[ccID] = make(plotter.XYs, 0)
|
||||||
|
for dStr, stat := range dStats {
|
||||||
|
d, err := time.Parse("20060102", dStr)
|
||||||
|
logErrorDebug(err, "botGraphPerf : 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
|
||||||
|
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||||
|
pt := plotter.XY{
|
||||||
|
X: dateFloat,
|
||||||
|
Y: valueFloat / unitFactor,
|
||||||
|
}
|
||||||
|
vals[ccID] = append(vals[ccID], pt)
|
||||||
|
}
|
||||||
|
sort.Slice(vals[ccID], func(i, j int) bool { return vals[ccID][i].X < vals[ccID][j].X })
|
||||||
|
}
|
||||||
|
|
||||||
|
p := plot.New()
|
||||||
|
p.Title.Text = "Company Loan"
|
||||||
|
p.X.Label.Text = "Year"
|
||||||
|
if unitName != "" {
|
||||||
|
p.Y.Label.Text = fmt.Sprintf("Value (%s)", unitName)
|
||||||
|
} else {
|
||||||
|
p.Y.Label.Text = "Value"
|
||||||
|
}
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for ccID, xys := range vals {
|
||||||
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
|
logErrorDebug(err, "botGraphPerf : 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, "botGraphPerf : 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 botGraphPlanes(m *tb.Message) {
|
func botGraphPlanes(m *tb.Message) {
|
||||||
var planes, airports map[uint8]plotter.XYs
|
var planes, airports map[int]plotter.XYs
|
||||||
planes = make(map[uint8]plotter.XYs)
|
planes = make(map[int]plotter.XYs)
|
||||||
airports = make(map[uint8]plotter.XYs)
|
airports = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
planes[ccID] = make(plotter.XYs, 0)
|
||||||
planes[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphPlanes : time.Parse")
|
logErrorDebug(err, "botGraphPlanes : time.Parse")
|
||||||
@ -1154,17 +1521,15 @@ func botGraphPlanes(m *tb.Message) {
|
|||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Planes),
|
Y: float64(stat.Planes),
|
||||||
}
|
}
|
||||||
planes[coID] = append(planes[coID], pt)
|
planes[ccID] = append(planes[ccID], pt)
|
||||||
pt = plotter.XY{
|
pt = plotter.XY{
|
||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Airports),
|
Y: float64(stat.Airports),
|
||||||
}
|
}
|
||||||
airports[coID] = append(airports[coID], pt)
|
airports[ccID] = append(airports[ccID], pt)
|
||||||
}
|
|
||||||
sort.Slice(planes[coID], func(i, j int) bool { return planes[coID][i].X < planes[coID][j].X })
|
|
||||||
sort.Slice(airports[coID], func(i, j int) bool { return airports[coID][i].X < airports[coID][j].X })
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(planes[ccID], func(i, j int) bool { return planes[ccID][i].X < planes[ccID][j].X })
|
||||||
|
sort.Slice(airports[ccID], func(i, j int) bool { return airports[ccID][i].X < airports[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -1174,8 +1539,8 @@ func botGraphPlanes(m *tb.Message) {
|
|||||||
p.Y.Min = 0
|
p.Y.Min = 0
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range planes {
|
for ccID, xys := range planes {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphPlanes : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphPlanes : plotter.NewLinePoints")
|
||||||
@ -1209,12 +1574,11 @@ func botGraphPlanes(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botGraphBusses(m *tb.Message) {
|
func botGraphBusses(m *tb.Message) {
|
||||||
var busses, busStops map[uint8]plotter.XYs
|
var busses, busStops map[int]plotter.XYs
|
||||||
busses = make(map[uint8]plotter.XYs)
|
busses = make(map[int]plotter.XYs)
|
||||||
busStops = make(map[uint8]plotter.XYs)
|
busStops = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
busses[ccID] = make(plotter.XYs, 0)
|
||||||
busses[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphBusses : time.Parse")
|
logErrorDebug(err, "botGraphBusses : time.Parse")
|
||||||
@ -1227,17 +1591,15 @@ func botGraphBusses(m *tb.Message) {
|
|||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Busses),
|
Y: float64(stat.Busses),
|
||||||
}
|
}
|
||||||
busses[coID] = append(busses[coID], pt)
|
busses[ccID] = append(busses[ccID], pt)
|
||||||
pt = plotter.XY{
|
pt = plotter.XY{
|
||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.BusStops),
|
Y: float64(stat.BusStops),
|
||||||
}
|
}
|
||||||
busStops[coID] = append(busStops[coID], pt)
|
busStops[ccID] = append(busStops[ccID], 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 })
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(busses[ccID], func(i, j int) bool { return busses[ccID][i].X < busses[ccID][j].X })
|
||||||
|
sort.Slice(busStops[ccID], func(i, j int) bool { return busStops[ccID][i].X < busStops[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -1247,8 +1609,8 @@ func botGraphBusses(m *tb.Message) {
|
|||||||
p.Y.Min = 0
|
p.Y.Min = 0
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range busses {
|
for ccID, xys := range busses {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphBusses : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphBusses : plotter.NewLinePoints")
|
||||||
@ -1282,12 +1644,11 @@ func botGraphBusses(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botGraphTrains(m *tb.Message) {
|
func botGraphTrains(m *tb.Message) {
|
||||||
var trains, trainStations map[uint8]plotter.XYs
|
var trains, trainStations map[int]plotter.XYs
|
||||||
trains = make(map[uint8]plotter.XYs)
|
trains = make(map[int]plotter.XYs)
|
||||||
trainStations = make(map[uint8]plotter.XYs)
|
trainStations = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
trains[ccID] = make(plotter.XYs, 0)
|
||||||
trains[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphTrains : time.Parse")
|
logErrorDebug(err, "botGraphTrains : time.Parse")
|
||||||
@ -1300,17 +1661,15 @@ func botGraphTrains(m *tb.Message) {
|
|||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Trains),
|
Y: float64(stat.Trains),
|
||||||
}
|
}
|
||||||
trains[coID] = append(trains[coID], pt)
|
trains[ccID] = append(trains[ccID], pt)
|
||||||
pt = plotter.XY{
|
pt = plotter.XY{
|
||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.TrainStations),
|
Y: float64(stat.TrainStations),
|
||||||
}
|
}
|
||||||
trainStations[coID] = append(trainStations[coID], pt)
|
trainStations[ccID] = append(trainStations[ccID], 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 })
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(trains[ccID], func(i, j int) bool { return trains[ccID][i].X < trains[ccID][j].X })
|
||||||
|
sort.Slice(trainStations[ccID], func(i, j int) bool { return trainStations[ccID][i].X < trainStations[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -1320,8 +1679,8 @@ func botGraphTrains(m *tb.Message) {
|
|||||||
p.Y.Min = 0
|
p.Y.Min = 0
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range trains {
|
for ccID, xys := range trains {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphTrains : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphTrains : plotter.NewLinePoints")
|
||||||
@ -1355,12 +1714,11 @@ func botGraphTrains(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botGraphLorries(m *tb.Message) {
|
func botGraphLorries(m *tb.Message) {
|
||||||
var lorries, lorriesStations map[uint8]plotter.XYs
|
var lorries, lorriesStations map[int]plotter.XYs
|
||||||
lorries = make(map[uint8]plotter.XYs)
|
lorries = make(map[int]plotter.XYs)
|
||||||
lorriesStations = make(map[uint8]plotter.XYs)
|
lorriesStations = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
lorries[ccID] = make(plotter.XYs, 0)
|
||||||
lorries[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphLorries : time.Parse")
|
logErrorDebug(err, "botGraphLorries : time.Parse")
|
||||||
@ -1373,17 +1731,15 @@ func botGraphLorries(m *tb.Message) {
|
|||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Lorries),
|
Y: float64(stat.Lorries),
|
||||||
}
|
}
|
||||||
lorries[coID] = append(lorries[coID], pt)
|
lorries[ccID] = append(lorries[ccID], pt)
|
||||||
pt = plotter.XY{
|
pt = plotter.XY{
|
||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.LorryStations),
|
Y: float64(stat.LorryStations),
|
||||||
}
|
}
|
||||||
lorriesStations[coID] = append(lorriesStations[coID], pt)
|
lorriesStations[ccID] = append(lorriesStations[ccID], 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 })
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(lorries[ccID], func(i, j int) bool { return lorries[ccID][i].X < lorries[ccID][j].X })
|
||||||
|
sort.Slice(lorriesStations[ccID], func(i, j int) bool { return lorriesStations[ccID][i].X < lorriesStations[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -1393,8 +1749,8 @@ func botGraphLorries(m *tb.Message) {
|
|||||||
p.Y.Min = 0
|
p.Y.Min = 0
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range lorries {
|
for ccID, xys := range lorries {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphLorries : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphLorries : plotter.NewLinePoints")
|
||||||
@ -1428,12 +1784,11 @@ func botGraphLorries(m *tb.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botGraphShips(m *tb.Message) {
|
func botGraphShips(m *tb.Message) {
|
||||||
var ships, harbours map[uint8]plotter.XYs
|
var ships, harbours map[int]plotter.XYs
|
||||||
ships = make(map[uint8]plotter.XYs)
|
ships = make(map[int]plotter.XYs)
|
||||||
harbours = make(map[uint8]plotter.XYs)
|
harbours = make(map[int]plotter.XYs)
|
||||||
for coID, dStats := range cfg.Stats {
|
for ccID, dStats := range cfg.Stats {
|
||||||
if cfg.CompanyIsRegistered(coID) {
|
ships[ccID] = make(plotter.XYs, 0)
|
||||||
ships[coID] = make(plotter.XYs, 0)
|
|
||||||
for dStr, stat := range dStats {
|
for dStr, stat := range dStats {
|
||||||
d, err := time.Parse("20060102", dStr)
|
d, err := time.Parse("20060102", dStr)
|
||||||
logErrorDebug(err, "botGraphShips : time.Parse")
|
logErrorDebug(err, "botGraphShips : time.Parse")
|
||||||
@ -1446,17 +1801,15 @@ func botGraphShips(m *tb.Message) {
|
|||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Ships),
|
Y: float64(stat.Ships),
|
||||||
}
|
}
|
||||||
ships[coID] = append(ships[coID], pt)
|
ships[ccID] = append(ships[ccID], pt)
|
||||||
pt = plotter.XY{
|
pt = plotter.XY{
|
||||||
X: dateFloat,
|
X: dateFloat,
|
||||||
Y: float64(stat.Harbours),
|
Y: float64(stat.Harbours),
|
||||||
}
|
}
|
||||||
harbours[coID] = append(harbours[coID], pt)
|
harbours[ccID] = append(harbours[ccID], 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 })
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
sort.Slice(ships[ccID], func(i, j int) bool { return ships[ccID][i].X < ships[ccID][j].X })
|
||||||
|
sort.Slice(harbours[ccID], func(i, j int) bool { return harbours[ccID][i].X < harbours[ccID][j].X })
|
||||||
}
|
}
|
||||||
|
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
@ -1466,8 +1819,8 @@ func botGraphShips(m *tb.Message) {
|
|||||||
p.Y.Min = 0
|
p.Y.Min = 0
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
for coID, xys := range ships {
|
for ccID, xys := range ships {
|
||||||
cc := cfg.GetCompanyClient(coID)
|
cc := cfg.Clients[ccID]
|
||||||
|
|
||||||
l, s, err := plotter.NewLinePoints(xys)
|
l, s, err := plotter.NewLinePoints(xys)
|
||||||
logErrorDebug(err, "botGraphShips : plotter.NewLinePoints")
|
logErrorDebug(err, "botGraphShips : plotter.NewLinePoints")
|
||||||
|
@ -48,14 +48,14 @@ type Config struct {
|
|||||||
Telegram *TelegramConfig `json:"telegram"`
|
Telegram *TelegramConfig `json:"telegram"`
|
||||||
Game *GameConfig `json:"game"`
|
Game *GameConfig `json:"game"`
|
||||||
Clients map[int]*ClientConfig `json:"clients"`
|
Clients map[int]*ClientConfig `json:"clients"`
|
||||||
Stats map[uint8]map[string]*Stat `json:"stats"`
|
Stats map[int]map[string]*Stat `json:"stats"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init values for a config based on package defaults
|
// Init values for a config based on package defaults
|
||||||
func (c *Config) Init() error {
|
func (c *Config) Init() error {
|
||||||
err := json.Unmarshal(cfgSample, &c)
|
err := json.Unmarshal(cfgSample, &c)
|
||||||
c.Clients = make(map[int]*ClientConfig)
|
c.Clients = make(map[int]*ClientConfig)
|
||||||
c.Stats = make(map[uint8]map[string]*Stat)
|
c.Stats = make(map[int]map[string]*Stat)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
27
ttd.go
27
ttd.go
@ -385,20 +385,22 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
|||||||
logInfoDebug("Server.Poll() : PacketServerCompanyEconomy :\n- CompanyID: %d\n- M: %d\tL: %d\tI: %d\n- Delivered now: %d\tLast: %d\tPrevious: %d\n- Performance last: %d\t Previous: %d\n- Value last: %d\t Previous: %d", sp.CompanyID, sp.Money, sp.Loan, sp.Income, sp.DeliveredCargoThisQuarter, sp.DeliveredCargoLastQuarter, sp.DeliveredCargoPreviousQuarter, sp.PerformanceLastQuarter, sp.PerformancePreviousQuarter, sp.CompanyValueLastQuarter, sp.CompanyValuePreviousQuarter)
|
logInfoDebug("Server.Poll() : PacketServerCompanyEconomy :\n- CompanyID: %d\n- M: %d\tL: %d\tI: %d\n- Delivered now: %d\tLast: %d\tPrevious: %d\n- Performance last: %d\t Previous: %d\n- Value last: %d\t Previous: %d", sp.CompanyID, sp.Money, sp.Loan, sp.Income, sp.DeliveredCargoThisQuarter, sp.DeliveredCargoLastQuarter, sp.DeliveredCargoPreviousQuarter, sp.PerformanceLastQuarter, sp.PerformancePreviousQuarter, sp.CompanyValueLastQuarter, sp.CompanyValuePreviousQuarter)
|
||||||
|
|
||||||
if cfg.Stats == nil {
|
if cfg.Stats == nil {
|
||||||
cfg.Stats = make(map[uint8]map[string]*Stat)
|
cfg.Stats = make(map[int]map[string]*Stat)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := cfg.Stats[sp.CompanyID]
|
if cfg.CompanyIsRegistered(sp.CompanyID) {
|
||||||
|
cc := cfg.GetCompanyClient(sp.CompanyID)
|
||||||
|
_, ok := cfg.Stats[cc.UserID]
|
||||||
if !ok {
|
if !ok {
|
||||||
cfg.Stats[sp.CompanyID] = make(map[string]*Stat)
|
cfg.Stats[cc.UserID] = make(map[string]*Stat)
|
||||||
}
|
}
|
||||||
stats, ok := cfg.Stats[sp.CompanyID][s.Status.GameDate.Format("20060102")]
|
stats, ok := cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||||
if !ok {
|
if !ok {
|
||||||
stats = &Stat{
|
stats = &Stat{
|
||||||
CompanyID: sp.CompanyID,
|
CompanyID: sp.CompanyID,
|
||||||
Date: s.Status.GameDate,
|
Date: s.Status.GameDate,
|
||||||
}
|
}
|
||||||
cfg.Stats[sp.CompanyID][s.Status.GameDate.Format("20060102")] = stats
|
cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.Money = int64(sp.Money)
|
stats.Money = int64(sp.Money)
|
||||||
@ -411,6 +413,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
|||||||
stats.PerformancePreviousQuarter = int(sp.PerformancePreviousQuarter)
|
stats.PerformancePreviousQuarter = int(sp.PerformancePreviousQuarter)
|
||||||
stats.CompanyValueLastQuarter = int64(sp.CompanyValueLastQuarter)
|
stats.CompanyValueLastQuarter = int64(sp.CompanyValueLastQuarter)
|
||||||
stats.CompanyValuePreviousQuarter = int64(sp.CompanyValuePreviousQuarter)
|
stats.CompanyValuePreviousQuarter = int64(sp.CompanyValuePreviousQuarter)
|
||||||
|
}
|
||||||
case AdminPacketServerCompanyStats:
|
case AdminPacketServerCompanyStats:
|
||||||
sp := PacketServerCompanyStats{
|
sp := PacketServerCompanyStats{
|
||||||
Packet: p,
|
Packet: p,
|
||||||
@ -419,20 +422,22 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
|||||||
logInfoDebug("Server.Poll() : PacketServerCompanyStats :\n- CompanyID: %d\n- Vehicles T: %d\tL: %d\tB: %d\tP: %d\tS: %d\n- Stations T: %d\tL: %d\tB: %d\tP: %d\tS: %d", sp.CompanyID, sp.Trains, sp.Lorries, sp.Busses, sp.Planes, sp.Ships, sp.TrainStations, sp.LorryStations, sp.BusStops, sp.Airports, sp.Harbours)
|
logInfoDebug("Server.Poll() : PacketServerCompanyStats :\n- CompanyID: %d\n- Vehicles T: %d\tL: %d\tB: %d\tP: %d\tS: %d\n- Stations T: %d\tL: %d\tB: %d\tP: %d\tS: %d", sp.CompanyID, sp.Trains, sp.Lorries, sp.Busses, sp.Planes, sp.Ships, sp.TrainStations, sp.LorryStations, sp.BusStops, sp.Airports, sp.Harbours)
|
||||||
|
|
||||||
if cfg.Stats == nil {
|
if cfg.Stats == nil {
|
||||||
cfg.Stats = make(map[uint8]map[string]*Stat)
|
cfg.Stats = make(map[int]map[string]*Stat)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := cfg.Stats[sp.CompanyID]
|
if cfg.CompanyIsRegistered(sp.CompanyID) {
|
||||||
|
cc := cfg.GetCompanyClient(sp.CompanyID)
|
||||||
|
_, ok := cfg.Stats[cc.UserID]
|
||||||
if !ok {
|
if !ok {
|
||||||
cfg.Stats[sp.CompanyID] = make(map[string]*Stat)
|
cfg.Stats[cc.UserID] = make(map[string]*Stat)
|
||||||
}
|
}
|
||||||
stats, ok := cfg.Stats[sp.CompanyID][s.Status.GameDate.Format("20060102")]
|
stats, ok := cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||||
if !ok {
|
if !ok {
|
||||||
stats = &Stat{
|
stats = &Stat{
|
||||||
CompanyID: sp.CompanyID,
|
CompanyID: sp.CompanyID,
|
||||||
Date: s.Status.GameDate,
|
Date: s.Status.GameDate,
|
||||||
}
|
}
|
||||||
cfg.Stats[sp.CompanyID][s.Status.GameDate.Format("20060102")] = stats
|
cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||||
}
|
}
|
||||||
|
|
||||||
stats.Trains = int(sp.Trains)
|
stats.Trains = int(sp.Trains)
|
||||||
@ -445,7 +450,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
|||||||
stats.Airports = int(sp.Airports)
|
stats.Airports = int(sp.Airports)
|
||||||
stats.Ships = int(sp.Ships)
|
stats.Ships = int(sp.Ships)
|
||||||
stats.Harbours = int(sp.Harbours)
|
stats.Harbours = int(sp.Harbours)
|
||||||
|
}
|
||||||
case AdminPacketServerChat:
|
case AdminPacketServerChat:
|
||||||
sp := PacketServerChat{
|
sp := PacketServerChat{
|
||||||
Packet: p,
|
Packet: p,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||||
package main
|
package main
|
||||||
var githash = "e7f47ca"
|
var githash = "be1712b"
|
||||||
var buildstamp = "2021-12-08_14:23:02"
|
var buildstamp = "2021-12-09_13:41:53"
|
||||||
var commits = "246"
|
var commits = "247"
|
||||||
var version = "e7f47ca-b246 - 2021-12-08_14:23:02"
|
var version = "be1712b-b247 - 2021-12-09_13:41:53"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user