Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
cuniberto
Contributor III
Contributor III

sum without overlapping intervals in load script

Ciao,

i would like to sum the intervals of machine work only when they are not overlapped.

this is because if the machine work on two production order i don't want to duplicate worked time.

i hope the following table would explain better than my english.

ENG 1interval 113/03/201810.1311.151.02
ENG 1interval 213/03/201811.3012.301.00
ENG 1interval 313/03/201812.0012.300.30

TOTAL2.02

interval 3 is overlapped.

1 Solution

Accepted Solutions
cuniberto
Contributor III
Contributor III
Author

i've solved in this way:

temp:

load

if(begin<peek(end),peek(ID),rowno()) as ID

residen time_table;

in this way if the begin is overlapped to previous end it takes same id, then i used

time_differences:

load

max(end)-min(begin) as time_difference

resident temp group by ID;

View solution in original post

5 Replies
sunny_talwar

So you want to calculate this sum in the script?

marcus_sommer

You could do it with the help of Peek() or Previous() ? maybe with a logic like this:

...

if(Key = previous(Key) and Date = previous(Date) and Start < previous(End), 1, 0) as Flag

...

You might need some more if-conditions to fetch all possible combinations but then using this flag as a set analysis condition in the UI you could sum the values. Whereby also a cummulating within the script will be possible.

- Marcus

cuniberto
Contributor III
Contributor III
Author

i would like to obtain a sum like the one represented in attechment: when the interval is overlapped i would have the difference between the max end hour and the min value

Cattura3.JPG

cuniberto
Contributor III
Contributor III
Author

i've solved in this way:

temp:

load

if(begin<peek(end),peek(ID),rowno()) as ID

residen time_table;

in this way if the begin is overlapped to previous end it takes same id, then i used

time_differences:

load

max(end)-min(begin) as time_difference

resident temp group by ID;

cata_pli
Partner - Contributor III
Partner - Contributor III

It's an old thread, but maybe someone will see it.

I think in temp table you need to add one more condition to cover the case where you have at least 3  simultaneous intervals like this:

   beginend 
ENG 1interval 113/03/201810111
ENG 1interval 213/03/201810.110.30.2
ENG 1interval 313/03/201810.6121.4
  TOTAL  2

 

Your condition: if(begin<peek(end),peek(ID), rowno()) as ID ... applied for interval 3 will not work ok (it will give false) and it will duplicate interval 3, although interval 1 is still running. It will compare 10.6 with 10.3, but it should compare 10.6 with 11. 

This will be resolved if we also put the next condition in temp:

if( end < peek(end), peek(end), end) as end

That way it will replace end of interval 2 (10.3) with end of interval 1 (11) and it will not consider interval 3 having a new ID.