averageSince creates error "Division undefined" only for a certain period

Folks,

I have a rule which is doing an averageSince on an item.
For a certain band, it errors. Either before or after a certain time, it works fine.

  • RPi4
  • 2.4
  • default persistence in runtime.cfg is mysql

item

Number BedtimeMinutesOfDay      "Bedtime minutes of bedtime"    (g_persist_change)
Number KKOOPP 

g_persist_change is mysql persistence and used system wide.

rule


rule "FFF" 
when Item KKOOPP received command
then
    val f = (KKOOPP.state as Number).intValue

    logWarn("FFDD", "Going back " + f.toString + " " + now.minusDays(f).toString)
    var avgX = BedtimeMinutesOfDay.averageSince(now.minusDays(f))

    if (avgX === null){
        logWarn("KKK", "value is null")
        return;
    }

    logWarn("DD", avgX.toString)

end 


results

21:09:52.360 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 11
21:09:52.367 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 10 2019-11-17T21:09:52.366Z
21:09:52.375 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 10 to 11
21:09:52.378 [WARN ] [rg.eclipse.smarthome.model.script.KKK] - value is null
...
21:09:54.567 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 12
21:09:54.575 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 11 to 12
21:09:54.577 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 12 2019-11-15T21:09:54.576Z
21:09:54.584 [WARN ] [rg.eclipse.smarthome.model.script.KKK] - value is null
...
21:09:56.373 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 13
21:09:56.386 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 12 to 13
21:09:56.399 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 13 2019-11-14T21:09:56.390Z
21:09:56.414 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'FFF': Division undefined
...
21:09:58.235 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 14
21:09:58.249 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 13 to 14
21:09:58.278 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 14 2019-11-13T21:09:58.271Z
21:09:58.292 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'FFF': Division undefined
...
...
21:09:59.816 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 15
21:09:59.833 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 14 to 15
21:09:59.837 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 14 2019-11-13T21:09:59.834Z
21:09:59.849 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'FFF': Division undefined
...
21:10:01.770 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 16
21:10:01.778 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 15 2019-11-12T21:10:01.776Z
21:10:01.780 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 15 to 16
21:10:01.786 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'FFF': Division undefined
...
21:10:04.933 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 16
21:10:04.940 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 16 2019-11-11T21:10:04.939Z
21:10:04.945 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'FFF': Division undefined
...
21:10:07.943 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 17
21:10:07.954 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 16 to 17
21:10:07.960 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 17 2019-11-10T21:10:07.958Z
21:10:07.974 [WARN ] [org.eclipse.smarthome.model.script.DD] - 1417.0
...
21:10:11.079 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'KKOOPP' received command 18
21:10:11.090 [INFO ] [smarthome.event.ItemStateChangedEvent] - KKOOPP changed from 17 to 18
21:10:11.095 [WARN ] [g.eclipse.smarthome.model.script.FFDD] - Going back 18 2019-11-09T21:10:11.093Z
21:10:11.110 [WARN ] [org.eclipse.smarthome.model.script.DD] - 1417.0

Data in the mysql table

So, if I go to a period where there is no data, it acts correctly, returns null. Makes sense.
If I go well into the data period, it works as expected.
If I straddle the latest two rows for the data it errors which I don’t feel is right.

I’ve read a number of the other posts which also have this error and can’t see any similarities.

Anything I am doing daft here or should this just be logged as a bug?