-
Notifications
You must be signed in to change notification settings - Fork 22
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
Units signal metadata #367
Conversation
51dfbd8
to
cd96b2e
Compare
Are we waiting on PVA changes for this, or that a different PR? |
* unprivate variable * Add limits handling for PVA and CA * Tests for limits * Limits are only ever type float * Only add limits if set, used TypedDict * Revert nan, add more tests * Add limits and warnings to ioc
Co-authored-by: DiamondJoseph <53935796+DiamondJoseph@users.noreply.github.com>
def _limits_from_value(value: Value) -> Limits: | ||
valueAlarm = getattr(value, "valueAlarm", None) | ||
_empty_limit = LimitPair(low=None, high=None) | ||
|
||
def get_control_or_display_limit(limit: str) -> LimitPair: | ||
if (control_or_display := getattr(value, limit, None)) is None: | ||
return _empty_limit | ||
low = getattr(control_or_display, "limitLow", None) | ||
high = getattr(control_or_display, "limitHigh", None) | ||
return LimitPair( | ||
low=None if isnan(low) else low, high=None if isnan(high) else high | ||
) | ||
|
||
def get_alarm_or_warning_limit(limit: str) -> LimitPair: | ||
if valueAlarm is None: | ||
return _empty_limit | ||
low = getattr(valueAlarm, f"low{limit}Limit", None) | ||
high = getattr(valueAlarm, f"high{limit}Limit", None) | ||
return LimitPair( | ||
low=None if isnan(low) else low, high=None if isnan(high) else high | ||
) | ||
|
||
return Limits( | ||
alarm=get_alarm_or_warning_limit("Alarm"), | ||
control=get_control_or_display_limit("control"), | ||
display=get_control_or_display_limit("display"), | ||
warning=get_alarm_or_warning_limit("Warning"), | ||
) |
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.
Could this be written more simply?
def _limits_from_value(value: Value) -> Limits: | |
valueAlarm = getattr(value, "valueAlarm", None) | |
_empty_limit = LimitPair(low=None, high=None) | |
def get_control_or_display_limit(limit: str) -> LimitPair: | |
if (control_or_display := getattr(value, limit, None)) is None: | |
return _empty_limit | |
low = getattr(control_or_display, "limitLow", None) | |
high = getattr(control_or_display, "limitHigh", None) | |
return LimitPair( | |
low=None if isnan(low) else low, high=None if isnan(high) else high | |
) | |
def get_alarm_or_warning_limit(limit: str) -> LimitPair: | |
if valueAlarm is None: | |
return _empty_limit | |
low = getattr(valueAlarm, f"low{limit}Limit", None) | |
high = getattr(valueAlarm, f"high{limit}Limit", None) | |
return LimitPair( | |
low=None if isnan(low) else low, high=None if isnan(high) else high | |
) | |
return Limits( | |
alarm=get_alarm_or_warning_limit("Alarm"), | |
control=get_control_or_display_limit("control"), | |
display=get_control_or_display_limit("display"), | |
warning=get_alarm_or_warning_limit("Warning"), | |
) | |
def _limits_from_value(value: Value) -> Limits: | |
def get_limits(substucture_name: str, infix: str = "") -> LimitPair: | |
substructure = getattr(value, substucture_name, None) | |
low = getattr(substructure, f"low{infix}Limit", None) | |
high = getattr(substructure, f"high{infix}Limit", None) | |
return LimitPair( | |
low=None if isnan(low) else low, high=None if isnan(high) else high | |
) | |
return Limits( | |
alarm=get_limits("valueAlarm", infix="Alarm"), | |
control=get_limits("control"), | |
display=get_limits("display"), | |
warning=get_limits("valueAlarm", infix="Warning"), | |
) |
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.
Unfortunately the suggestion fails quite a number of tests but i'll have a look.
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.
Not quite, it's low{infix}Limit but limitLow for the others.
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.
So I am inclined to leave it as it is.
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.
How about?
def _limits_from_value(value: Value) -> Limits: | |
valueAlarm = getattr(value, "valueAlarm", None) | |
_empty_limit = LimitPair(low=None, high=None) | |
def get_control_or_display_limit(limit: str) -> LimitPair: | |
if (control_or_display := getattr(value, limit, None)) is None: | |
return _empty_limit | |
low = getattr(control_or_display, "limitLow", None) | |
high = getattr(control_or_display, "limitHigh", None) | |
return LimitPair( | |
low=None if isnan(low) else low, high=None if isnan(high) else high | |
) | |
def get_alarm_or_warning_limit(limit: str) -> LimitPair: | |
if valueAlarm is None: | |
return _empty_limit | |
low = getattr(valueAlarm, f"low{limit}Limit", None) | |
high = getattr(valueAlarm, f"high{limit}Limit", None) | |
return LimitPair( | |
low=None if isnan(low) else low, high=None if isnan(high) else high | |
) | |
return Limits( | |
alarm=get_alarm_or_warning_limit("Alarm"), | |
control=get_control_or_display_limit("control"), | |
display=get_control_or_display_limit("display"), | |
warning=get_alarm_or_warning_limit("Warning"), | |
) | |
def _limits_from_value(value: Value) -> Limits: | |
def get_limits(substucture_name: str, low_name: str = "limitLow", high_name: str = "limitHigh") -> LimitPair: | |
substructure = getattr(value, substucture_name, None) | |
low = getattr(substructure, low_name, None) | |
high = getattr(substructure, high_name, None) | |
return LimitPair( | |
low=None if isnan(low) else low, high=None if isnan(high) else high | |
) | |
return Limits( | |
alarm=get_limits("valueAlarm", "lowAlarmLimit", "highAlarmLimit"), | |
control=get_limits("control"), | |
display=get_limits("display"), | |
warning=get_limits("valueAlarm", "lowWarningLimit", "highWarningLimit"), | |
) |
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.
Still no. Is this worth blocking on? Can I make an issue to put in the upcoming sprint to refactor it, it would be a good first issue.
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.
Got there in the end (assuming this passes), made a minor change to getattr(foo, bar, nan) as isnan(None) becomes unhappy. I'm assuming that if the attr is there (substructure is not None and hasattr(substructure, attr)) it will never be None
Fixes #146 . Rebase of #137 .
Propagates units and precision metadata (if present) from PVA or CA signal backends.