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

only calculate Aggregated TZ attributes if existing and use to_aggregation method #780

Open
wants to merge 4 commits into
base: development
Choose a base branch
from

Conversation

DaJansenGit
Copy link
Member

closes #779

@DaJansenGit DaJansenGit linked an issue Jan 6, 2025 that may be closed by this pull request
@DaJansenGit DaJansenGit self-assigned this Jan 6, 2025
if all([getattr(tz, name) is not None for tz in self.elements]):
prop_sum = sum(
getattr(tz, name) * tz.net_volume for tz in self.elements if
getattr(tz, name) is not None and tz.net_volume is not None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getattr(tz, name) is not None and tz.net_volume is not None)
tz.net_volume is not None)

remove redundant check that the attribute is not None. Also remove check for tz.net_volume if included in all(...) check as suggested above.

getattr(tz, name) is not None and tz.net_volume is not None)
return prop_sum / self.net_volume
# only calculate intensive calc if all zones have this attribute
if all([getattr(tz, name) is not None for tz in self.elements]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you check for the net_volume (= not None) here, too?

if getattr(tz, name) is not None and tz.net_volume is not None)
/ self.net_volume)
return aux
if all([getattr(tz, name) is not None for tz in self.elements]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

getattr(tz, name)[x] * tz.net_volume for tz in
self.elements
if getattr(tz,
name) is not None and tz.net_volume is not None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see previous comment

Comment on lines +177 to +178
return sum(getattr(tz, name) for tz in self.elements if
getattr(tz, name) is not None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return sum(getattr(tz, name) for tz in self.elements if
getattr(tz, name) is not None)
return sum(getattr(tz, name) for tz in self.elements))

Comment on lines +187 to +194
prop_bool = False
for tz in self.elements:
prop = getattr(tz, name)
if prop is not None:
if prop:
prop_bool = True
break
return prop_bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prop_bool = False
for tz in self.elements:
prop = getattr(tz, name)
if prop is not None:
if prop:
prop_bool = True
break
return prop_bool
for tz in self.elements:
prop = getattr(tz, name)
if prop is not None:
return True

Please simplify this function. You may even be able to shorten even further by directly checking "if getattr(tz, name): return True"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix tz aggregation attributes
2 participants