Accessing the scenario configuration: components and parameters#

It is possible to access the Scenario of the job, which contains the configuration of Component objects, and Parameter objects, related to that scenario.

Access of scenario, components and parameters#

Example: Use configuration stored in parameters and components to compute a result.#
with JobClient.connect() as job:
    my_component = job.scenario.components["my_component"]
    my_cool_subcomponents = my_component.components["cool_component_name"]
    my_nifty_subcomponents = my_component.components["nifty_component_name"]
    cool_result = 0.0
    for cool_subcomponent in my_cool_subcomponents:
        cool_subcomponent_parameter = cool_subcomponent.parameters["coolness"]
        cool_result += cool_subcomponent_parameter.value
    ... # continue your job code

Accessing subcomponents#

Accessing subcomponents is a bit more complicated. Sub-components exist inside other components, and are grouped by the name of the component type.

Example: Use the configuration stored in subcomponents to compute a result.#
with JobClient.connect() as job:
    my_component = job.scenario.components["my_component"]
    my_cool_subcomponents = my_component.components["cool_component_name"]
    my_nifty_subcomponents = my_component.components["nifty_component_name"]
    cool_result = 0.0
    for cool_subcomponent in my_cool_subcomponents:
        cool_subcomponent_parameter = cool_subcomponent.parameters["coolness"]
        cool_result += cool_subcomponent_parameter.value
    ... # continue your job code

Accessing job parameters#

The job itself, and can also have parameters associated with it. They are accessed through numerous.sdk.connect.job_client.JobClient.parameters, which is a shortcut for parameters on the numerous.sdk.connect.job_client.JobClient.job property.

Example: Log the value of the job parameter with ID my_job_parameter_id#
with JobClient.connect() as job_client:
    my_job_parameter = job_client.parameters["my_job_parameter_id"]
    my_same_job_parameter = job_client.job.parameters["my_job_parameter_id"]  # same!
    job_client.log.info("My Job Parameter = %s", my_job_parameter.value)

Accessing parameter values#

You can access a parameters value, with the value property, is is shown in the examples above.

The type of the value property depends on the parameter type chosen when designing the tool in numerous.

Some correspond to simple values (e.g. string corresponds to str, and number corresponds to float), while others are more complex. Below is an overview of the different parameter types, and how they are mapped into python values.

Parameter type

Python value type

Description

number

float

A simple number value.

string

str

A simpel text value.

boolean

bool

A simple boolean value.

selecter

Selection

A selection has a value of type str, float or number, and the id of the selected element.

month

Month

A wrapper for the selected month as an integer number.

config

Config

file

FileReference

Has helper methods to read the uploaded files referenced.

table

Not yet implemented.

time_value

TimeValue

Contains a timedelta, the total seconds, and specified unit of the time value.

json

any

Contains the parsed JSON document, as parsed by json.loads.