Calculating on off time and time between; idea search?

#1

Could anyone give me a recommendation on the best way to query ie calculate on/off and time between each on off. And how that simple data could be analyzed?

say I have a measurement widget with a value of devicestate ( 0(off) or 1 (on)).

I get a record every second, most of the time, but not always. Would look something like this charted:

on ***** ************ ***
off *** ******** ******* *****

What are the best ways to query influx and what kind of info could I derive with it.

What would be useful information?

total time on vs off
average duration of an off or on period
maybe some kind of standard deviation of when on and off. is it off on longer than what is historically normal.
anything else you can think of…

thanks,