kipe / nordpool

Python library for fetching Nord Pool spot prices.
MIT License
105 stars 39 forks source link

Fetching Elbas is missing additional data (Min, Max,...) #49

Closed MacValley closed 1 month ago

MacValley commented 1 month ago
First of all, many thanks for fixing the issue with getting hourly values. However, I see one difference since before Oct 14: Additional data, like Min, Max, Average is no longer added at the bottom of prices_spot.hourly. On Oct 14, the result was: start "2024-10-13 22:00:00+00:00"
end "2024-10-14 22:00:00+00:00"
updated "2024-10-14 11:16:42.452000+00:00"
currency "SEK"
areas  
SE4  
values […]
Min 223.31
Max 2990.41
Average 1115.63
Peak 1473.33
Off-peak 1 565.04
Off-peak 2 1143.74
However from Oct 16 the result is: start "2024-10-16 22:00:00+00:00"
end "2024-10-17 22:00:00+00:00"
updated "2024-10-16 11:24:40.210954+00:00"
currency "SEK"
areas  
SE4  
values […]

I did not change my code at all, I just find that Min, Max etc are missing. Is there a way to get that data with an additional parameter or another function? Please advice

kipe commented 1 month ago
'blockPriceAggregates': [{'averagePricePerArea': {'FI': {'average': 41.41,
                                                          'max': 129.35,
                                                          'min': 12.04}},
                           'blockName': 'Off-peak 1',
                           'deliveryEnd': '2024-10-15T06:00:00Z',
                           'deliveryStart': '2024-10-14T22:00:00Z'},
                          {'averagePricePerArea': {'FI': {'average': 50.37,
                                                          'max': 122.86,
                                                          'min': 27.24}},
                           'blockName': 'Peak',
                           'deliveryEnd': '2024-10-15T18:00:00Z',
                           'deliveryStart': '2024-10-15T06:00:00Z'},
                          {'averagePricePerArea': {'FI': {'average': 16.13,
                                                          'max': 20.24,
                                                          'min': 10.16}},
                           'blockName': 'Off-peak 2',
                           'deliveryEnd': '2024-10-15T22:00:00Z',
                           'deliveryStart': '2024-10-15T18:00:00Z'}],

These seem to be available in the API, but what's the actual use-case? I haven't found one and especially the min, max and average are so easy to calculate that I'd rather leave them out for the library user to calculate if needed.

I've been thinking about re-structuring the output to be more simple anyways, that's why I'm thinking these additions quite critically.

My current idea is that the output would drop to something like the following, as I've never found any use for the other stuff. I'd rather calculate the required values my self from a more simple format as needed, for example when calculating the total electricity cost.

{
  "currency": "EUR",
  "updated": "2024-10-14T12:07:23Z",
  "areas": {
    "FI": [
      {"time": "2024-10-14T22:00:00Z", "value": 45.13},
      {"time": "2024-10-14T23:00:00Z", "value": 27.31},
      {"time": "2024-10-15T00:00:00Z", "value": 25.68},
      {"time": "2024-10-15T01:00:00Z", "value": 16.71},
      {"time": "2024-10-15T02:00:00Z", "value": 12.04},
      {"time": "2024-10-15T03:00:00Z", "value": 26.56}
    ]
  }
}
MacValley commented 1 month ago

kipe, you are absolutely right! No need to extract extra data that can be calculated if needed. I used AVERAGE in a presentation more like a convenience since the number was there already. I fully respect your decision to abandon those extra numbers. In other words: This "issue" is really not an issue, shall we call it change n design? So feel free to close! Keep up the good work!

kipe commented 1 month ago

Yeah, I'd rather keep the response more simple and if more complex data is required, the user can always calculate it.

I found the documentation for calculating Off-Peak 1, Off-Peak 2 and Peak, leaving it here for future reference in case someone needs them: image

source: https://www.energiforetagen.se/globalassets/energiforetagen/det-erbjuder-vi/kurser-och-konferenser/krisutbildningar/nord-pool-spot-glossary.pdf

For example those times don't correspond to the day/night grid tariff commonly used in Finland, which is typically from 22:00-06:59 -> those values are more or less useless depending on the country.

MacValley commented 1 month ago

I experimented a bit in Jupyter with the code, and ended up with this code: ... import pandas as pd ...

... I have my json data in the variable jsnordpool, then...

se4_start = jsnordpool['start'] se4_updated = jsnordpool['updated'] se4_currency = jsnordpool['currency'] se4_values = jsnordpool['areas']['SE4']['values']

Now, to calculate those extra data, you just need to add these 4 lines of code, putting the data in Pandas Dataframes.

df_all = pd.DataFrame(se4_values) df_offpeak1 = pd.DataFrame(se4_values[:8]) df_peak = pd.DataFrame(se4_values[8:20]) df_offpeak2 = pd.DataFrame(se4_values[20:]) ...

Then I have the extra data if I need to do some stuff with it: MIN is df_all['value'].min() MAX is df_all['value'].max() AVERAGE is df_all['value'].mean() PEAK is df_peak['value'].mean() OFFPEAK1 is df_offpeak1['value'].mean() OFFPEAK2 is df_offpeak2['value'].mean()

I checked with the values from Nordpool's web site, and the values were the same. So once again, the decision to NOT calculate the extra data in the base code is absolutely correct.