jnioche / carbonintensity-api

A simple Rust library to retrieve data from https://api.carbonintensity.org.uk/
Apache License 2.0
10 stars 1 forks source link

Document API weirdness with regards to multi-years ranges #24

Closed xoen closed 1 month ago

xoen commented 1 month ago

I added an explicit test with a bit more context to explain why the normalise_ranges() is checking for the end of the year (or at least my understanding of it).

The problem

Example:

$ curl "https://api.carbonintensity.org.uk/regional/intensity/2022-12-31T00:01Z/2023-01-01T05:00Z/regionid/13" | jq '.data.data[].from'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17235  100 17235    0     0  71119      0 --:--:-- --:--:-- --:--:-- 71219
"2022-12-31T00:00Z"
"2022-12-31T00:30Z"
[...]
"2022-12-31T22:30Z"
"2022-12-31T23:00Z"

What happened to the values for the 1st January?

This is why currently the logic checks if a range is spanning multiple years, e.g. 2023-12-30..2024-01-10, and it splits it into 2 ranges, e.g. 2023-12-30..2024-01-01 and 2024-01-01..2024-01-10.