Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh of calculation methods #197

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
089f9f2
Refresh of calculation methods
Pluimvee Oct 7, 2024
fd9156b
Some small adjustements
Pluimvee Oct 7, 2024
0d07dcc
Some Todo's added
Pluimvee Oct 8, 2024
c4ca4f2
Merge pull request #1 from Pluimvee/Adding-comments-and-reschuffle-co…
Pluimvee Oct 8, 2024
139449d
Apply the formatting again
Pluimvee Oct 8, 2024
7fce573
renamed some analysis windows
Pluimvee Oct 8, 2024
2873cbe
Merge branch 'main' into Change-Calculation-Modes
Pluimvee Oct 8, 2024
9ceda93
Introducting Analysis Windows
Pluimvee Oct 8, 2024
1d15d7a
Readme updates
Pluimvee Oct 8, 2024
716ea8b
Added analysis window picture
Pluimvee Oct 8, 2024
8d02fc3
Data fetch needs to call refresh_analysis
Pluimvee Oct 8, 2024
30f2374
Merge branch 'Change-Calculation-Modes' of https://github.com/Pluimve…
Pluimvee Oct 8, 2024
5f8a116
As long as we do not have data for tommorrow, we return yesterday and…
Pluimvee Oct 8, 2024
71f47db
Change comment
Pluimvee Oct 8, 2024
2569b33
Code Format
Pluimvee Oct 9, 2024
cdd2a95
Update README.md
Pluimvee Oct 9, 2024
e604e67
Merge pull request #204 from Pluimvee/Adding-comments-and-reschuffle-…
Roeland54 Oct 10, 2024
0df5db6
Refresh of calculation methods
Pluimvee Oct 7, 2024
a204bf5
Some small adjustements
Pluimvee Oct 7, 2024
06fbeae
renamed some analysis windows
Pluimvee Oct 8, 2024
b5cec20
Introducting Analysis Windows
Pluimvee Oct 8, 2024
fd7d178
Readme updates
Pluimvee Oct 8, 2024
abc8554
Data fetch needs to call refresh_analysis
Pluimvee Oct 8, 2024
ccab378
Added analysis window picture
Pluimvee Oct 8, 2024
4162d75
As long as we do not have data for tommorrow, we return yesterday and…
Pluimvee Oct 8, 2024
5d56da6
Change comment
Pluimvee Oct 8, 2024
ad90cf5
Update README.md
Pluimvee Oct 9, 2024
a85173d
Merge branch
Pluimvee Oct 10, 2024
940726a
Some additional code comments
Pluimvee Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions custom_components/entsoe/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

# default is only for internal use / backwards compatibility
CALCULATION_MODE = {
"default": "publish",
"rotation": "rotation",
"sliding": "sliding",
"publish": "publish",
"default": "publish",
"publish": "publish",
"daily": "daily",
"sliding": "sliding",
"sliding-12": "sliding-12", # new half day sliding
"forward": "forward", # 24hrs forward looking
"forward-12": "forward-12", # 12hrs forward looking
}

ENERGY_SCALES = { "kWh": 1000, "MWh": 1 }
Expand Down
50 changes: 34 additions & 16 deletions custom_components/entsoe/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ async def _async_update_data(self) -> dict:
self.data = parsed_data
self.filtered_hourprices = self._filter_calculated_hourprices(parsed_data)
return parsed_data


# fetching of new data is needed when (1) we have no data, (2) when todays data is below 20 hrs or (3) tomorrows data is below 20hrs and its after 11
def check_update_needed(self, now):
if self.data is None:
return True
Expand Down Expand Up @@ -178,6 +179,7 @@ async def get_energy_prices(self, start_date, end_date):
}
return self.parse_hourprices(await self.fetch_prices(start_date, end_date))

# TODO: this method is called by each sensor, each hour. Change the code so only the first will update
Pluimvee marked this conversation as resolved.
Show resolved Hide resolved
def update_data(self):
now = dt.now()
if self.today.date() != now.date():
Expand All @@ -190,27 +192,43 @@ def today_data_available(self):
return len(self.get_data_today()) > MIN_HOURS

def _filter_calculated_hourprices(self, data):
# rotation = calculations made upon 24hrs today
if self.calculation_mode == CALCULATION_MODE["rotation"]:
if self.calculation_mode == CALCULATION_MODE["daily"]:
self.logger.debug(f"Filter dataset for prices today -> refresh each day")
return {
hour: price
for hour, price in data.items()
if hour >= self.today and hour < self.today + timedelta(days=1)
}
# sliding = calculations made on all data from the current hour and beyond (future data only)

elif self.calculation_mode == CALCULATION_MODE["sliding"]:
now = dt.now().replace(minute=0, second=0, microsecond=0)
return {hour: price for hour, price in data.items() if hour >= now}
# publish >48 hrs of data = calculations made on all data of today and tomorrow (48 hrs)
elif self.calculation_mode == CALCULATION_MODE["publish"] and len(data) > 48:
return {hour: price for hour, price in data.items() if hour >= self.today}
# publish <=48 hrs of data = calculations made on all data of yesterday and today (48 hrs)
elif self.calculation_mode == CALCULATION_MODE["publish"]:
return {
hour: price
for hour, price in data.items()
if hour >= self.today - timedelta(days=1)
}
start = dt.now().replace(minute=0, second=0, microsecond=0)
start -= timedelta(hours=12)
end = start + timedelta(hours=24)
self.logger.debug(f"Filter dataset to surrounding 24hrs {start} - {end} -> refresh each hour")
return {hour: price for hour, price in data.items() if start < hour < end }

elif self.calculation_mode == CALCULATION_MODE["sliding-12"]:
start = dt.now().replace(minute=0, second=0, microsecond=0)
start -= timedelta(hours=6)
end = start + timedelta(hours=12)
self.logger.debug(f"Filter dataset to surrounding 12hrs {start} - {end} -> refresh each hour")
return {hour: price for hour, price in data.items() if start < hour < end }

elif self.calculation_mode == CALCULATION_MODE["forward"]:
start = dt.now().replace(minute=0, second=0, microsecond=0)
end = start + timedelta(hours=24)
self.logger.debug(f"Filter dataset to upcomming 24hrs {start} - {end} -> refresh each hour")
return {hour: price for hour, price in data.items() if start < hour < end }

elif self.calculation_mode == CALCULATION_MODE["forward-12"]:
start = dt.now().replace(minute=0, second=0, microsecond=0)
end = start + timedelta(hours=12)
self.logger.debug(f"Filter dataset to upcomming 12hrs {start} - {end} -> refresh each hour")
return {hour: price for hour, price in data.items() if start < hour < end }

# default elif self.calculation_mode == CALCULATION_MODE["publish"]:
self.logger.debug(f"Do not filter the dataset, use the complete dataset as fetched")
return { hour: price for hour, price in data.items() }

def get_prices_today(self):
return self.get_timestamped_prices(self.get_data_today())
Expand Down
Loading