Prefs¶
Prefs set configurable parameters used throughout PVP.
See prefs._DEFAULTS
for description of all available parameters
Prefs are stored in a .json file, by default located at ~/pvp/prefs.json
. Prefs can be manually
changed by editing this file (when the system is not running, when the system is running use prefs.set_pref()
).
When any module in pvp is first imported, the prefs.init()
function is called
that
Makes any directories listed in
prefs._DIRECTORIES
Declares all prefs as their default values from
prefs._DEFAULTS
to ensure they are always definedLoads the existing
prefs.json
file and updates values from their defaults
Prefs can be gotten and set from anywhere in the system with prefs.get_pref()
and prefs.set_pref()
.
Prefs are stored in a multiprocessing.Manager
dictionary which makes these methods both thread- and process-safe.
Whenever a pref is set, the prefs.json
file is updated to reflect the new value, so preferences
are durable between runtimes.
Additional prefs
should be added by adding an entry in the prefs._DEFAULTS
dict rather than hardcoding them elsewhere in the program.
Data:
flag to indicate whether prefs have been loaded (and thus |
|
Declare all available parameters and set default values. |
|
Directories to ensure are created and added to prefs. |
|
Locks access to prefs_fn |
|
A |
|
The dict created by |
|
The |
Classes:
|
Functions:
|
Get global configuration value |
|
Initialize prefs. |
|
Load prefs from a .json prefs file, combining (and overwriting) any existing prefs, and then saves. |
ensures _DIRECTORIES are created and added to prefs. |
|
|
Dumps loaded prefs to |
|
Sets a pref in the manager and, if |
-
pvp.common.prefs.
_PREF_MANAGER
= <multiprocessing.managers.SyncManager object>¶ The
multiprocessing.Manager
that stores prefs during system operation
-
pvp.common.prefs.
_PREFS
= <DictProxy object, typeid 'dict'>¶ The dict created by
prefs._PREF_MANAGER
to store prefs.
-
pvp.common.prefs.
_LOGGER
= <Logger pvp.common.prefs (WARNING)>¶ A
logging.Logger
to log pref init and setting events
-
pvp.common.prefs.
_LOCK
= <Lock(owner=None)>¶ Locks access to prefs_fn
- Type
mp.Lock
-
pvp.common.prefs.
_DIRECTORIES
= {'DATA_DIR': '/home/docs/pvp/logs', 'LOG_DIR': '/home/docs/pvp/logs', 'VENT_DIR': '/home/docs/pvp'}¶ Directories to ensure are created and added to prefs.
VENT_DIR
: ~/pvp - base directory for user storageLOG_DIR
: ~/pvp/logs - for storage of event and alarm logsDATA_DIR
: ~/pvp/data - for storage of waveform data
-
pvp.common.prefs.
LOADED
= <Synchronized wrapper for c_bool(True)>¶ flag to indicate whether prefs have been loaded (and thus
set_pref()
should write to disk).uses a
multiprocessing.Value
to be thread and process safe.- Type
-
pvp.common.prefs.
_DEFAULTS
= {'BREATH_DETECTION': True, 'BREATH_PRESSURE_DROP': 4, 'CONTROLLER_LOOPS_UNTIL_UPDATE': 1, 'CONTROLLER_LOOP_UPDATE_TIME': 0.0, 'CONTROLLER_LOOP_UPDATE_TIME_SIMULATOR': 0.005, 'CONTROLLER_MAX_FLOW': 10, 'CONTROLLER_MAX_PRESSURE': 100, 'CONTROLLER_MAX_STUCK_SENSOR': 0.2, 'CONTROLLER_RINGBUFFER_SIZE': 100, 'COUGH_DURATION': 0.1, 'ENABLE_DIALOGS': True, 'ENABLE_WARNINGS': True, 'GUI_STATE_FN': 'gui_state.json', 'GUI_UPDATE_TIME': 0.05, 'HEARTBEAT_TIMEOUT': 0.02, 'LOGGING_MAX_BYTES': 2147483648, 'LOGGING_MAX_FILES': 5, 'LOGLEVEL': 'WARNING', 'PREFS_FN': None, 'TIMEOUT': 0.05, 'TIME_FIRST_START': None}¶ Declare all available parameters and set default values. If no default, set as None.
PREFS_FN
- absolute path to the prefs fileTIME_FIRST_START
- time when the program has been started for the first timeVENT_DIR
: ~/pvp - base directory for user storageLOG_DIR
: ~/pvp/logs - for storage of event and alarm logsDATA_DIR
: ~/pvp/data - for storage of waveform dataLOGGING_MAX_BYTES
: the total storage space for all loggers – each logger getsLOGGING_MAX_BYTES/len(loggers)
space (2GB by default)LOGGING_MAX_FILES
: number of files to split each logger’s logs across (default: 5)LOGLEVEL
: One of('DEBUG', 'INFO', 'WARNING', 'EXCEPTION')
that sets the minimum log level that is printed and written to diskTIMEOUT
: timeout used for timeout decorators on time-sensitive operations (in seconds, default 0.05)HEARTBEAT_TIMEOUT
: Time between heartbeats between GUI and controller after which contact is assumed to be lost (in seconds, default 0.02)GUI_STATE_FN
: Filename of gui control state file, relative toVENT_DIR
(default: gui_state.json)GUI_UPDATE_TIME
: Time between calls ofPVP_Gui.update_gui()
(in seconds, default: 0.05)ENABLE_DIALOGS
: Enable all GUI dialogs – set as False when testing on virtual frame buffer that doesn’t support them (default: True and should stay that way)ENABLE_WARNINGS
: Enable user warnings and value change confirmations (default: True)CONTROLLER_MAX_FLOW
: Maximum flow, above which the controller considers a sensor error (default: 10)CONTROLLER_MAX_PRESSURE
: Maximum pressure, above which the controller considers a sensor error (default: 100)CONTROLLER_MAX_STUCK_SENSOR
: Max amount of time (in s) before considering a sensor stuck (default: 0.2)CONTROLLER_LOOP_UPDATE_TIME
: Amount of time to sleep in between controller update times when usingControlModuleDevice
(default: 0.0)CONTROLLER_LOOP_UPDATE_TIME_SIMULATOR
: Amount of time to sleep in between controller updates when usingControlModuleSimulator
(default: 0.005)CONTROLLER_LOOPS_UNTIL_UPDATE
: Number of controller loops in between updating its externally-availableCOPY
attributes retrieved byControlModuleBase.get_sensor()
et alCONTROLLER_RINGBUFFER_SIZE
: Maximum number of breath cycle records to be kept in memory (default: 100)COUGH_DURATION
: Amount of time the high-pressure alarm limit can be exceeded and considered a cough (in seconds, default: 0.1)BREATH_PRESSURE_DROP
: Amount pressure can drop below set PEEP before being considered an autonomous breath when in breath detection modeBREATH_DETECTION
: Whether the controller should detect autonomous breaths in order to reset ventilation cycles (default: True)
-
pvp.common.prefs.
set_pref
(key: str, val)[source]¶ Sets a pref in the manager and, if
prefs.LOADED
is True, callsprefs.save_prefs()
- Parameters
key (str) – Name of pref key
val – Value to set
-
pvp.common.prefs.
load_prefs
(prefs_fn: str)[source]¶ Load prefs from a .json prefs file, combining (and overwriting) any existing prefs, and then saves.
Called on pvp import by
prefs.init()
Also initializes
prefs._LOGGER
Note
once this function is called,
set_pref()
will update the prefs file on disk. So ifload_prefs()
is called again at any point it should not change prefs.- Parameters
prefs_fn (str) – path of prefs.json