DART (indra_world.sources.dart)

API (indra_world.sources.dart.api)

Client (indra_world.sources.dart.client)

A client for accessing reader output from the DART system.

class indra_world.sources.dart.client.DartClient(storage_mode='web', dart_url=None, dart_uname=None, dart_pwd=None, local_storage=None)[source]

A client for the DART web service with optional local storage.

Parameters
  • storage_mode (Optional[str]) – If web, the configured DART URL and credentials are used to communicate with the DART web service. If local, a local storage is used to access and store reader outputs.

  • dart_url (Optional[str]) – The DART service URL. If given, it overrides the DART_WM_URL configuration value.

  • dart_uname (Optional[str]) – The DART service user name. If given, it overrides the DART_WM_USERNAME configuration value.

  • dart_pwd (Optional[str]) – The DART service password. If given, it overrides the DART_WM_PASSWORD configuration value.

  • local_storage (Optional[str]) – A path that points to a folder for local storage. If the storage_mode is web, this local_storage is used as a local cache. If the storage_mode is local, it is used as the primary location to access reader outputs. If given, it overrides the INDRA_WM_CACHE configuration value.

cache_record(record, overwrite=False)[source]

Download and cache a given record in local storage.

Parameters

record (dict) – A DART record.

cache_records(records, overwrite=False)[source]

Download and cache a list of records in local storage.

Parameters

records (list[dict]) – A list of DART records.

download_output(storage_key)[source]

Return content from the DART web service based on its storage key.

Parameters

storage_key (str) – A DART storage key.

Returns

The content corresponding to the storage key.

Return type

str

get_local_storage_path(record)[source]

Return the local storage path for a DART record.

get_output_from_record(record)[source]

Return reader output corresponding to a single record.

Parameters

record (dict) – A single DART record.

Returns

The reader output corresponding to the given record.

Return type

str

get_outputs_from_records(records)[source]

Return reader outputs corresponding to a list of records.

Parameters

records (list of dict) – A list of records returned from the reader output query.

Returns

A two-level dict of reader output keyed by reader and then document id.

Return type

dict(str, dict)

get_reader_output_records(readers=None, versions=None, document_ids=None, timestamp=None)[source]

Return reader output metadata records by querying the DART API

Query json structure:

{“readers”: [“MyAwesomeTool”, “SomeOtherAwesomeTool”], “versions”: [“3.1.4”, “1.3.3.7”], “document_ids”: [“qwerty1234”, “poiuyt0987”], “timestamp”: {“before”: “yyyy-mm-dd”|”yyyy-mm-dd hh:mm:ss”, “after”: “yyyy-mm-dd”|”yyyy-mm-dd hh:mm:ss”, “on”: “yyyy-mm-dd”}}

Parameters
  • readers (list) – A list of reader names

  • versions (list) – A list of versions to match with the reader name(s)

  • document_ids (list) – A list of document identifiers

  • timestamp (dict("on"|"before"|"after",str)) – The timestamp string must of format “yyyy-mm-dd” or “yyyy-mm-dd hh:mm:ss” (only for “before” and “after”).

Returns

The JSON payload of the response from the DART API

Return type

dict

get_reader_versions(reader)[source]

Return the available versions for a given reader.

indra_world.sources.dart.client.prioritize_records(records, priorities=None)[source]

Return unique records per reader and document prioritizing by version.

Parameters
  • records (list of dict) – A list of records returned from the reader output query.

  • priorities (dict of list) – A dict keyed by reader names (e.g., cwms, eidos) with values representing reader versions in decreasing order of priority.

Returns

records – A list of records that are unique per reader and document, picked by version priority when multiple records exist for the same reader and document.

Return type

list of dict