broker_utils.schema_maps

The schema_maps module loads and returns schema maps stored in Cloud Storage.

broker.broker_utils.broker_utils.schema_maps.get_key(key, schema_map)[source]

Return the key or final element in list corresponding to schema_map and key.

Return type

Union[int, str]

broker.broker_utils.broker_utils.schema_maps.get_value(key, alert_dict, schema_map)[source]

Return the alert_dict value corresponding to schema_map and key.

Return type

Union[int, str]

broker.broker_utils.broker_utils.schema_maps.load_schema_map(survey, testid, schema=None)[source]

Return a dict mapping the survey’s field names to an internal broker standard.

Parameters
  • survey (str) – Name of the survey associated with the broker instance. If schema is a pathlib.Path, survey is ignored (left as an arg for backward compatibility). Otherwise, it determines (in conjunction with testid) which GCS bucket the schema map will be loaded from. If schema is None, this will also determine which survey’s schema map is returned.

  • testid (str) – If schema is a pathlib.Path, testid is ignored (left as an arg for backward compatibility). Otherwise, it determines (in conjunction with survey) which GCS bucket the schema map will be loaded from. If this is a bool, it must be False (indicating a production instance).

  • schema (Union[Path, str, None]) – If this is a pathlib.Path: path to a local yaml file to be loaded. In this case, survey and testid are ignored. If this is a str: name of the survey who’s schema map is to be loaded. It will be retrieved from a Cloud Storage bucket. If this is None, the schema map corresponding to survey will be will be retrieved from a Cloud Storage bucket.

Return type

dict

Returns

Dictionary mapping the survey’s field names to an internal broker standard.

broker.broker_utils.broker_utils.schema_maps.load_yaml(fin)[source]

Load a yaml file and return as a dict.

Parameters

fin (Union[Path, str, Blob]) – Path-like or google.cloud.storage.blob.Blob object. Assumes yaml format.

Return type

dict

Returns

Dictionary mapping the survey’s field names to an internal broker standard.