-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadshift_location.py
More file actions
78 lines (72 loc) · 2.39 KB
/
loadshift_location.py
File metadata and controls
78 lines (72 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from .loadshift_time import predict_optimal_time
from datetime import datetime
from ..data import energy
from ..utilities.message import CodegreenDataError
def predict_optimal_location_now(
country_list: list,
estimated_runtime_hours: int,
estimated_runtime_minutes: int,
percent_renewable: int,
hard_finish_date: datetime,
) -> tuple:
# Given a list of countries, returns the best location where a computation can be run based on the input criteria
# first get data
start_time = datetime.now()
forecast_data = (
{}
) # will contain energy data for each country for which data is available
for country in country_list:
try:
print(country)
energy_data = energy(country, start_time, hard_finish_date, "forecast")
forecast_data[country] = energy_data["data"]
except CodegreenDataError as c:
print(c)
# print(forecast_data)
return predict_optimal_location(
forecast_data,
estimated_runtime_hours,
estimated_runtime_minutes,
percent_renewable,
hard_finish_date,
)
def predict_optimal_location(
forecast_data,
estimated_runtime_hours,
estimated_runtime_minutes,
percent_renewable,
hard_finish_date,
request_date=None,
):
#Determines the optimal location and time to run a computation using energy data of the selected locations
## obtain the optimal start time for each country
best_values = {}
current_best = -1
best_country = "UTOPIA"
for country in forecast_data:
print(country)
optimal_start, message, avg_percentage_renewable = predict_optimal_time(
forecast_data[country],
estimated_runtime_hours,
estimated_runtime_minutes,
percent_renewable,
hard_finish_date,
request_date,
)
best = {
"optimal_start": optimal_start,
"message": message,
"avg_percentage_renewable": avg_percentage_renewable,
}
print(best)
if avg_percentage_renewable > current_best:
best_country = country
best_values = best
current_best = avg_percentage_renewable
print("Update")
return (
best_values["optimal_start"],
best_values["message"],
best_values["avg_percentage_renewable"],
best_country,
)