-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler.py
146 lines (118 loc) · 4.26 KB
/
scheduler.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
import datetime
from math import ceil
import database
import device
import nordpool_prices
class Scheduler():
def __init__(self) -> None:
pass
def get_all_enabled_devices():
devices = database.get_all_devices()
def find_lowest_price_for_device(device):
pass
def find_start_time_for_power_duration(prices, duration):
window = ceil(duration * 2)
# Double the data to get the 30-minutes resolution
half_hour_prices = []
for data in prices:
half_hour_prices.append(data)
half_hour_prices.append({
'time': data['time'] + datetime.timedelta(minutes=30),
'value': data['value'],
})
print(half_hour_prices)
half_hour_windows = (half_hour_prices[i:i + window] for i in range(len(half_hour_prices) - window + 1))
window_totals = tuple(sum(map(lambda x: x['value'], window_prices)) for window_prices in half_hour_windows)
print(window_totals)
min_price = min(window_totals)
min_price_index = window_totals.index(min_price)
return half_hour_prices[min_price_index]['time']
def find_mean_value(prices):
values = sorted(prices, key=lambda x: x['value'])
vals = [v['value'] for v in values]
print(vals)
diffs = [round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])]
print(diffs)
return values[len(values) // 2]
def find_average_value(prices):
total = sum(v['value'] for v in prices)
return total // len(prices)
def find_flat_periods(prices, variation=0.1):
pass
def get_low_prices(prices):
all_slices = []
average = find_average_value(prices)
slice_started = False
for price in prices:
if price['value'] < average:
if not slice_started:
slice = [price['value']]
slice_started = True
else:
slice.append(price['value'])
else:
if slice_started:
slice_started = False
all_slices.append(slice)
if slice_started:
all_slices.append(slice)
return all_slices
if __name__ == '__main__':
print('now')
prices = nordpool_prices.get_future_prices()
prices = prices[:24]
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))
print('day_before=1')
prices = nordpool_prices.get_past_prices(days_before=1)
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))
print('day_before=2')
prices = nordpool_prices.get_past_prices(days_before=2)
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))
print('day_before=3')
prices = nordpool_prices.get_past_prices(days_before=3)
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))
print('day_before=4')
prices = nordpool_prices.get_past_prices(days_before=4)
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))
print('day_before=5')
prices = nordpool_prices.get_past_prices(days_before=5)
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))
print('day_before=6')
prices = nordpool_prices.get_past_prices(days_before=6)
vals = [p['value'] for p in prices]
print(vals)
print(get_low_prices(prices))
print([round((n-v) / n, 2) for v, n in zip(vals[:-1], vals[1:])])
print(find_mean_value(prices))
print(find_average_value(prices))