pyvlog package¶
pyvlog.parsers module¶
Classes for parsing V-Log messages and logging statuses.
-
class
pyvlog.parsers.
VLogParser
(logged_types=['detectie', 'externeSignaalgroep'], **kwargs)¶ Bases:
object
Base class for parsing v-log messages. Does not log statuses.
Parameters: logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged. -
log_status
(status)¶ Placeholder function, does nothing with the status.
Parameters: status (dict) – V-log status to be logged.
-
parse_message
(message)¶ Parse a v-log message and update the status. If the status is complete log_status is called.
Parameters: message (str) – V-log message.
-
-
class
pyvlog.parsers.
VLogParserToJson
(path_to_json, logged_types=['detectie', 'externeSignaalgroep'])¶ Bases:
pyvlog.parsers.VLogParser
Class for parsing v-log messages to a json of statuses. Appends each logged status to a json file.
Parameters: - path_to_json (str) – Path to json file.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
-
log_status
(status, path_to_json)¶ Append the status to a json file.
Parameters: - status (dict) – V-log status to be logged.
- path_to_json (str) – Path to json file.
-
class
pyvlog.parsers.
VLogParserToList
(status_list, logged_types=['detectie', 'externeSignaalgroep'])¶ Bases:
pyvlog.parsers.VLogParser
Class for parsing v-log messages to a list of statuses. Appends each logged status to a list object.
Parameters: - status_list (list) – List to be appended to.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
-
log_status
(status, status_list)¶ Append the status to a list.
Parameters: - status (dict) – V-log status to be logged.
- status_list (list) – List to be appended to.
pyvlog.converters module¶
Functions for converting V-Log data into statuses.
-
pyvlog.converters.
file_to_dataframe
(path_to_vlg, logged_types=['detectie', 'externeSignaalgroep'])¶ Convert a file of v-log messages (each on a new line) to a dataframe of statuses.
Parameters: - path_to_vlg (str) – Path to file containing vlog messages.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
Returns: df – Dataframe of statuses.
Return type: pd.DataFrame
-
pyvlog.converters.
file_to_json
(path_to_vlg, path_to_json, logged_types=['detectie', 'externeSignaalgroep'])¶ Convert a file of v-log messages (each on a new line) to a json file of statuses.
Parameters: - path_to_vlg (str) – Path to file containing vlog messages.
- path_to_json (str) – Path to json file to write to.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
-
pyvlog.converters.
file_to_list
(path_to_vlg, logged_types=['detectie', 'externeSignaalgroep'])¶ Convert a file of v-log messages (each on a new line) to a list of statuses.
Parameters: - path_to_vlg (str) – Path to file containing v-log messages.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
Returns: status_list – List of statuses.
Return type: list
-
pyvlog.converters.
list_to_dataframe
(messages, logged_types=['detectie', 'externeSignaalgroep'])¶ Convert a list of v-log messages to a dataframe of statuses.
Parameters: - messages (list) – List of vlog messages.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
Returns: df – Dataframe of statuses.
Return type: pd.DataFrame
-
pyvlog.converters.
list_to_json
(messages, path_to_json, logged_types=['detectie', 'externeSignaalgroep'])¶ Convert a list of v-log messages to a json file of statuses.
Parameters: - messages (list) – List of v-log messages.
- path_to_json (str) – Path to json file to write to.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
-
pyvlog.converters.
list_to_list
(messages, logged_types=['detectie', 'externeSignaalgroep'])¶ Convert a list of v-log messages to a list of statuses.
Parameters: - messages (list) – List of v-log messages.
- logged_types (list) – Message types (should match keys of messagetypes.MESSAGE_TYPE_DICT) to be logged. If empty list all types are logged.
Returns: status_list – List of statuses.
Return type: list
pyvlog.utils module¶
Utility functions for converting hex messages and logging statuses.
-
pyvlog.utils.
flatten
(d, parent_key='', sep='_')¶ Flatten a nested dict.
Parameters: - d (dict) – Dictionary to flatten.
- parent_key (str) – Parent key to prefix new key.
- sep (str) – Separation character(s) for combined keys.
Returns: Flattened dict.
Return type: dict
-
pyvlog.utils.
hex_string_to_bits
(string)¶ Convert a string of hex characters to bits.
Parameters: string (str) – String of hex characters. Returns: bits – Number of sensors in status. Return type: str
-
pyvlog.utils.
parse_detection_data
(string)¶ Parse an element of detection data.
Parameters: string (str) – Element of detection data. Returns: out_concise – Dictionary of internal phase status. Return type: dict
-
pyvlog.utils.
parse_instruction_data
(string)¶ Parse an element of instruction variable status.
Parameters: string (str) – Element of instruction data. Returns: out_concise – Dictionary of internal phase status. Return type: dict
-
pyvlog.utils.
parse_internal_data
(string)¶ Parse an element of internal phase data.
Parameters: string (str) – Element of internal phase data. Returns: out_concise – Dictionary of internal phase status. Return type: dict
-
pyvlog.utils.
parse_ovhd_data
(string)¶ Parse an element of ov/hulpdienst data.
Parameters: string (str) – Element of internal phase data. Returns: out_concise – Dictionary of internal phase status. Return type: dict