-
Notifications
You must be signed in to change notification settings - Fork 21
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
GSYE-568: Change hierarchy self consumption into percentage values #1800
Changes from 3 commits
6562b69
b55266d
d4ea7d7
87ff961
e7a8af6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import logging | ||
from collections import defaultdict | ||
from typing import TYPE_CHECKING, Dict, Iterable, List | ||
from math import isclose | ||
|
||
from gsy_framework.constants_limits import ( | ||
DATE_TIME_FORMAT, | ||
|
@@ -94,7 +95,7 @@ | |
self.status = "" | ||
self.area_result_dict = self._create_area_tree_dict(area) | ||
self.flattened_area_core_stats_dict = {} | ||
self.hierarchy_self_consumption: Dict[int, float] = {} | ||
self.hierarchy_self_consumption_percent: Dict[int, float] = {} | ||
self.simulation_progress = { | ||
"eta_seconds": 0, | ||
"elapsed_time_seconds": 0, | ||
|
@@ -135,7 +136,7 @@ | |
"status": self.status, | ||
"progress_info": self.simulation_progress, | ||
"simulation_state": self.simulation_state, | ||
"hierarchy_self_consumption": self.hierarchy_self_consumption, | ||
"hierarchy_self_consumption_percent": self.hierarchy_self_consumption_percent, | ||
**self.results_handler.all_raw_results, | ||
} | ||
|
||
|
@@ -195,14 +196,35 @@ | |
def create_hierarchy_stats(self, area: "AreaBase"): | ||
"""Calculate hierarchy related statistics.""" | ||
hierarchy_self_consumption_list = {} | ||
self._calc_hierarchy_stats(area, 0, hierarchy_self_consumption_list) | ||
hierarchy_self_consumption = {} | ||
self._calc_hierarchy_self_consumption(area, 0, hierarchy_self_consumption_list) | ||
for level, consumption_list in hierarchy_self_consumption_list.items(): | ||
if len(consumption_list): | ||
self.hierarchy_self_consumption[level] = sum(consumption_list) / len( | ||
consumption_list | ||
) | ||
hierarchy_self_consumption[level] = sum(consumption_list) / len(consumption_list) | ||
if ( | ||
len(hierarchy_self_consumption) > 0 | ||
and hierarchy_self_consumption[next(iter(hierarchy_self_consumption))] == 0 | ||
): | ||
# early return in case there is no self consumpton at all (in order to not devide by 0) | ||
return | ||
|
||
def _calc_hierarchy_stats(self, area: "AreaBase", level: int, results: Dict): | ||
for level, self_consumption in hierarchy_self_consumption.items(): | ||
if level + 1 not in hierarchy_self_consumption: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that big of an issue, since it probably makes the solution simpler, however I think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not mind either way, so I changed it to be a list: 87ff961 |
||
# lowest level case: | ||
self.hierarchy_self_consumption_percent[level] = ( | ||
self_consumption / hierarchy_self_consumption[0] | ||
) * 100 | ||
else: | ||
self.hierarchy_self_consumption_percent[level] = ( | ||
(self_consumption - hierarchy_self_consumption[level + 1]) | ||
/ hierarchy_self_consumption[0] | ||
) * 100 | ||
if self.hierarchy_self_consumption_percent: | ||
assert isclose( | ||
sum(self.hierarchy_self_consumption_percent.values()), 100 | ||
), "Self consumption percentages do not sum up to 100%" | ||
Comment on lines
+220
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great assert, it will always confirm that this feature is working as expected, thanks! |
||
|
||
def _calc_hierarchy_self_consumption(self, area: "AreaBase", level: int, results: Dict): | ||
if not area.children: | ||
return | ||
kpis = self.results_handler.results_mapping["kpi"].ui_formatted_results | ||
|
@@ -215,7 +237,7 @@ | |
if level not in results: | ||
results[level] = [] | ||
results[level].append(kpis[child.uuid]["self_consumption"]) | ||
self._calc_hierarchy_stats(child, level + 1, results) | ||
self._calc_hierarchy_self_consumption(child, level + 1, results) | ||
|
||
def _generate_result_report(self) -> Dict: | ||
"""Create dict that contains all statistics that are sent to the gsy-web.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
87ff961