expirement value_delta

This commit is contained in:
shoopea 2021-12-08 20:15:14 +08:00
parent c6a235e436
commit 4ad875c1ec
2 changed files with 47 additions and 52 deletions

91
bot.go
View File

@ -128,6 +128,37 @@ func (b *Bot) BotHandlers() {
b.bot.Start() b.bot.Start()
} }
func botHelp(m *tb.Message) {
msg := ""
msg = fmt.Sprintf("%s/pause - pause the game\r\n", msg)
msg = fmt.Sprintf("%s/unpause - unpause the game\r\n", msg)
msg = fmt.Sprintf("%s/register - register company\r\n", msg)
msg = fmt.Sprintf("%s/deregister - deregister company\r\n", msg)
msg = fmt.Sprintf("%s/delete - delete company\r\n", msg)
msg = fmt.Sprintf("%s/companies - list companies\r\n", msg)
msg = fmt.Sprintf("%s/clients - list clients\r\n", msg)
msg = fmt.Sprintf("%s/give - give time to player\r\n", msg)
msg = fmt.Sprintf("%s/take - take time from player\r\n", msg)
msg = fmt.Sprintf("%s/transfer - transfer time between players\r\n", msg)
msg = fmt.Sprintf("%s/passwd - change passwd\r\n", msg)
msg = fmt.Sprintf("%s/say - send msg to the game\r\n", msg)
msg = fmt.Sprintf("%s/reset - reset the game\r\n", msg)
msg = fmt.Sprintf("%s/start - start the game\r\n", msg)
msg = fmt.Sprintf("%s/ready - set player as ready\r\n", msg)
msg = fmt.Sprintf("%s/players - list players\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_delta - delta value 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/planes - planes graph\r\n", msg)
msg = fmt.Sprintf("%s/version - version\r\n", msg)
msg = fmt.Sprintf("%s/help - this\r\n", msg)
bot.SendChat(m.Chat.ID, msg)
return
}
func botPause(m *tb.Message) { func botPause(m *tb.Message) {
for userID, cc := range cfg.Clients { for userID, cc := range cfg.Clients {
if userID == m.Sender.ID { if userID == m.Sender.ID {
@ -685,31 +716,6 @@ func botTake(m *tb.Message) {
bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft.Round(time.Second))) bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s now has %s left.", uStr, cc.TimeLeft.Round(time.Second)))
} }
func botHelp(m *tb.Message) {
msg := ""
msg = fmt.Sprintf("%s/pause - pause the game\r\n", msg)
msg = fmt.Sprintf("%s/unpause - unpause the game\r\n", msg)
msg = fmt.Sprintf("%s/register - register company\r\n", msg)
msg = fmt.Sprintf("%s/deregister - deregister company\r\n", msg)
msg = fmt.Sprintf("%s/delete - delete company\r\n", msg)
msg = fmt.Sprintf("%s/companies - list companies\r\n", msg)
msg = fmt.Sprintf("%s/clients - list clients\r\n", msg)
msg = fmt.Sprintf("%s/give - give time to player\r\n", msg)
msg = fmt.Sprintf("%s/take - take time from player\r\n", msg)
msg = fmt.Sprintf("%s/transfer - transfer time between players\r\n", msg)
msg = fmt.Sprintf("%s/passwd - change passwd\r\n", msg)
msg = fmt.Sprintf("%s/say - send msg to the game\r\n", msg)
msg = fmt.Sprintf("%s/reset - reset the game\r\n", msg)
msg = fmt.Sprintf("%s/start - start the game\r\n", msg)
msg = fmt.Sprintf("%s/ready - set player as ready\r\n", msg)
msg = fmt.Sprintf("%s/players - list players\r\n", msg)
msg = fmt.Sprintf("%s/version - version\r\n", msg)
msg = fmt.Sprintf("%s/help - this\r\n", msg)
bot.SendChat(m.Chat.ID, msg)
return
}
func botSay(m *tb.Message) { func botSay(m *tb.Message) {
r := regexp.MustCompile("^\\/say( )+(?P<Message>.+)$") r := regexp.MustCompile("^\\/say( )+(?P<Message>.+)$")
if !r.MatchString(m.Text) { if !r.MatchString(m.Text) {
@ -1016,7 +1022,6 @@ func botGraphValue(m *tb.Message) {
func botGraphValueDelta(m *tb.Message) { func botGraphValueDelta(m *tb.Message) {
var ( var (
minZero int
maxVal float64 maxVal float64
unitFactor float64 unitFactor float64
unitName string unitName string
@ -1041,36 +1046,26 @@ func botGraphValueDelta(m *tb.Message) {
vals[coID] = append(vals[coID], pt) vals[coID] = append(vals[coID], pt)
} }
sort.Slice(vals[coID], func(i, j int) bool { return vals[coID][i].X < vals[coID][j].X }) sort.Slice(vals[coID], func(i, j int) bool { return vals[coID][i].X < vals[coID][j].X })
if len(vals[coID]) > minZero {
minZero = len(vals[coID])
}
} }
} }
logInfoDebug("botGraphValueDelta : got %d values", minZero)
for coID, v := range vals { for coID, v := range vals {
for i := len(v) - 1; i > 0; i-- { if len(v) <= 3 {
v[i].Y = v[i].Y - v[i-1].Y delete(vals, coID)
if math.Abs(v[i].Y) > maxVal {
maxVal = math.Abs(v[i].Y)
}
if v[i].Y == 0 && i < minZero {
minZero = i
}
}
vals[coID] = v
}
for coID, v := range vals {
if minZero > 1 {
vals[coID] = v[minZero:]
} else { } else {
vals[coID] = v[1:] v0 := v[0].Y
v1 := v[1].Y
v2 := v[2].Y
for i := 3; i < len(v); i++ {
v0 = v1
v1 = v2
v2 = v[i].Y
v[i].Y = (v0 + v1 + v2) / 3
}
vals[coID] = v[3:]
} }
} }
logInfoDebug("botGraphValueDelta : removing leading %d values", minZero)
if maxVal > 1000000000 { if maxVal > 1000000000 {
unitFactor = 1000000000 unitFactor = 1000000000
unitName = "billion" unitName = "billion"

View File

@ -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 = "14f65a4" var githash = "c6a235e"
var buildstamp = "2021-12-08_11:53:51" var buildstamp = "2021-12-08_12:15:03"
var commits = "239" var commits = "240"
var version = "14f65a4-b239 - 2021-12-08_11:53:51" var version = "c6a235e-b240 - 2021-12-08_12:15:03"