I have a list of random data and a threshold:
threshold = 3
data = [2,2,2,2,2,5,5,2,2,2,2,3,4,5,6,4,5,4,3,4,5,3,3,7,8,2,2,2] # data
timestamp =[]
for i in range(len(data)):
timestamp.append(i)
print(timestamp)
I am trying to extract timestamps that are below the threshold but, if a range of consecutive timestamps (less than 4 timestamps (<4)), between 2 time ranges below the threshold occurs, we also treat it as below the threshold
As such, this example should return:
belowthreshold = [0,1,2,3,4,5,6,7,8,9,10,25,26,27]
So we can see that the consecutive 5,5 is skipped and treated as under threshold since values before and after it are under threshold
Currently, my method is:
belowthreshold = []
for j in range(len(data)):
if data[j] < threshold and data[j]: # check if greater than threshold, meaning energy is being used at home
belowthreshold.append(j) # add this time to a list
However it quite clearly only extracts values less than the threshold.
What is the best way to approach this?
Thanks in advance for your answers