change delta compute

This commit is contained in:
shoopea 2021-12-08 22:03:04 +08:00
parent 350d7cfb10
commit 55fa6be367
2 changed files with 20 additions and 21 deletions

25
bot.go
View File

@ -1050,23 +1050,22 @@ func botGraphValueDelta(m *tb.Message) {
} }
for coID, v := range vals { for coID, v := range vals {
if len(v) <= 3 { v2 := make(plotter.XYs, 0)
delete(vals, coID) for i := 0; i < len(v); i = i + 3 {
} else { v2 = append(v2, v[i])
}
vals[coID] = v2
}
for coID, v := range vals {
v0 := v[0].Y v0 := v[0].Y
v1 := v[1].Y for i := 1; i < len(v); i++ {
v2 := v[2].Y v[i].Y, v0 = v[i].Y-v0, v[i].Y
for i := 3; i < len(v); i++ {
v0 = v1
v1 = v2
v2 = v[i].Y
v[i].Y = (v0+v1+v2)/3 - v1
if math.Abs(v[i].Y) > maxVal { if math.Abs(v[i].Y) > maxVal {
maxVal = math.Abs(v[i].Y) maxVal = math.Abs(v[i].Y)
} }
} }
vals[coID] = v[3:] vals[coID] = v[1:]
}
} }
if maxVal > 1000000000 { if maxVal > 1000000000 {
@ -1083,7 +1082,7 @@ func botGraphValueDelta(m *tb.Message) {
logInfoDebug("botGraphValueDelta : unit set to %s (factor : %f)", unitName, unitFactor) logInfoDebug("botGraphValueDelta : unit set to %s (factor : %f)", unitName, unitFactor)
for coID, v := range vals { for coID, v := range vals {
for i := 1; i < len(vals)-1; i++ { for i := 0; i < len(vals); 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", coID, v[i].X)

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 = "ef7af10" var githash = "350d7cf"
var buildstamp = "2021-12-08_13:30:52" var buildstamp = "2021-12-08_14:02:46"
var commits = "242" var commits = "243"
var version = "ef7af10-b242 - 2021-12-08_13:30:52" var version = "350d7cf-b243 - 2021-12-08_14:02:46"