Forum Discussion
Find last camera status
It is possible to do this, but it is a bit complex...
Your first step is to make a date table with 1 row per date, since in the rare case there is no events for a day, you still want to generate stats.
Next, in a custom column you will need to find the last event that happened no latter than the date for that row (could be yesterday). This event will indicate if the camera is on or off.
Then you will need a column that finds the first event for that day. Then another column that determins the turn on time, which is the event time of the first event if the event is a turn on event, or the start of the day if it is a turn off event. In the case of no events for that day, you need to look at the most recent event and assign the turn on to either start of day if the last event is on, or end of day if it is off.
Once you have calculated the first turn on and last turn off time, you would calculate the total turn on or off time for that day. To do this, subtract every event on/off time in the list by the first turn on time (which can be start of day), for turn off events make the value negative. Now just add up the transformed event times and you should get the total on time (take 24 hours and subtract this value to get the off time)
Great my friend, but can you give me a hint how to start to do this? can i solve it with M language?