diff --git a/cats/__init__.py b/cats/__init__.py index ad1ad04..b0af2ca 100644 --- a/cats/__init__.py +++ b/cats/__init__.py @@ -118,7 +118,7 @@ def main(arguments=None): # Find best possible average carbon intensity, along # with corresponding job start time. now_avg, best_avg = get_avg_estimates( - CI_forecast, method="windowed", duration=duration + CI_forecast, duration=duration ) sys.stderr.write(str(best_avg) + "\n") diff --git a/cats/optimise_starttime.py b/cats/optimise_starttime.py index 67aebee..6fe1155 100644 --- a/cats/optimise_starttime.py +++ b/cats/optimise_starttime.py @@ -2,7 +2,7 @@ from .forecast import WindowedForecast -def get_avg_estimates(data, method="simple", duration=None): +def get_avg_estimates(data, duration=None): """ Get lowest carbon intensity in data depending on user method return dict of timestamp and carbon intensity @@ -17,22 +17,12 @@ def get_avg_estimates(data, method="simple", duration=None): # "Windowed method timespan cannot be greater than the cached timespan" # ) - METHODS = ["simple", "windowed"] - if method not in METHODS: - raise ValueError(f"Invalid Carbon Intensity Method. Must be one of {METHODS}") - - if method == "simple": - # Return element with smallest 2nd value - # if multiple elements have the same value, return the first - return min(data) - - if method == "windowed": - # get length of interval between timestamps - interval = ( - data[1].datetime - data[0].datetime - ).total_seconds() / 60 - wf = WindowedForecast( - data=data, - window_size=ceil(duration / interval) - ) - return wf[0], min(wf) + # get length of interval between timestamps + interval = ( + data[1].datetime - data[0].datetime + ).total_seconds() / 60 + wf = WindowedForecast( + data=data, + window_size=ceil(duration / interval) + ) + return wf[0], min(wf) diff --git a/tests/test_timeseries_conversion.py b/tests/test_timeseries_conversion.py deleted file mode 100644 index 2c87491..0000000 --- a/tests/test_timeseries_conversion.py +++ /dev/null @@ -1,33 +0,0 @@ -from pathlib import Path -from datetime import datetime -import csv - -from cats.optimise_starttime import get_avg_estimates -from cats.forecast import CarbonIntensityPointEstimate - - -TEST_DATA = Path(__file__).parent / "carbon_intensity_24h.csv" - - -def test_stub(): - pass - - -def test_timeseries_conversion(): - with open(TEST_DATA, "r") as f: - csvfile = csv.reader(f, delimiter=",") - next(csvfile) # Skip header line - forecast_data = [ - CarbonIntensityPointEstimate( - datetime=datetime.fromisoformat(datestr[:-1]), - value=float(intensity_value), - ) - for datestr, _, _, intensity_value in csvfile - ] - result = get_avg_estimates( - forecast_data, method="simple", duration=None - ) - assert result == CarbonIntensityPointEstimate( - datetime=datetime(2023, 5, 5, 14, 0), - value=5.0, - )