Skip to content

Commit 886681d

Browse files
committed
new version
1 parent b3031aa commit 886681d

5 files changed

Lines changed: 3056 additions & 105 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# codegreen python client :seedling:
2-
This repository contains the source code for the codegreen python client. For more information on the usage and background of this tool please go to our documentation on Readthedocs and the website [https://codegreen.world](https://codegreen.world). Please note that in order to use this webservice, you will need to generate an API key on the website.
2+
This repository contains the source code for the codegreen python client. For more information on the usage and background of this tool please go to our documentation on Readthedocs and the website [https://codegreen.world](https://codegreen.world). Please note that in order to use this web service, you will need to generate an API key on the website.
33

44
> **Warning**
55
> We are extremely happy that you consider using our tool. We are still actively developing the functionalities. If there are problems, please file and issue or contact us directly. Stay green! :seedling:
66
7-
##
87
## Functionalities
98
This package is designed to make timeshifting computations easy. They main functionalities are
109
1. Providing python decorators to timeshift, monitor and report the carbon footprint of computation. The functionalities can of course also be used indvidually.

codegreen/queries.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import requests
2-
from datetime import datetime
3-
import pandas as pd
4-
import requests
5-
from datetime import datetime
62
import pandas as pd
3+
from datetime import datetime , timedelta
74
from urllib.parse import urljoin
85

96
from codegreen.config import get_api_endpoint, get_api_key
@@ -13,25 +10,18 @@
1310

1411

1512
def get_prediction(estimated_runtime_hours:int = 1,
16-
estimated_run_time_in_minutes:int=12,
17-
percent_renewable:int=40,
18-
hard_finish_time:datetime.timestamp = datetime.utcnow().replace(hour=18, minute=0, second=0).timestamp(),
19-
area_code:list[str] = ['DE'],
13+
estimated_run_time_in_minutes:int=0,
14+
hard_finish_time:datetime.timestamp = datetime.now() + timedelta(hours=24),
2015
log_request:bool = True,
2116
process_id:str = None,
2217
experiment_name:str = None) -> requests.Response:
2318
"""Get a prediction for an optimal time given the specified parameters.
24-
2519
:param estimated_runtime_hours: Estimated run time in hours, defaults to 1
2620
:type estimated_runtime_hours: int, optional
2721
:param estimated_run_time_in_minutes: Estimated additional minutes of runtime, defaults to 12
2822
:type estimated_run_time_in_minutes: int, optional
29-
:param percent_renewable: Required percentage of renewable energy available in the grid at the time of computation, defaults to 40
30-
:type percent_renewable: int, optional
31-
:param hard_finish_time: deadline for when the computation needs to be finished, defaults to datetime.utcnow().replace(hour=18, minute=0, second=0).timestamp()
23+
:param hard_finish_time: deadline for when the computation needs to be finished, defaults to 24 hours from the current time
3224
:type hard_finish_time: datetime.timestamp, optional
33-
:param area_code: list of area codes with a two letter country code and an optional postal code separated by a dash. Postal codes can be given as 1-5 digit areas. ['CC-PPPPP', 'CC', 'CC-P'], defaults to ['DE']
34-
:type area_code: list[str], optional
3525
:param log_request: allow logging the request server side, this is required to compute the carbon offset, defaults to True
3626
:type log_request: bool, optional
3727
:param process_id: An string to identify the experiment, defaults to None
@@ -44,17 +34,13 @@ def get_prediction(estimated_runtime_hours:int = 1,
4434
"""
4535
payload = {'estimated_runtime_hours': estimated_runtime_hours,
4636
'estimated_runtime_minutes': estimated_run_time_in_minutes,
47-
'percent_renewable': percent_renewable,
48-
'hard_finish_time': hard_finish_time,
49-
'area_code' : area_code,
37+
'hard_finish_time': int(hard_finish_time.timestamp()),
5038
'log_request' : log_request,
5139
'process_id': process_id}
52-
5340
API_URL = get_api_endpoint(experiment_name)
5441
API_KEY = get_api_key(experiment_name)
55-
AUTHORIZATION_HEADER = {'Authorization': API_KEY}
42+
AUTHORIZATION_HEADER = {'Authorization': "Bearer "+API_KEY}
5643
r = requests.post(urljoin(API_URL, 'forecast/timeshift'), json=payload, headers=AUTHORIZATION_HEADER)
57-
print(r.headers)
5844
if r.status_code == 200:
5945
return r
6046
if r.status_code == 401:

0 commit comments

Comments
 (0)