dispel.providers.bdh.io package#

Functionality to read files from BDH apps.

Examples

To read a BDH json file and work with the contained data one can read the file:

bdh

>>> from dispel.providers.bdh.io import read_bdh
>>> reading = read_bdh(path)

And access raw sensor data for the first level

bdh
:options: +NORMALIZE_WHITESPACE

>>> id_ = reading.level_ids[0]
>>> reading.get_level(id_).get_raw_data_set('screen').data.head().tsTouch
0   2021-03-21 10:33:26.666
1   2021-03-21 10:33:26.674
2   2021-03-21 10:33:26.690
3   2021-03-21 10:33:26.698
4   2021-03-21 10:33:26.716
Name: tsTouch, dtype: datetime64[ns]

For further details on Reading and the data model take a look at dispel.data.core.

dispel.providers.bdh.io.create_levels(data, schema)[source]#

Create levels from uni-level activity data.

The BDH format does not split data in levels in the same way the ADS format does. For example, in the mood test, the two questions are lumped in the same level. This function splits the data in the way dispel expects.

Parameters:
Returns:

Level data

Return type:

Dict[str, Any]

dispel.providers.bdh.io.enrich_context(schema, level_id, context)[source]#

Enrich the context with level specific information.

dispel.providers.bdh.io.get_context(config, schema_name)[source]#

Create a context from a config dictionary.

Parameters:
  • config (Dict[str, Any] | None) – An optional dict that contains the raw information about the context

  • schema_name (str) – The name of the schema

Returns:

The parsed context

Return type:

Context

dispel.providers.bdh.io.get_level_id(config, schema)[source]#

Parse level id from level type and configuration.

Parameters:
  • config (dict) – The level configuration

  • schema (ReadingSchema) – The schema from data header

Returns:

Level id for the level.

Return type:

LevelId

Raises:

NotImplementedError – If the schema name parsing has not been implemented.

dispel.providers.bdh.io.parsable_bdh_json(value)[source]#

Test if a value is a dictionary and contains BDH specific keys.

Parameters:

value (Any) –

Return type:

bool

dispel.providers.bdh.io.parse_bdh_reading(data)[source]#

Get class representation of dictionary representation.

Parameters:

data (Dict) – The dictionary containing the information about the reading

Returns:

The class representation of the record passed.

Return type:

Reading

Raises:

ValueError – If header, schema or body information is missing in data.

dispel.providers.bdh.io.parse_device(device_dict)[source]#

Parse a device dictionary into a Device class.

Parameters:

device_dict (dict) – The device information dictionary.

Returns:

The device information.

Return type:

Device

dispel.providers.bdh.io.parse_evaluation(data)[source]#

Parse the evaluation information for a reading.

Parameters:

data (Dict) – The header of the BDH json file

Returns:

The evaluation information for the reading

Return type:

BDHEvaluation

Raises:

ValueError – If the evaluation id is missing from the data.

dispel.providers.bdh.io.parse_level(data, schema, measure_definitions, raw_data_definitions)[source]#

Parse level id from dictionary containing level info.

Parameters:
Returns:

The parsed level

Return type:

Level

dispel.providers.bdh.io.parse_levels(data, schema, measure_definitions, raw_data_definitions)[source]#

Parse levels from dict.

Parameters:
Returns:

list of levels

Return type:

List[Level]

Raises:

ValueError – If a level property is missing in data.

dispel.providers.bdh.io.parse_measure_definition(id_, data)[source]#

Parse a measure definition.

Parameters:
  • id – The id of the measure value definition

  • data (Dict) – The measure definition in BDH json format

  • id_ (str) –

Returns:

The created value definition.

Return type:

ValueDefinition

dispel.providers.bdh.io.parse_measures(data, definitions)[source]#

Parse measures from a reading.

Parameters:
Returns:

The created measure set.

Return type:

MeasureSet

dispel.providers.bdh.io.parse_raw_data_set_definition(id_, data)[source]#

Parse a raw data set definition for a reading.

Parameters:
  • id – The id of the raw data set

  • data (Dict) – The definition of the raw data set in BDH json format.

  • id_ (str) –

Returns:

The created raw data set definition.

Return type:

RawDataSetDefinition

Raises:
  • ValueError – If no source is defined for the given raw data source.

  • ValueError – If no values are defined for the given raw data source.

dispel.providers.bdh.io.parse_raw_data_source(data)[source]#

Parse a raw data source definition.

Parameters:

data (Dict) – The BDH raw data source definition dictionary in BDH json format.

Returns:

The created BDH format raw data set source.

Return type:

BDHRawDataSetSource

dispel.providers.bdh.io.parse_raw_data_value_definition(id_, data)[source]#

Parse a raw data value definition.

Parameters:
  • id – The id of the raw data value definition.

  • data (Dict) – The raw data value definition in BDH json format.

  • id_ (str) –

Returns:

The created raw data value definition.

Return type:

RawDataValueDefinition

dispel.providers.bdh.io.parse_schema(data)[source]#

Parse the schema of a reading.

Parameters:

data (Dict) – A dictionary containing the schema attributes

Returns:

The created reading schema.

Return type:

ReadingSchema

dispel.providers.bdh.io.parse_screen(device)[source]#

Parse a screen dictionary into a Screen class.

Parameters:

device (Dict[str, Any]) – Device information.

Returns:

The screen information.

Return type:

Screen

dispel.providers.bdh.io.parse_session(header)[source]#

Parse the header into a Session class.

Parameters:

header (dict) – The header dictionary.

Returns:

Session data.

Return type:

Session

dispel.providers.bdh.io.read_bdh(path)[source]#

Read a BDH data record.

Parameters:

path (str) – The path to the reading to be parsed

Returns:

The class representation of the record parsed.

Return type:

Reading

dispel.providers.bdh.io.update_raw_data_definition(data, schema)[source]#

Update raw data definitions.

Parameters:
Returns:

Level data

Return type:

Dict[str, Any]

Submodules#