-
Notifications
You must be signed in to change notification settings - Fork 30
/
utils.py
91 lines (82 loc) · 3.04 KB
/
utils.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
from flexmeasures import Sensor
def make_sensor_data_request_for_gas_sensor(
num_values: int = 6,
duration: str = "PT1H",
unit: str = "m³",
include_a_null: bool = False,
) -> dict:
"""Creates request to post sensor data for a gas sensor.
This particular gas sensor measures units of m³/h with a 10-minute resolution.
"""
sensor = Sensor.query.filter(Sensor.name == "some gas sensor").one_or_none()
values = num_values * [-11.28]
if include_a_null:
values[0] = None
message: dict = {
"type": "PostSensorDataRequest",
"sensor": f"ea1.2021-01.io.flexmeasures:fm1.{sensor.id}",
"values": values,
"start": "2021-06-07T00:00:00+02:00",
"duration": duration,
"horizon": "PT0H",
"unit": unit,
}
if num_values == 1:
# flatten [<float>] to <float>
message["values"] = message["values"][0]
return message
def get_asset_post_data(account_id: int = 1, asset_type_id: int = 1) -> dict:
post_data = {
"name": "Test battery 2",
"latitude": 30.1,
"longitude": 100.42,
"generic_asset_type_id": asset_type_id,
"account_id": account_id,
}
return post_data
def get_sensor_post_data(generic_asset_id: int = 2) -> dict:
post_data = {
"name": "power",
"event_resolution": "PT1H",
"unit": "kWh",
"generic_asset_id": generic_asset_id,
}
return post_data
def message_for_trigger_schedule(
unknown_prices: bool = False,
with_targets: bool = False,
realistic_targets: bool = True,
too_far_into_the_future_targets: bool = False,
) -> dict:
message = {
"start": "2015-01-01T00:00:00+01:00",
"duration": "PT24H", # Will be extended in case of targets that would otherwise lie beyond the schedule's end
}
if unknown_prices:
message[
"start"
] = "2040-01-01T00:00:00+01:00" # We have no beliefs in our test database about 2040 prices
message["flex-model"] = {
"soc-at-start": 12.1, # in kWh, according to soc-unit
"soc-min": 0, # in kWh, according to soc-unit
"soc-max": 40, # in kWh, according to soc-unit
"soc-unit": "kWh",
"roundtrip-efficiency": "98%",
"storage-efficiency": "99.99%",
}
if with_targets:
if realistic_targets:
# this target (in kWh, according to soc-unit) is well below the soc_max_in_mwh on the battery's sensor attributes
target_value = 25
else:
# this target (in kWh, according to soc-unit) is actually higher than soc_max_in_mwh on the battery's sensor attributes
target_value = 25000
if too_far_into_the_future_targets:
# this target exceeds FlexMeasures' default max planning horizon
target_datetime = "2015-02-02T23:00:00+01:00"
else:
target_datetime = "2015-01-02T23:00:00+01:00"
message["flex-model"]["soc-targets"] = [
{"value": target_value, "datetime": target_datetime}
]
return message