Given a panda series where a value is either {0, +1, -1} and the sequence always starts with a +1 and end with a -1.
For example,
2019-01-02 15:19:00 0.0
2019-01-02 15:20:00 0.0
2019-01-02 15:21:00 1.0 # sequence start
2019-01-02 15:22:00 0.0 # sequence continue, it's only a 0
2019-01-02 15:23:00 -1.0 # sequence finish, let's look for the next +1 value
2019-01-02 15:24:00 0.0
2019-01-02 15:25:00 1.0 # sequence start
2019-01-02 15:26:00 -1.0 # sequence finish
2019-01-02 15:27:00 0.0
2019-01-02 15:28:00 0.0
2019-01-02 15:29:00 1.0 # sequence start
2019-01-02 15:30:00 -1.0 # sequence finish
How do you calculate the total number of sequences where the interval from the "sequence start" and "sequence finish" is less than 5 minutes.
For example,
2019-01-02 15:19:00 0.0
2019-01-02 15:20:00 0.0
2019-01-02 15:21:00 1.0 # sequence start
2019-01-02 15:22:00 0.0
2019-01-02 15:23:00 0.0
2019-01-02 15:24:00 0.0
2019-01-02 15:25:00 -1.0 # sequence finish (sequence start to sequence finish is less than 5 minutes, so increment counter)
2019-01-02 15:26:00 1.0 # sequence start
2019-01-02 15:27:00 0.0
2019-01-02 15:28:00 0.0
2019-01-02 15:29:00 0.0
2019-01-02 15:30:00 0.0
2019-01-02 15:31:00 0.0
2019-01-02 15:32:00 0.0
2019-01-02 15:33:00 0.0
2019-01-02 15:34:00 0.0
2019-01-02 15:35:00 0.0
2019-01-02 15:36:00 0.0
2019-01-02 15:37:00 0.0
2019-01-02 15:38:00 0.0
2019-01-02 15:39:00 0.0
2019-01-02 15:40:00 -1.0 # sequence finish (longer than 5 minutes, don't increment)
From the above example, we get a total count:
counter: 1