Skip to content

Commit

Permalink
Docstrings for values.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Aug 16, 2020
1 parent 488eae6 commit df712eb
Showing 1 changed file with 113 additions and 48 deletions.
161 changes: 113 additions & 48 deletions pvp/common/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Values
=======
Testing headings and subheadings in docstring docs
Subheading
-----------
Expand All @@ -15,22 +15,32 @@

# TODO: Zhenyu's job is to make sure the print value is an intepretable string
class ValueName(Enum):
#Setting that are likely important for future adjustements
"""
Canonical names of all values used in PVP.
"""
PIP = auto() # PIP pressure
PIP_TIME = auto() # time to reach PIP
PEEP = auto() # PEEP pressure
PEEP_TIME = auto() # time to reach PEEP
BREATHS_PER_MINUTE = auto()
INSPIRATION_TIME_SEC = auto()
IE_RATIO = auto()
#Settings that are read out, but can not be controlled by software
FIO2 = auto()
VTE = auto()
PRESSURE = auto()
FLOWOUT = auto()


class Value(object):
"""
Class to parameterize how a value is used in PVP.
Sets whether a value is a sensor value, a control value, whether it should be plotted,
and other details for the rest of the system to determine how to use it.
Values should only be declared in this file so that they are kept consistent with :class:`.ValueName`
and to not leak stray values anywhere else in the program.
"""

