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

WattTime Model Implementation #130

Merged
merged 9 commits into from
Sep 13, 2023
Merged

WattTime Model Implementation #130

merged 9 commits into from
Sep 13, 2023

Conversation

gnanakeethan
Copy link
Contributor

@gnanakeethan gnanakeethan commented Sep 8, 2023

Types of changes

  • Enhancement (project structure, spelling, grammar, formatting)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

A description of the changes proposed in the Pull Request

Implementation of WattTime Model for calculating the energy intensity in gCO2e/KWh.

Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
@gnanakeethan gnanakeethan linked an issue Sep 8, 2023 that may be closed by this pull request
3 tasks
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
@gnanakeethan gnanakeethan marked this pull request as ready for review September 8, 2023 00:56
@gnanakeethan gnanakeethan self-assigned this Sep 8, 2023
@gnanakeethan gnanakeethan changed the title WatTime Model Implementation WattTime Model Implementation Sep 8, 2023
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
@gnanakeethan gnanakeethan merged commit ec96e7f into dev Sep 13, 2023
@gnanakeethan gnanakeethan deleted the wattime-model branch September 13, 2023 06:11
Copy link
Contributor

@jawache jawache left a comment

Choose a reason for hiding this comment

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

@gnanakeethan

  • Very light on documentation. I've given the same feedback on lack of documentation many times before, it's not going to change. Please can you assume that for every issue ongoing that documentation is going to be a strong requirement. Both the readme and the functions, this one has one on authentication which we've never used before and has some specific functionality with respect to auth and none of it is documented as far as I can see.
  • Also the original issue had requirements on how to use the WattTime API so we don't break it's rate limits. We need to think much more carefully about this approach, please re-read the original issue and my comments in this PR.

name: string | undefined;
baseUrl = 'https://api2.watttime.org/v2';

async authenticate(authParams: object): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

It how this auth work documented anywhere @gnanakeethan? Looks like you have to specificy the end var where the username and password is stored, is that right.

Please document this fully both in the comments and in the readme.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added in documentation.

if (!Array.isArray(observations)) {
throw new Error('observations should be an array');
}
observations = await Promise.all(
Copy link
Contributor

Choose a reason for hiding this comment

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

@gnanakeethan please not this way, as mentioned in the issue #125

This is the requirement:

"You will need to pass in the start time for the first observation and the start time for the last observation.
It seems to return all the data in 5 min increments, need to figure out how to map this to your series of observations which might not on the same 5 min time series. Investigate and propose an idea to the team for us to discuss before you implement."

The WattTime API has rate limits so we want to call the API as little as possible. From the docs you can call it once with a large time range and it returns an array of results for smaller intervals. So figure out the total time range for the whole series of observations, call the API for that time range and then try to figure out from the responses how to allocate to the individual observations.

The way you are proposing to use here will break their API limits very quickly. Please investigate and propose an alternative route as described in the issue if what I propose doesn't work but the current approach is not approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jawache that might require extensive processing before/after we obtain the data from Watt-Time API.

I would suggest we create an intermediary mechanism which groups the data to 5 min intervals / larger intervals before we use the watt-time model.

Also we need to consider about the arbitrary durations this model has to execute.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please expand on this with:

  • An impl with several observations, makes one WattTime API call and each observation has it's own grid-ci.
  • What happens when their is an authentication error.
  • What happens when the Wattime API returns error codes (like API rate limited?)
  • Add documentation so we can understand what your testing without reading the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jawache I am not testing the response from the API in the unit-test scenario. I am mocking the response.

I will run it via the RIMPL locally to test this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added some custom errors to be thrown when there is no data.

})
);

return Promise.resolve(observations);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return Promise.resolve(observations);
return observations;

The function is async so anything returned is treated as a resolve and anything that you throw is treated as a reject.

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.

Model Plugin - watttime
3 participants