Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix off by one #100

Merged
merged 6 commits into from
Jun 9, 2024
Merged

fix off by one #100

merged 6 commits into from
Jun 9, 2024

Conversation

abhidg
Copy link
Contributor

@abhidg abhidg commented May 24, 2024

This fixes off-by-one errors in the code which led to #99. Detailed info is in commit messages.

@andreww
Copy link
Collaborator

andreww commented May 26, 2024

This all looks good to me but I think it would be good to turn the error in #99 into a test case - do we actually need a handful of integration tests where we feed in chosen forcasts and test the whole code?

This fixes issues in the current CATS implementation which led to
#99

Firstly, bisect_left() which finds the index of the closest data point
past the job end time, was looking at the datetime attribute of the
CarbonIntensityPointEstimate object, which by convention only has the
start time of the window for which carbon intensity is reported from
ciuk_parse_response_data(). This led to an error where if the job end
time fell in the last window, bisect_left() would return None as it did
not find a starting datetime past the job end time. This commit fixes
this by looking at the end of the window.

Secondly, this fixes __len__ on WindowedForecast which had a off by one
error on the number of windows. This was triggerred when the number of
windows was the same size as the data which should be valid, but gave an
empty iterable.

Thirdly, fixed a IndexError in rbound estimation that was caused by this
new method. This happened when the job end time fell on the last data
point. Interpolation between this data point and the next one failed, as
there was no succeeding data point. Also corrected off-by-one shifts in
the list of windows for the trapezoidal rule.

Fixes: #99
carbonintensity.org.uk reports carbon intensity for 48h from the current
half hour block in 30min windows. Thus if the API is invoked at 18:59
UTC then the API will return with the starting window at 18:30 UTC. This
can lead to a situation where a job with duration=2865 min (47h 45min)
would place its end time beyond the forecast end by 15min. Thus the
maximum duration for the carbonintensity.org.uk provider is changed to
2850min (48h - 30min)
@GreenScheduler GreenScheduler deleted a comment from codecov bot May 28, 2024
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.21%. Comparing base (ad68095) to head (92d7608).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #100      +/-   ##
==========================================
+ Coverage   89.19%   89.21%   +0.01%     
==========================================
  Files          14       14              
  Lines         546      547       +1     
==========================================
+ Hits          487      488       +1     
  Misses         59       59              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abhidg abhidg merged commit 8853312 into main Jun 9, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors when duration close to 48h
3 participants