def __init__(self,
name: str,
Expand Down Expand Up @@ -64,11 +74,15 @@ def __init__(self,
though the user-set alarm values are initialized as ``safe_range``.
decimals (int): the number of decimals of precision used when displaying the value
display (bool): whether the value should be displayed in the monitor. if ``control == True``,
automatically set to ``False`` because all controls have their own numerical displays
plot (bool): whether or not the value is plottable int he center plot window
control (bool): Whether or not the value is used to control ventilation
sensor (bool): Whether or not the value is a measured sensor value
display (bool): whether the value should be created as a :class:`.gui.widgets.Display` widget.
plot (bool): whether or not the value is plottable in the center plot window
plot_limits (None, tuple(ValueName)): If plottable, and the plotted value has some alarm limits for another value,
plot those limits as horizontal lines in the plot. eg. the PIP alarm range limits should be plotted on the Pressure plot
control_type (None, "slider", "record"): If a control sets whether the control should use a slider or be set by recording recent sensor values.
group (None, str): Unused currently, but to be used to create subgroups of control & display widgets
default (None, int, float): Default value, if any. (Not automatically set in the GUI.)
"""

self._name = None
Expand Down Expand Up @@ -103,6 +117,12 @@ def __init__(self,

@property
def name(self) -> str:
"""
Human readable name of value
Returns:
str
"""
return self._name

@name.setter
Expand All @@ -112,6 +132,13 @@ def name(self, name):

@property
def abs_range(self) -> tuple:
"""
tuple of ints or floats setting the logical limit of the value,
eg. a percent between 0 and 100, (0, 100)
Returns:
tuple
"""
return self._abs_range

@abs_range.setter
Expand All @@ -122,6 +149,17 @@ def abs_range(self, abs_range):

@property
def safe_range(self) -> tuple:
"""
tuple of ints or floats setting the safe ranges of the value,
note::
this is not the same thing as the user-set alarm values,
though the user-set alarm values are initialized as ``safe_range``.
Returns:
tuple
"""
return self._safe_range

@safe_range.setter
Expand All @@ -133,6 +171,12 @@ def safe_range(self, safe_range):

@property
def decimals(self) -> int:
"""
The number of decimals of precision used when displaying the value
Returns:
int
"""
return self._decimals

@decimals.setter
Expand All @@ -142,6 +186,9 @@ def decimals(self, decimals):

@property
def default(self):
"""
Default value, if any. (Not automatically set in the GUI.)
"""
return self._default

@default.setter
Expand All @@ -150,7 +197,13 @@ def default(self, default):
self._default = default

@property
def control(self):
def control(self) -> bool:
"""
Whether or not the value is used to control ventilation
Returns:
bool
"""
return self._control

@control.setter
Expand All @@ -159,7 +212,13 @@ def control(self, control):
self._control = control

@property
def sensor(self):
def sensor(self) -> bool:
"""
Whether or not the value is a measured sensor value
Returns:
bool
"""
return self._sensor

@sensor.setter
Expand All @@ -169,6 +228,12 @@ def sensor(self, sensor):

@property
def display(self):
"""
Whether the value should be created as a :class:`.gui.widgets.Display` widget.
Returns:
bool
"""
return self._display

@display.setter
Expand All @@ -178,6 +243,12 @@ def display(self, display):

@property
def control_type(self):
"""
If a control sets whether the control should use a slider or be set by recording recent sensor values.
Returns:
None, "slider", "record"
"""
return self._control_type

@control_type.setter
Expand All @@ -187,6 +258,12 @@ def control_type(self, control_type):

@property
def group(self):
"""
Unused currently, but to be used to create subgroups of control & display widgets
Returns:
None, str
"""
return self._group

@group.setter
Expand All @@ -199,6 +276,12 @@ def group(self, group):

@property
def plot(self):
"""
whether or not the value is plottable in the center plot window
Returns:
bool
"""
return self._plot

@plot.setter
Expand All @@ -208,6 +291,13 @@ def plot(self, plot):

@property
def plot_limits(self):
"""
If plottable, and the plotted value has some alarm limits for another value,
plot those limits as horizontal lines in the plot. eg. the PIP alarm range limits should be plotted on the Pressure plot
Returns:
None, typing.Tuple[ValueName]
"""
return self._plot_limits

@plot_limits.setter
Expand Down Expand Up @@ -375,22 +465,17 @@ def to_dict(self):
'plot': True
}),
})
"""
Declaration of all values used by PVP
"""

SENSOR = odict({
k:v for k, v in VALUES.items() if v.sensor
})
"""
Values to monitor but not control.
Used to set alarms for out-of-bounds sensor values. These should be sent from the control module and not computed.::
Sensor values
{
'name' (str): Human readable name,
'units' (str): units string, (like degrees or %),
'abs_range' (tuple): absolute possible range of values,
'safe_range' (tuple): range outside of which a warning will be raised,
'decimals' (int): The number of decimals of precision this number should be displayed with
}
Automatically generated as all :class:`.Value` objects in :data:`.VALUES` where ``sensor == True``
"""


Expand All @@ -400,52 +485,32 @@ def to_dict(self):
"""
Values to control but not monitor.
Sent to control module to control operation of ventilator.::
{
'name' (str): Human readable name,
'units' (str): units string, (like degrees or %),
'abs_range' (tuple): absolute possible range of values,
'safe_range' (tuple): range outside of which a warning will be raised,
'default' (int, float): the default value of the parameter,
'decimals' (int): The number of decimals of precision this number should be displayed with
}
Automatically generated as all :class:`.Value` objects in :data:`.VALUES` where ``control == True``
"""

DISPLAY_MONITOR = odict({
k: v for k, v in VALUES.items() if v.sensor and v.display
})
"""
Values that should be displayed in the GUI. If a value is also a CONTROL it will always have the measured value displayed,
these values are those that are sensor values that are uncontrolled and should be displayed.
Those sensor values that should also have a widget created in the GUI
Automatically generated as all :class:`.Value` objects in :data:`.VALUES` where ``sensor == True`` and ``display == True``
"""

DISPLAY_CONTROL = odict({
k: v for k, v in VALUES.items() if v.control and v.display
})
"""
Values that should be displayed in the GUI. If a value is also a CONTROL it will always have the measured value displayed,
these values are those that are sensor values that are uncontrolled and should be displayed.
Control values that should also have a widget created in the GUI
Automatically generated as all :class:`.Value` objects in :data:`.VALUES` where ``control == True`` and ``display == True``
"""

PLOTS = odict({
k: v for k, v in VALUES.items() if v.plot
})

LIMITS = {

}
"""
Values that are dependent on other values::
{
"dependent_value": (
['value_1', 'value_2'],
callable_returning_boolean
}
}
Where the first argument in the tuple is a list of the values that will be
given as argument to the ``callable_returning_boolean`` which will return
whether (``True``) or not (``False``) a value is allowed.
Values that can be plotted
Automatically generated as all :class:`.Value` objects in :data:`.VALUES` where ``plot == True``
"""

0 comments on commit df712eb

Please sign in to comment.