Skip to content

Commit

Permalink
Adding documentation and detailing and more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
  • Loading branch information
gnanakeethan committed Sep 14, 2023
1 parent 534197e commit 356d872
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 102 deletions.
34 changes: 21 additions & 13 deletions docs/implementations/watt-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ WattTime technology—based on real-time grid data, cutting-edge algorithms, and
WattTime Model provides a way to calculate emissions for a given time in a specific location.

The model is based on the WattTime API. The model uses the following inputs:
* location: Location of the software system ({latitude:0.0, longitude:0.0})
* latitude: Location of the software system (latitude in decimal degrees).
* longitude: Location of the software system (longitude in decimal degrees).
* timestamp: Timestamp of the recorded event (2021-01-01T00:00:00Z) RFC3339
* duration: Duration of the recorded event in seconds (3600)

Expand All @@ -22,13 +23,17 @@ Limitations:
* Emissions are aggregated for every 5 minutes regardless of the granularity of the observations.

### Authentication


WattTime API requires activation of subscription before usage. Please refer to WattTime website for more information.

**Required Parameters:**

* username: Username for the WattTime API
* password: Password for the WattTime API



### Typescript Usage
```typescript
// environment variable configuration
// export WATT_TIME_USERNAME=test1
Expand All @@ -38,8 +43,18 @@ const env_model = await new WattTimeGridEmissions().configure('watt-time', {
username: process.env.WATT_TIME_USERNAME,
password: process.env.WATT_TIME_PASSWORD,
});
const observations = [
{
timestamp: '2021-01-01T00:00:00Z',
latitude: 43.22,
longitude: -80.22,
duration: 3600,
},
];
const results = env_model.calculateEmissions(observations);
```

### IMPL Usage
#### Environment Variable based configuration for IMPL
```yaml
# environment variable config , prefix the environment variables with "ENV" to load them inside the model.
Expand All @@ -50,9 +65,8 @@ config:
password: ENV_WATT_TIME_PASSWORD
observations:
- timestamp: 2021-01-01T00:00:00Z
location:
latitude: 43.22
longitude: -80.22
latitude: 43.22
longitude: -80.22
duration: 3600
```
#### Static configuration for IMPL
Expand All @@ -62,13 +76,7 @@ config:
password: password
observations:
- timestamp: 2021-01-01T00:00:00Z
location:
latitude: 43.22
longitude: -80.22
latitude: 43.22
longitude: -80.22
duration: 3600
```
### Calculations
82 changes: 66 additions & 16 deletions src/lib/watt-time/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ mockAxios.get.mockImplementation(url => {
switch (url) {
case 'https://api2.watttime.org/v2/login':
return Promise.resolve({
status: 200,
data: {
token: 'test_token',
},
});
case 'https://api2.watttime.org/v2/data':
return Promise.resolve({data: DATA});
return Promise.resolve({
data: DATA,
status: 200,
});
}
});
describe('watt-time:configure test', () => {
Expand All @@ -32,41 +36,87 @@ describe('watt-time:configure test', () => {
await expect(
model.calculate([
{
location: {
latitude: 37.7749,
longitude: -122.4194,
},
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 1200,
},
])
).resolves.toStrictEqual([
{
location: {
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 1200,
'grid-ci': 2185.332173907599,
},
]);
await expect(
model.calculate([
{
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 120,
},
])
).resolves.toStrictEqual([
{
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 1200,
'grid-ci': 2185.332173907599,
duration: 120,
'grid-ci': 2198.0087539832293,
},
]);
await expect(
model.calculate([
{
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 300,
},
])
).resolves.toStrictEqual([
{
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 300,
'grid-ci': 2198.0087539832293,
},
]);
await expect(
model.calculate([
{
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 360,
},
])
).resolves.toStrictEqual([
{
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 360,
'grid-ci': 2193.5995087395318,
},
]);

await expect(
model.calculate([
{
location: {
latitude: 37.7749,
longitude: -122.4194,
},
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
},
{
location: {
latitude: 37.7749,
longitude: -122.4194,
},
latitude: 37.7749,
longitude: -122.4194,
timestamp: '2021-01-02T01:00:00Z',
duration: 3600,
},
Expand Down
Loading

0 comments on commit 356d872

Please sign in to comment.