Finding X lowest values
I'm trying to put together a Task to run a pool circulation pump only on the hours when the electricity cost is the lowest. I can get the prices from nordpoolspot.com API. I end up with 24 Doubles, one for each hour of the day. But I have not managed to figure out a way to filter out the lowest values.
For instance I need to run the pump for 6 hours every day. So at every hour I need a way to check "Is this current hour one of the 6 cheapest hours for today?"
Any ideas?
I still have not managed to find a way to achieve this, however I'm using a temporary "good enough" solution. I'm calculating the average of the days power cost and then checking to see if current hours cost is below average. If it is, it counts as one of the "safe" hours.
The only problem is, when I need to run the pump for longer than there are hours with below average costs in a given day. For that case I'm currently just logging an error message saying "The pump was asked to run for X hours, but it only ran for Y hours yesterday." To give me a heads up should this happen.
the trick is to find the highest value of the X cheepset hours and then you can check if the actual hour price is <= this price. To finde this reverence price will be a tough one.
Max