ASRResult

class ase2sprkkr.asr.core.results.ASRResult(data={}, metadata={}, strict=None)[source]

Base class for describing results generated with recipes.

A results object is a container for results generated with ASR. It contains data and metadata describing results and the circumstances under which the result were generated, respectively. The metadata has to be set manually through the metadata property. The wrapped data can be accessed through the data property or directly as an attribute on the object.

The result object provides the means of presenting the wrapped data in different formats as obtained from the get_formats method. To implement a new webpanel, inherit from this class and overwrite the formats dictionary appropriately.

This object implements dict/namespace like default behaviour and contained data can be check with in (see “Examples” below).

Examples

>>> @prepare_result
... class Result(ASRResult):
...     a: int
...     key_descriptions = {'a': 'Some key description.'}
>>> result = Result.fromdata(a=1)
>>> result.metadata = {'resources': {'time': 'a good time.'}}
>>> result.a
1
>>> result['a']
1
>>> result.metadata
resources={'time': 'a good time.'}
>>> str(result)
'a=1'
>>> 'a' in result
True
>>> other_result = Result.fromdata(a=1)
>>> result == other_result
True
>>> print(format(result, 'json'))
{
 "object_id": "asr.core.results::Result",
 "constructor": "asr.core.results::Result",
 "args": [],
 "kwargs": {
  "data": {
   "a": 1
  },
  "metadata": {
   "resources": {
    "time": "a good time."
   }
  },
  "strict": true
 }
}

Class hierarchy

Inheritance diagram of ase2sprkkr.asr.core.results.ASRResult

Constructor

Parameters:
  • data (Dict[str, Any])

  • metadata (Dict[str, Any])

  • strict (bool | None)

__init__(data={}, metadata={}, strict=None)[source]

Instantiate result.

Parameters:
  • data (Dict[str, Any]) – Input data to be wrapped.

  • metadata (dict) – Dictionary containing metadata.

  • strict (bool or None) – Strictly enforce data entries in data.

version: int = 0
prev_version: Any = None
key_descriptions: Dict[str, str]
formats = {'dict': <ase2sprkkr.asr.core.results.DictEncoder object>, 'html': <ase2sprkkr.asr.core.results.HTMLEncoder object>, 'json': <ase2sprkkr.asr.core.results.JSONEncoder object>, 'str': <class 'str'>}
strict = False
classmethod fromdata(**data)[source]
classmethod get_obj_id()[source]
Return type:

str

property data: dict

Get result data.

property metadata: MetaData

Get result metadata.

classmethod from_format(input_data, format='json')[source]

Instantiate result from format.

classmethod get_formats()[source]

Get implemented result formats.

Return type:

dict

format_as(format='', *args, **kwargs)[source]

Format result in specific format.

Parameters:

format (str)

Return type:

Any

get_object_desc()[source]

Make ObjectDescription of this instance.

Return type:

ObjectDescription

todict()[source]
classmethod fromdict(dct)[source]
Parameters:

dct (dict)

get(key, *args)[source]

Wrap self.data.get.

values()[source]

Wrap self.data.values.

items()[source]

Wrap self.data.items.

keys()[source]

Wrap self.data.keys.