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

Make sure we respect local system time #61

Merged
merged 4 commits into from
Aug 11, 2023

Conversation

andreww
Copy link
Collaborator

@andreww andreww commented Aug 10, 2023

This (draft) pull request makes sure we keep track of any differences in timezone between system time (e.g. used for at) and the time zone returned by our datasource. To do this, we need to:

  • Make sure the datetime objects in the CarbonIntensityPointEstimate are timezone aware
  • Set the correct timezone on these objects
  • Make sure the timezone is still set for the calculated start time
  • Convert to the correct system time when we output a start time
  • Make sure our other reported dates and times are correct with respect to timezones

With a little luck, the actual calculation will 'just work'. We should check this.

This addresses #21

This probably needs to be done on an api-interface
by api-interface basis (as how we do it depends on
how we convert whatever comes back into a datetime
object). For the ciuk we have explicit UTC returned
but strptime does not know how to parse this. So
add the timezone info for each datetime object.

Also modify the test to make sure all datetime
objects we get back from the api_query are aware
of their datetime (we don't care what this is,
only that it is defined). We can then convert to
system time at the other end.
Make all test data going into the unit tests for
WindowedForcast have a timezone (specifically
UTC) and add that timezone to the expected output.
The existing assert statments will fail if timezone
data does not match.
As far as I can tell, when using the posix timestamp
to at, it works in local system time (which for me is
BST). So make all our start times and reports from the
optimiser timezone aware and in local system time. It
turns out that all we need to do to do this is feed in
a start time that is timezone aware and in the right
timezone. Doing this shifts the time that gets passed
generated for feeding into at by 1 hr, which is what we
want.

Also add a test case to test_windowed_forecast to make
sure that this all works. Note that we have to explicitly
check the timezones as the same time with different timezones
compare equal.
@andreww
Copy link
Collaborator Author

andreww commented Aug 11, 2023

I think this has everything we need to run correctly on systems where the system time is not UTC but the forecast data is.

@andreww andreww marked this pull request as ready for review August 11, 2023 09:09
Copy link
Collaborator

@tlestang tlestang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andreww ! It's really amazing to see that you can 'specify the start time in whatever timezone and all the comparisons between datetime objects under the hood work as expected.

tests/test_api_query.py Show resolved Hide resolved
cats/optimise_starttime.py Show resolved Hide resolved
tests/test_windowed_forecast.py Show resolved Hide resolved
tests/test_windowed_forecast.py Show resolved Hide resolved
This documents the need for two checks for timezone awarness,
and makes one of the more complex forecast checks cross timezones
between the data and 'system' time.
Copy link
Collaborator

@tlestang tlestang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are tests
and the ticks are green
I think this should go in

@andreww andreww merged commit a829d9f into GreenScheduler:main Aug 11, 2023
@andreww andreww mentioned this pull request Aug 11, 2023
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.

2 participants