mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 08:55:15 +00:00
comments, cleanup
This commit is contained in:
parent
b16a545379
commit
df54303284
@ -6,7 +6,7 @@ humidity, cloud cover, and solar irradiance. The data is mapped to the `ElecPric
|
|||||||
format, enabling consistent access to forecasted and historical electricity price attributes.
|
format, enabling consistent access to forecasted and historical electricity price attributes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Any, List, Optional, Union, Tuple
|
from typing import Any, List, Optional, Tuple, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import requests
|
import requests
|
||||||
@ -98,6 +98,10 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If the API response does not include expected `electricity price` data.
|
ValueError: If the API response does not include expected `electricity price` data.
|
||||||
|
|
||||||
|
Todo:
|
||||||
|
- maybe some data cleanup/checking. we might have a problem if a single day has none values or is missing at all in the api or the data.
|
||||||
|
- add the file cache again.
|
||||||
"""
|
"""
|
||||||
source = "https://api.akkudoktor.net"
|
source = "https://api.akkudoktor.net"
|
||||||
assert self.start_datetime # mypy fix
|
assert self.start_datetime # mypy fix
|
||||||
@ -137,7 +141,7 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
|
|||||||
|
|
||||||
def _update_data(
|
def _update_data(
|
||||||
self, force_update: Optional[bool] = False
|
self, force_update: Optional[bool] = False
|
||||||
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
|
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]: # TODO: remove return, only for debug
|
||||||
"""Update forecast data in the ElecPriceDataRecord format.
|
"""Update forecast data in the ElecPriceDataRecord format.
|
||||||
|
|
||||||
Retrieves data from Akkudoktor, maps each Akkudoktor field to the corresponding
|
Retrieves data from Akkudoktor, maps each Akkudoktor field to the corresponding
|
||||||
@ -177,7 +181,7 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
|
|||||||
history = np.array(
|
history = np.array(
|
||||||
[
|
[
|
||||||
record.elecprice_marketprice_wh
|
record.elecprice_marketprice_wh
|
||||||
for record in self.records
|
for record in sorted(self.records, key=lambda r: r.date_time)
|
||||||
if record.elecprice_marketprice_wh is not None
|
if record.elecprice_marketprice_wh is not None
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -186,9 +190,13 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
|
|||||||
assert highest_orig_datetime # mypy fix
|
assert highest_orig_datetime # mypy fix
|
||||||
# Insert prediction into ElecPriceDataRecord
|
# Insert prediction into ElecPriceDataRecord
|
||||||
if amount_datasets > 800:
|
if amount_datasets > 800:
|
||||||
prediction = self._predict_ets(history, seasonal_periods=168, prediction_hours=7 * 24)
|
prediction = self._predict_ets(
|
||||||
|
history, seasonal_periods=168, prediction_hours=7 * 24
|
||||||
|
) # todo: add config values for prediction_hours
|
||||||
elif amount_datasets > 168:
|
elif amount_datasets > 168:
|
||||||
prediction = self._predict_ets(history, seasonal_periods=24, prediction_hours=7 * 24)
|
prediction = self._predict_ets(
|
||||||
|
history, seasonal_periods=24, prediction_hours=7 * 24
|
||||||
|
) # todo: add config values for prediction_hours
|
||||||
elif amount_datasets > 0:
|
elif amount_datasets > 0:
|
||||||
prediction = self._predict_median(history, prediction_hours=7 * 24)
|
prediction = self._predict_median(history, prediction_hours=7 * 24)
|
||||||
else:
|
else:
|
||||||
@ -200,48 +208,40 @@ class ElecPriceAkkudoktor(ElecPriceProvider):
|
|||||||
# Update existing record
|
# Update existing record
|
||||||
existing_record.elecprice_marketprice_wh = price
|
existing_record.elecprice_marketprice_wh = price
|
||||||
else:
|
else:
|
||||||
assert pred_datetime # mypy fix
|
assert pred_datetime # mypy fix, why do we need that we already made sure highest_orig_datetime is not None
|
||||||
self.insert(
|
self.insert(
|
||||||
0,
|
0,
|
||||||
ElecPriceDataRecord(date_time=pred_datetime, elecprice_marketprice_wh=price),
|
ElecPriceDataRecord(date_time=pred_datetime, elecprice_marketprice_wh=price),
|
||||||
)
|
)
|
||||||
history2 = np.array(
|
history2 = np.array( # TODO: remove return, only for debug, offset to see the difference
|
||||||
[
|
[
|
||||||
[record.elecprice_marketprice_wh, record.date_time]
|
record.elecprice_marketprice_wh + 0.0002
|
||||||
for record in self.records
|
for record in sorted(self.records, key=lambda r: r.date_time)
|
||||||
if record.elecprice_marketprice_wh is not None
|
if record.elecprice_marketprice_wh is not None
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return history, prediction
|
|
||||||
# print(len(history2), len(history))
|
|
||||||
|
|
||||||
# now we count how many data points we have.
|
return history, history2, prediction # TODO: remove return, only for debug
|
||||||
# if its > 800 (5 weeks) we will use EST
|
|
||||||
# elif > idk maybe 168 (1 week) we use EST without season
|
|
||||||
# elif < 168 we use a simple median
|
|
||||||
# #elif == 0 we need some static value from the config
|
|
||||||
|
|
||||||
# depending on the result we check prediction_hours and predict that many hours.
|
|
||||||
|
|
||||||
# we get the result and iterate over it to put it into ElecPriceDataRecord
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
elec_price_akkudoktor = ElecPriceAkkudoktor()
|
elec_price_akkudoktor = ElecPriceAkkudoktor()
|
||||||
history, predictions = elec_price_akkudoktor._update_data()
|
history, history2, predictions = elec_price_akkudoktor._update_data()
|
||||||
|
|
||||||
visualize_predictions(history, predictions)
|
visualize_predictions(history, history2, predictions)
|
||||||
print(history, predictions)
|
# print(history, history2, predictions)
|
||||||
|
|
||||||
|
|
||||||
def visualize_predictions(
|
def visualize_predictions(
|
||||||
history: List[float],
|
history: np.ndarray[Any, Any],
|
||||||
predictions: List[float],
|
history2: np.ndarray[Any, Any],
|
||||||
|
predictions: np.ndarray[Any, Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
plt.figure(figsize=(28, 14))
|
plt.figure(figsize=(28, 14))
|
||||||
plt.plot(range(len(history)), history, label="History", color="green")
|
plt.plot(range(len(history)), history, label="History", color="green")
|
||||||
|
plt.plot(range(len(history2)), history2, label="History_new", color="blue")
|
||||||
plt.plot(
|
plt.plot(
|
||||||
range(len(history), len(history) + len(predictions)),
|
range(len(history), len(history) + len(predictions)),
|
||||||
predictions,
|
predictions,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user