Sum updation when no data is present in given timeperiod

Dear Ubidots team,

We are working to develop smart factory solution.
Scenario: machine sends its speed every 1 minute (approximately).

Typical inputs (raw variables):

  1. speed: value >1 (actual speed of machine)
  2. speed : = 0 (when machine is idle). machine is power on but motor is off. IoT device 0 value.
  3. No Data (machine is switched and our IoT device is also off).

We want to get various KPI on every shift (8 hour) basis.
For trials, we work on 5 minute window ". To begin with, we just sum() the data as synthetic variable.
I could play around with synthetic variable to generate various output in (1) and (2).
For example, we used sum(input, “5T”) to sum the input data points.

But when there is no data for given 5 minute interval, we still want to have 0 output in sum.
We played around with offset and position. eg: position=start and position=end.
In final use case. we will be using position=end to get runtime of past 5 minutes.

Now, when machine is off (case 3) for many 5 minute intervals, there is no input data. And sum is not getting updated in those intervals.

When we push some data after 20 minutes, we get 0 values of all previous 5 minute intervals (when no data was present). But not before that. I believe there is delay in processing.

Also, we observed that
a) 0 value of 5 minute intervals (when no data present) was updated only for position=start.
b) for position=end, 0 values were not updated where data is not present.
c) We could see that once we click, “Compute historic data” the previous data was computed.

Can we have a mechanism that sum is updated every 5 minutes independent of presence of new data push? Basically zero value of sum when no data is present.
Some options I could image:
a) Dummy zero data when no input data is present, but it has to be triggered in some way? events?
b) use count() and check for zero value. then assign output to be sum() or 0 value.

Finally, we will be changing 5 minutes to 8 hours. And we need “last shift” runtime as zero when machine was totally off (with no data points received).

Thanks,
Sunand Mittal

Hello, @Sunand

I hope this note finds you well,

I would like to clarify that a sum() function doesn’t return 0 when there is no data because inside of it there is no way of knowing whether the data totaled 0 or there was actually no data during the period. This behavior is opposite to the count() function which returns 0 when there’s no data. Having all this in mind we could create an expression combining these two behaviors by using a conditional as follows:

a = count(var, '5T')
b = sum(var, '5T')
where(a > 0, b, 0)

That way the expression will output the sum if there was data in the interval otherwise it will return 0. Please verify and let us know if that would help with the expression you’re trying to create for the KPIs.

Regards,

-Santiago