Skip to content

user_interface

SystemSpecsHandler(data=None, specs_file=None)

Load and decode system specifications for test-input generation.

Supports loading from a JSON file or inferring values from a dataset.

Attributes:

specs: dict Dictionary storing system specifications.

int

Number of features.

Methods:

get_n_features() Returns the number of features.

get_nominal_features() Returns the indices of all nominal features.

get_numerical_features() Returns the indices of all numerical features.

get_int_features() Returns the indices of all features with type 'int'.

extract_minmax_values() Extracts min and max values from specifications.

extract_input_types() Extracts value types from specifications.

extract_feature_names() Extracts feature names.

extract_feature_names_with_idx() Extract feature names along with their corresponding indices.

extract_feature_names_with_idx_reversed() Extract feature indices along with their corresponding names.

Loads specifications from a JSON file or infers them from a dataset.

For details on defining specifications in JSON, refer to README.md.

Example JSON structure: { "features": [ { "name": "feature_0_name", "min": 0, "max": 100, "type": "float" or "int", "nominal": true or false }, ... ] }

Parameters:

Name Type Description Default
data DataFrame | None

Dataset used to infer specifications if specs_file is not provided.

None
specs_file Path | None

JSON file containing system specifications.

None
Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def __init__(
    self,
    data: pl.DataFrame | None = None,
    specs_file: Path | None = None,
) -> None:
    """Loads specifications from a JSON file or infers them from a dataset.

    For details on defining specifications in JSON, refer to README.md.

    Example JSON structure:
    {
        "features": [
            {
                "name": "feature_0_name",
                "min": 0,
                "max": 100,
                "type": "float" or "int",
                "nominal": true or false
            },
            ...
        ]
    }

    Args:
        data: Dataset used to infer specifications if specs_file
            is not provided.
        specs_file: JSON file containing system specifications.
    """
    if data is not None:
        self._load_from_data(data)
    elif specs_file is not None:
        self._load_from_file(specs_file)
    else:
        msg = (
            "Either data or specs_file must be provided "
            "to load specifications."
        )
        raise ValueError(msg)

get_n_features()

Returns the number of features defined in the specifications.

Returns:

Type Description
int

Number of features.

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
185
186
187
188
189
190
191
def get_n_features(self) -> int:
    """Returns the number of features defined in the specifications.

    Returns:
        Number of features.
    """
    return len(self.specs["features"])

get_nominal_features()

Returns the indices of nominal features.

Returns:

Type Description
list

A list containing indices of nominal features.

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
193
194
195
196
197
198
199
200
201
202
203
def get_nominal_features(self) -> list:
    """Returns the indices of nominal features.

    Returns:
        A list containing indices of nominal features.
    """
    return [
        feature
        for feature in range(self.n_features)
        if self.specs["features"][feature]["nominal"]
    ]

get_numerical_features()

Returns the indices of numerical features.

Returns:

Type Description
list

A list containing indices of numerical features.

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
205
206
207
208
209
210
211
212
213
214
215
def get_numerical_features(self) -> list:
    """Returns the indices of numerical features.

    Returns:
        A list containing indices of numerical features.
    """
    return [
        feature
        for feature in range(self.n_features)
        if not self.specs["features"][feature]["nominal"]
    ]

get_int_features()

Returns the indices of features with type 'int'.

Returns:

Type Description
list

A list containing indices of integer-type features.

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
217
218
219
220
221
222
223
224
225
226
227
def get_int_features(self) -> list:
    """Returns the indices of features with type 'int'.

    Returns:
        A list containing indices of integer-type features.
    """
    return [
        feature
        for feature in range(self.n_features)
        if self.specs["features"][feature]["type"] == "int"
    ]

extract_minmax_values()

Extracts the min and max values for each feature.

Returns:

Type Description
dict

Dictionary mapping feature index to its min and max values.

Example

{ 0: {'min': 0.5, 'max': 5.3}, 1: {'min': 0, 'max': 500}, 2: {'min': 0.0, 'max': 10.0} }

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def extract_minmax_values(self) -> dict:
    """Extracts the min and max values for each feature.

    Returns:
        Dictionary mapping feature index to its min and max values.

    Example:
        {
            0: {'min': 0.5, 'max': 5.3},
            1: {'min': 0, 'max': 500},
            2: {'min': 0.0, 'max': 10.0}
        }
    """
    minmax_dict = {}
    for feature in range(self.n_features):
        min_value = self.specs["features"][feature]["min"]
        max_value = self.specs["features"][feature]["max"]
        feature_range = {"min": min_value, "max": max_value}
        minmax_dict[feature] = feature_range
    return minmax_dict

extract_input_types()

Extract the input type of each feature from the specifications.

Returns:

Type Description
dict

A dictionary mapping feature index to its type.

Example

{ 0: {'type': 'float'}, 1: {'type': 'int'}, 2: {'type': 'float'} }

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def extract_input_types(self) -> dict:
    """Extract the input type of each feature from the specifications.

    Returns:
        A dictionary mapping feature index to its type.

    Example:
            {
                0: {'type': 'float'},
                1: {'type': 'int'},
                2: {'type': 'float'}
            }
    """
    type_dict = {}
    for feature in range(self.n_features):
        input_type = self.specs["features"][feature]["type"]
        feature_type = {"type": input_type}
        type_dict.update({feature: feature_type})
    return type_dict

extract_feature_names()

Extract the name of each feature from the specifications.

Returns:

Type Description
list

A list of feature names.

Example

["pH", "temperature", "humidity"]

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
270
271
272
273
274
275
276
277
278
279
280
281
282
def extract_feature_names(self) -> list:
    """Extract the name of each feature from the specifications.

    Returns:
        A list of feature names.

    Example:
            ["pH", "temperature", "humidity"]
    """
    return [
        self.specs["features"][feature]["name"]
        for feature in range(self.n_features)
    ]

extract_feature_names_with_idx()

Extract feature names along with their corresponding indices.

Returns:

Type Description
dict

A dictionary mapping feature names to their indices.

Example

{ "pH": 0, "temperature": 1, "humidity": 2 }

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
def extract_feature_names_with_idx(self) -> dict:
    """Extract feature names along with their corresponding indices.

    Returns:
        A dictionary mapping feature names to their indices.

    Example:
            {
                "pH": 0,
                "temperature": 1,
                "humidity": 2
            }
    """
    return {
        self.specs["features"][feature]["name"]: feature
        for feature in range(self.n_features)
    }

extract_feature_names_with_idx_reversed()

Extract feature indices along with their corresponding names.

Returns:

Type Description
dict

A dictionary mapping feature indices to their names.

Example

{ 0: "pH", 1: "temperature", 2: "humidity" }

Source code in src/flowcean/testing/generator/ddtig/user_interface/specs_handler.py
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
def extract_feature_names_with_idx_reversed(self) -> dict:
    """Extract feature indices along with their corresponding names.

    Returns:
        A dictionary mapping feature indices to their names.

    Example:
            {
                0: "pH",
                1: "temperature",
                2: "humidity"
            }
    """
    return {
        feature: self.specs["features"][feature]["name"]
        for feature in range(self.n_features)
    }