Survey accessors

Surveys come to SDX as JSON messages. They are then loaded via Python’s json module, which returns a nested dictionary.

The survey module provides functions to access survey reply data. These will be of use in Processing functions and Transformers.

class sdx.common.survey.Survey[source]

Provide operations and accessors to survey data.

static load_survey(ids, package, pattern)[source]

Retrieve the survey definition by id.

This function takes metadata from a survey reply, finds the JSON definition of that survey, and loads it as a Python object.

Parameters:
  • ids (sdx.common.survey.Survey.Identifiers) – Survey response ids.
  • package (str) – The name of the Python package where the survey is to be found, eg: “sdx.common”. Within standalone apps which do not declare themselves as Python packages, pass in the variable __name__.
  • pattern (str) –

    A query for the survey definition. This will be a file path relative to the package location which uniquely identifies the survey definition file. It accepts keyword formatting arguments for any of the attributes of sdx.common.survey.Survey.Identifiers.

    For example: “surveys/{survey_id}.{inst_id}.json”.

Return type:

dict

static bind_logger(log, ids)[source]

Bind a structured logger with survey response metadata.

Parameters:
static parse_timestamp(text)[source]

Parse a text field for a date or timestamp.

Date and time formats vary across surveys. This method reads those formats.

Parameters:text (str) – The date or timestamp value.
Return type:Python date or datetime.
static identifiers(data, batch_nr=0, seq_nr=0, log=None)[source]

Parse common metadata from the survey.

Return a named tuple which code can use to access the various ids and discriminators.

Parameters:
  • data (dict) – A survey reply.
  • batch_nr (int) – A batch number for the reply.
  • seq_nr (int) – An image sequence number for the reply.
Survey.Identifiers (batch_nr, seq_nr, ts, tx_id, survey_id, inst_id, user_ts, user_id, ru_ref, ru_check, period)

A named tuple type to capture ids and discriminators from a survey response.