-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: development
Are you sure you want to change the base?
Conversation
…ation for all attributes
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) |
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.
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]): |
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.
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]): |
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.
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) |
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.
see previous comment
return sum(getattr(tz, name) for tz in self.elements if | ||
getattr(tz, name) is not None) |
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.
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)) |
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 |
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.
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"
closes #779