Skip to content

Commit

Permalink
Merge branch 'main' into adjust_integration_window
Browse files Browse the repository at this point in the history
  • Loading branch information
tlestang committed Aug 1, 2023
2 parents db76c19 + 0b574d4 commit 50319ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
19 changes: 5 additions & 14 deletions cats/forecast.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
from dataclasses import dataclass, field
from dataclasses import dataclass
from datetime import datetime, timedelta


@dataclass(order=True)
class CarbonIntensityPointEstimate:
"""Represents a single data point within an intensity
timeseries. Use order=True in order to enable comparison of class
instance based on the sort_index attribute. See
instance based on the first attribute. See
https://peps.python.org/pep-0557
"""
sort_index: float = field(init=False, repr=False)
value: float # the first attribute is used automatically for sorting methods
datetime: datetime
value: float

def __post_init__(self):
self.sort_index = self.value


@dataclass(order=True)
class CarbonIntensityAverageEstimate:
"""Represents a single data point within an *integrated* carbon
intensity timeseries. Use order=True in order to enable comparison
of class instance based on the sort_index attribute. See
of class instance based on the first attribute. See
https://peps.python.org/pep-0557
"""
sort_index: float = field(init=False, repr=False)
value: float
start: datetime # Start of the time-integration window
end: datetime # End of the time-integration window
value: float

def __post_init__(self):
self.sort_index = self.value


class WindowedForecast:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_windowed_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def test_average_intensity_with_offset():
# intensity value at beginning and end of each potential job
# duration window.
CI_forecast = [
CarbonIntensityPointEstimate(datetime(2023,1,1,8,30), value=26),
CarbonIntensityPointEstimate(datetime(2023,1,1,9,0), value=40),
CarbonIntensityPointEstimate(datetime(2023,1,1,9,30), value=50),
CarbonIntensityPointEstimate(datetime(2023,1,1,10,0), value=60),
CarbonIntensityPointEstimate(datetime(2023,1,1,10,30), value=25),
CarbonIntensityPointEstimate(26, datetime(2023,1,1,8,30)),
CarbonIntensityPointEstimate(40, datetime(2023,1,1,9,0)),
CarbonIntensityPointEstimate(50, datetime(2023,1,1,9,30)),
CarbonIntensityPointEstimate(60, datetime(2023,1,1,10,0)),
CarbonIntensityPointEstimate(25, datetime(2023,1,1,10,30)),
]
duration = 70 # in minutes
# First available data point is for 08:00 but the job
Expand Down

0 comments on commit 50319ee

Please sign in to comment.