Skip to main content
Version: 14

viktor.result

SetParamsResult

class viktor.result.SetParamsResult(params)

Bases: _SerializableObject

Container for the output of a SetParamsButton.

In order to set the content of the field Tab 1 > Section 1 > NumberField 1 to 1234 use the format:

SetParamsResult({
    "tab_1": {
        "section_1": {
            "numberfield_1": 1234
        }
    }
})

To clear one or more fields one has to explicitly set the params to the empty state. Note that the empty value is different for each field and can be found in their docs:

SetParamsResult({
    "tab_1": {
        "section_1": {
            "numberfield_1": None,
        }
    }
})
Parameters

params (Union[dict, Munch]) – the params you want to set. If a param is not specified, the value will be kept as is.

get(key)
Return type

Any

SetParametersResult

viktor.result.SetParametersResult

alias of SetParamsResult

DownloadResult

class viktor.result.DownloadResult(file_content=None, file_name=None, encoding='utf-8', *, zipped_files=None)

Bases: _SerializableObject

Container for the output of a DownloadButton.

Download of single file:

DownloadResult(file_content=my_file, file_name="my_file.txt")

Download of multiple files bundled in a zip-file:

DownloadResult(zipped_files={'my_file_1.txt': my_file_1, 'my_file_2.txt': my_file_2}, file_name="my_file.zip")
Parameters
  • file_content (Union[str, bytes, File, BytesIO]) – if type str and encoding is not utf-8, specify in additional argument. Mutual exclusive with ‘zipped_files’.

  • file_name (str) – name (including extension) to be used for download. In case of ‘zipped_files’, this is the name of the zip-file. May only consist of alphanumeric characters, underscores and dots (any other characters are converted to an underscore).

  • encoding (str) – optional argument to specify file encoding when file_content is provided with type str

  • zipped_files (Dict[str, Union[File, BytesIO]]) – a dict of {file name: content} to be bundled in a zip-file with file-name ‘file_name’. Mutual exclusive with ‘file_content’.

OptimizationResultElement

class viktor.result.OptimizationResultElement(params, analysis_result=None)
Parameters
  • params (Union[dict, Munch]) – a complete parameter set

  • analysis_result (dict) – the accompanying results.

For an example, see OptimizationResult

OptimisationResultElement

viktor.result.OptimisationResultElement

alias of OptimizationResultElement

OptimizationResult

class viktor.result.OptimizationResult(results, result_column_names_input=None, output_headers=None, image=None)

Bases: _SerializableObject

Container for the output of an OptimizationButton.

Parameters
  • results (List[OptimizationResultElement]) – list of results, order is kept in user interface.

  • result_column_names_input (List[str]) – specifies which input parameters should be shown the table. The parametrization class defined the label which is shown

  • output_headers (dict) – specifies which results should be shown in the results table. Key should match the key of the analysis_result inside each result. Value is the corresponding label which the end user sees.

  • image (ImageResult) – image which is shown next to the results. Could be JPG, PNG or SVG.

Example:

params1 = {'tab': {'section': {'field1': 'a', 'field2': 5}}}
params2 = {'tab': {'section': {'field1': 'b', 'field2': 8}}}
analysis1 = {'result1': 10, 'result2': 20}
analysis2 = {'result1': 100, 'result2': 150}

results = [
    OptimizationResultElement(params1, analysis1),
    OptimizationResultElement(params2, analysis2),
]

OptimizationResult(
    results, result_column_names_input=['tab.section.field1'], output_headers={'result1': 'Result 1'}
)

This renders as the following table for the end-user:

#

Field 1

Result 1

1

a

10

2

b

100

OptimisationResult

viktor.result.OptimisationResult

alias of OptimizationResult

ViktorResult

class viktor.result.ViktorResult(optimisation_result=None, set_parameters_result=None, download_result=None, *, optimization_result=None, set_params_result=None)

Bases: _SerializableObject

Standard output object of a ViktorController method, which serialises and combines several individual results into the standard automation output. All inputs are optional to facilitate many combinations of results where needed in the future. Currently, the serialisation only accounts for the following (backward compatible) combinations:

  • a single optimization result

  • a single set_params result

  • a single download result

Parameters