add stats daily
This commit is contained in:
parent
7590355d87
commit
15203263e6
35
bot.go
35
bot.go
@ -389,7 +389,8 @@ func botActuallyReset(m *tb.Message) {
|
||||
} else {
|
||||
cfg.Save("backup." + *configFlag)
|
||||
cfg.Game.Started = false
|
||||
cfg.Stats = make(map[int]map[string]*Stat)
|
||||
cfg.StatsMonthly = make(map[int]map[string]*StatMonthly)
|
||||
cfg.StatsDaily = make(map[int]map[string]*StatDaily)
|
||||
for _, cc := range cfg.Clients {
|
||||
cc.Ready = false
|
||||
cc.CompanyID = 255
|
||||
@ -943,7 +944,7 @@ func botGraphValue(m *tb.Message) {
|
||||
unitFactor float64
|
||||
unitName string
|
||||
)
|
||||
for _, dStats := range cfg.Stats {
|
||||
for _, dStats := range cfg.StatsMonthly {
|
||||
for _, stat := range dStats {
|
||||
valueFloat := float64(stat.CompanyValueLastQuarter)
|
||||
if math.Abs(valueFloat) > maxVal {
|
||||
@ -964,7 +965,7 @@ func botGraphValue(m *tb.Message) {
|
||||
|
||||
var vals map[int]plotter.XYs
|
||||
vals = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
vals[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1037,7 +1038,7 @@ func botGraphValueDelta(m *tb.Message) {
|
||||
|
||||
var vals map[int]plotter.XYs
|
||||
vals = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
vals[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1145,7 +1146,7 @@ func botGraphMoney(m *tb.Message) {
|
||||
unitFactor float64
|
||||
unitName string
|
||||
)
|
||||
for _, dStats := range cfg.Stats {
|
||||
for _, dStats := range cfg.StatsMonthly {
|
||||
for _, stat := range dStats {
|
||||
valueFloat := float64(stat.Money)
|
||||
if math.Abs(valueFloat) > maxVal {
|
||||
@ -1166,7 +1167,7 @@ func botGraphMoney(m *tb.Message) {
|
||||
|
||||
var vals map[int]plotter.XYs
|
||||
vals = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
vals[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1236,7 +1237,7 @@ func botGraphIncome(m *tb.Message) {
|
||||
unitFactor float64
|
||||
unitName string
|
||||
)
|
||||
for _, dStats := range cfg.Stats {
|
||||
for _, dStats := range cfg.StatsMonthly {
|
||||
for _, stat := range dStats {
|
||||
valueFloat := float64(stat.Income)
|
||||
if math.Abs(valueFloat) > maxVal {
|
||||
@ -1257,7 +1258,7 @@ func botGraphIncome(m *tb.Message) {
|
||||
|
||||
var vals map[int]plotter.XYs
|
||||
vals = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
vals[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1327,7 +1328,7 @@ func botGraphLoan(m *tb.Message) {
|
||||
unitFactor float64
|
||||
unitName string
|
||||
)
|
||||
for _, dStats := range cfg.Stats {
|
||||
for _, dStats := range cfg.StatsMonthly {
|
||||
for _, stat := range dStats {
|
||||
valueFloat := float64(stat.Loan)
|
||||
if math.Abs(valueFloat) > maxVal {
|
||||
@ -1348,7 +1349,7 @@ func botGraphLoan(m *tb.Message) {
|
||||
|
||||
var vals map[int]plotter.XYs
|
||||
vals = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
vals[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1418,7 +1419,7 @@ func botGraphPerf(m *tb.Message) {
|
||||
unitFactor float64
|
||||
unitName string
|
||||
)
|
||||
for _, dStats := range cfg.Stats {
|
||||
for _, dStats := range cfg.StatsMonthly {
|
||||
for _, stat := range dStats {
|
||||
valueFloat := float64(stat.PerformancePreviousQuarter)
|
||||
if math.Abs(valueFloat) > maxVal {
|
||||
@ -1439,7 +1440,7 @@ func botGraphPerf(m *tb.Message) {
|
||||
|
||||
var vals map[int]plotter.XYs
|
||||
vals = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
vals[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1507,7 +1508,7 @@ func botGraphPlanes(m *tb.Message) {
|
||||
var planes, airports map[int]plotter.XYs
|
||||
planes = make(map[int]plotter.XYs)
|
||||
airports = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
planes[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1577,7 +1578,7 @@ func botGraphBusses(m *tb.Message) {
|
||||
var busses, busStops map[int]plotter.XYs
|
||||
busses = make(map[int]plotter.XYs)
|
||||
busStops = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
busses[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1647,7 +1648,7 @@ func botGraphTrains(m *tb.Message) {
|
||||
var trains, trainStations map[int]plotter.XYs
|
||||
trains = make(map[int]plotter.XYs)
|
||||
trainStations = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
trains[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1717,7 +1718,7 @@ func botGraphLorries(m *tb.Message) {
|
||||
var lorries, lorriesStations map[int]plotter.XYs
|
||||
lorries = make(map[int]plotter.XYs)
|
||||
lorriesStations = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
lorries[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
@ -1787,7 +1788,7 @@ func botGraphShips(m *tb.Message) {
|
||||
var ships, harbours map[int]plotter.XYs
|
||||
ships = make(map[int]plotter.XYs)
|
||||
harbours = make(map[int]plotter.XYs)
|
||||
for ccID, dStats := range cfg.Stats {
|
||||
for ccID, dStats := range cfg.StatsMonthly {
|
||||
ships[ccID] = make(plotter.XYs, 0)
|
||||
for dStr, stat := range dStats {
|
||||
d, err := time.Parse("20060102", dStr)
|
||||
|
14
config.go
14
config.go
@ -44,18 +44,20 @@ type ClientConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Server *ServerConfig `json:"server"`
|
||||
Telegram *TelegramConfig `json:"telegram"`
|
||||
Game *GameConfig `json:"game"`
|
||||
Clients map[int]*ClientConfig `json:"clients"`
|
||||
Stats map[int]map[string]*Stat `json:"stats"`
|
||||
Server *ServerConfig `json:"server"`
|
||||
Telegram *TelegramConfig `json:"telegram"`
|
||||
Game *GameConfig `json:"game"`
|
||||
Clients map[int]*ClientConfig `json:"clients"`
|
||||
StatsMonthly map[int]map[string]*StatMonthly `json:"stats_monthly"`
|
||||
StatsDaily map[int]map[string]*StatDaily `json:"stats_daily"`
|
||||
}
|
||||
|
||||
// Init values for a config based on package defaults
|
||||
func (c *Config) Init() error {
|
||||
err := json.Unmarshal(cfgSample, &c)
|
||||
c.Clients = make(map[int]*ClientConfig)
|
||||
c.Stats = make(map[int]map[string]*Stat)
|
||||
c.StatsMonthly = make(map[int]map[string]*StatMonthly)
|
||||
c.StatsDaily = make(map[int]map[string]*StatDaily)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
12
stats.go
12
stats.go
@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Stat struct {
|
||||
type StatMonthly struct {
|
||||
CompanyID uint8
|
||||
Date time.Time
|
||||
Trains int
|
||||
@ -28,3 +28,13 @@ type Stat struct {
|
||||
PerformancePreviousQuarter int
|
||||
DeliveredCargoPreviousQuarter int
|
||||
}
|
||||
|
||||
type StatDaily struct {
|
||||
Money int64
|
||||
Loan int64
|
||||
Value int64
|
||||
Trains int
|
||||
Road int
|
||||
Planes int
|
||||
Ships int
|
||||
}
|
||||
|
40
ttd.go
40
ttd.go
@ -224,6 +224,11 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
||||
}
|
||||
s.Status.GameDate = gameDate
|
||||
s.Status.UpdateDate = time.Now()
|
||||
px := PacketAdminRCon{
|
||||
Packet: Packet{PType: AdminPacketAdminRCon},
|
||||
Command: "companies",
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
case AdminPacketServerClientJoin:
|
||||
sp := PacketServerClientJoin{
|
||||
Packet: p,
|
||||
@ -384,23 +389,23 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
||||
sp.Read(buffer[:p.PLength])
|
||||
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 {
|
||||
cfg.Stats = make(map[int]map[string]*Stat)
|
||||
if cfg.StatsMonthly == nil {
|
||||
cfg.StatsMonthly = make(map[int]map[string]*StatMonthly)
|
||||
}
|
||||
|
||||
if cfg.CompanyIsRegistered(sp.CompanyID) {
|
||||
cc := cfg.GetCompanyClient(sp.CompanyID)
|
||||
_, ok := cfg.Stats[cc.UserID]
|
||||
_, ok := cfg.StatsMonthly[cc.UserID]
|
||||
if !ok {
|
||||
cfg.Stats[cc.UserID] = make(map[string]*Stat)
|
||||
cfg.StatsMonthly[cc.UserID] = make(map[string]*StatMonthly)
|
||||
}
|
||||
stats, ok := cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
stats, ok := cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
if !ok {
|
||||
stats = &Stat{
|
||||
stats = &StatMonthly{
|
||||
CompanyID: sp.CompanyID,
|
||||
Date: s.Status.GameDate,
|
||||
}
|
||||
cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
}
|
||||
|
||||
stats.Money = int64(sp.Money)
|
||||
@ -421,23 +426,23 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
||||
sp.Read(buffer[:p.PLength])
|
||||
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 {
|
||||
cfg.Stats = make(map[int]map[string]*Stat)
|
||||
if cfg.StatsMonthly == nil {
|
||||
cfg.StatsMonthly = make(map[int]map[string]*StatMonthly)
|
||||
}
|
||||
|
||||
if cfg.CompanyIsRegistered(sp.CompanyID) {
|
||||
cc := cfg.GetCompanyClient(sp.CompanyID)
|
||||
_, ok := cfg.Stats[cc.UserID]
|
||||
_, ok := cfg.StatsMonthly[cc.UserID]
|
||||
if !ok {
|
||||
cfg.Stats[cc.UserID] = make(map[string]*Stat)
|
||||
cfg.StatsMonthly[cc.UserID] = make(map[string]*StatMonthly)
|
||||
}
|
||||
stats, ok := cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
stats, ok := cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
if !ok {
|
||||
stats = &Stat{
|
||||
stats = &StatMonthly{
|
||||
CompanyID: sp.CompanyID,
|
||||
Date: s.Status.GameDate,
|
||||
}
|
||||
cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
}
|
||||
|
||||
stats.Trains = int(sp.Trains)
|
||||
@ -851,7 +856,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateDate)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateDate")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@ -860,7 +864,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateClientInfo)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateClientInfo")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@ -869,7 +872,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateCompanyInfo)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateCompanyInfo")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@ -878,7 +880,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateCompanyEconomy)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateCompanyEconomy")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@ -887,7 +888,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateCompanyStats)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateCompanyStats")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@ -896,7 +896,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateChat)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateChat")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@ -905,7 +904,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateConsole)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateConsole")
|
||||
|
||||
s.Status.Initialized = true
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||
package main
|
||||
var githash = "2a2dd7e"
|
||||
var buildstamp = "2021-12-09_14:04:15"
|
||||
var commits = "251"
|
||||
var version = "2a2dd7e-b251 - 2021-12-09_14:04:15"
|
||||
var githash = "7590355"
|
||||
var buildstamp = "2021-12-10_13:21:22"
|
||||
var commits = "252"
|
||||
var version = "7590355-b252 - 2021-12-10_13:21:22"
|
||||
|
Loading…
x
Reference in New Issue
Block a user