I am struggling a bit in this one - in order to find the necessary battery capacity I need to analyze production/demand over a year's worth of data. To do this, I figured I need to calculate the biggest area under the 0 line. I guess I need to find the start/end points of that area and multiply everything by its respective y-value?
Here is a shortened version of the graph I have:
That is the biggest area under the 0 in the image, but in the full dataset it could be any area. I know how to integrate it in the case I find the boundaries of the area in question but I'm struggling to find an efficient way to do that.
My dataframe looks like this:
demand Production diff
Time
2019-01-01 00:15:01 17.25 32.907 15.657
2019-01-01 00:30:01 17.80 32.954 15.154
... ... ... ...
2019-01-16 22:15:02 17.34 27.704 10.364
2019-01-16 22:30:01 18.67 35.494 16.824
I use this snippet to find the length in timesteps of the longest area but I'm missing if there's a way to multiply the points by their y-values (diff). It's technically not correct, however, considering that an area might be long but narrow and another might be shorter and taller, so with an overall bigger area.
def max0(sr):
return (sr >= 0).cumsum().value_counts().max() - (0 if (sr >= 0).cumsum().value_counts().idxmax() < 0 else 1)