From 6071a1ccc246efa7555d420c0b3271d5ef757a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=A0trauch?= Date: Thu, 2 Oct 2025 17:48:31 +0200 Subject: [PATCH] Switch to 15 mins intervals --- calculator/calc.py | 30 +++-- calculator/index.html | 277 ++++++++++++++++++++++++++---------------- calculator/main.py | 34 ++++-- calculator/miner.py | 53 ++++++-- calculator/schema.py | 2 +- 5 files changed, 265 insertions(+), 131 deletions(-) diff --git a/calculator/calc.py b/calculator/calc.py index 73f835d..7718ec0 100644 --- a/calculator/calc.py +++ b/calculator/calc.py @@ -8,7 +8,7 @@ from calculator.miner import PriceNotFound, get_energy_prices, get_eur_czk_ratio from calculator.schema import BatteryChargingInfo, Price, SpotPrices -def get_spot_prices(date: datetime.date, hour:int, kwh_fees_low:float, kwh_fees_high:float, sell_fees:float, VAT:float, low_tariff_hours:List[int], no_cache: bool = False) -> SpotPrices: +def get_spot_prices(date: datetime.date, hour:str, kwh_fees_low:float, kwh_fees_high:float, sell_fees:float, VAT:float, low_tariff_hours:List[int], no_cache: bool = False) -> SpotPrices: is_today = datetime.date.today() == date spot_hours = {} @@ -19,21 +19,21 @@ def get_spot_prices(date: datetime.date, hour:int, kwh_fees_low:float, kwh_fees_ currency_ratio = get_eur_czk_ratio(date, no_cache=no_cache) for key, value in spot_data.items(): - kwh_fees = kwh_fees_low if int(key) in low_tariff_hours else kwh_fees_high + kwh_fees = kwh_fees_low if key in low_tariff_hours else kwh_fees_high spot_hours[key] = value * currency_ratio / 1000 spot_hours_total[key] = (value * currency_ratio / 1000 + kwh_fees) * VAT spot_hours_for_sell[key] = value * currency_ratio / 1000 - sell_fees - spot = Price(hours=spot_hours, now=spot_hours[str(hour)] if is_today else None) + spot = Price(hours=spot_hours, now=spot_hours[hour] if is_today else None) spot_hours_total_sorted = {k: v for k, v in sorted(spot_hours_total.items(), key=lambda item: item[1])} - spot_total = Price(hours=spot_hours_total_sorted, now=spot_hours_total[str(hour)] if is_today else None) - spot_for_sell = Price(hours=spot_hours_for_sell, now=spot_hours_for_sell[str(hour)] if is_today else None) + spot_total = Price(hours=spot_hours_total_sorted, now=spot_hours_total[hour] if is_today else None) + spot_for_sell = Price(hours=spot_hours_for_sell, now=spot_hours_for_sell[hour] if is_today else None) return SpotPrices( spot=spot, - spot_hours_total_sorted=Price(hours=spot_hours_total_sorted, now=spot_hours_total[str(hour)] if is_today else None), + spot_hours_total_sorted=Price(hours=spot_hours_total_sorted, now=spot_hours_total[hour] if is_today else None), spot_total=spot_total, spot_for_sell=spot_for_sell, ) @@ -48,14 +48,13 @@ def battery_charging_info(kwh_fees_low:float, kwh_fees_high:float, sell_fees:flo # average4hours = sum(list(spot_prices_today.spot_hours_total_sorted.hours.values())[0:4]) / 4 max_cheapest_hour = max(list(spot_prices_today.spot_hours_total_sorted.hours.values())[0:4]) - average4expensive_hours = sum(list(spot_prices_today.spot_hours_total_sorted.hours.values())[20:24]) / 4 max_most_expensive_hour = max( [x[1] for x in list(spot_prices_today.spot_hours_total_sorted.hours.items())[0:20]] ) if spot_prices_today.spot_hours_total_sorted.hours else 0 diff = max_most_expensive_hour - max_cheapest_hour - charging_hours = [int(k) for k, v in spot_prices_today.spot_hours_total_sorted.hours.items()][0:4] - discharging_hours = [int(k) for k, v in spot_prices_today.spot_hours_total_sorted.hours.items() if v > (max_cheapest_hour + battery_kwh_price)] + charging_hours = [k for k, v in spot_prices_today.spot_hours_total_sorted.hours.items()][0:4] + discharging_hours = [k for k, v in spot_prices_today.spot_hours_total_sorted.hours.items() if v > (max_cheapest_hour + battery_kwh_price)] # Add charging hours if the price is just 10% above the most expensive charging hour if charging_hours: @@ -87,3 +86,16 @@ def battery_charging_info(kwh_fees_low:float, kwh_fees_high:float, sell_fees:flo is_discharging_hour=hour in discharging_hours if len(discharging_hours) > 0 and is_viable else False, total_price=spot_prices_today.spot_hours_total_sorted ) + + +def minutes_to_15mins(mins:int|str) -> str: + mins = int(mins) + + if mins < 15: + return "00" + elif mins < 30: + return "15" + elif mins < 45: + return "30" + else: + return "45" diff --git a/calculator/index.html b/calculator/index.html index 8811ead..648b1dc 100644 --- a/calculator/index.html +++ b/calculator/index.html @@ -7,31 +7,31 @@