src.fairreckitlib.core.config.config_object

This module contains the base functionality for an object's configuration.

Classes:

ObjectConfig: base class configuration for an object with a name and parameters.

Functions:

object_config_list_to_yml_format: convert list of ObjectConfig's to a yml format.

This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)

 1"""This module contains the base functionality for an object's configuration.
 2
 3Classes:
 4
 5    ObjectConfig: base class configuration for an object with a name and parameters.
 6
 7Functions:
 8
 9    object_config_list_to_yml_format: convert list of ObjectConfig's to a yml format.
10
11This program has been developed by students from the bachelor Computer Science at
12Utrecht University within the Software Project course.
13© Copyright Utrecht University (Department of Information and Computing Sciences)
14"""
15
16from dataclasses import dataclass
17from typing import Any, Dict
18
19from ..core_constants import KEY_NAME, KEY_PARAMS
20from .config_yml import YmlConfig
21
22
23@dataclass
24class ObjectConfig(YmlConfig):
25    """Base Object Configuration.
26
27    name: the name of the object.
28    params: the parameters of the object.
29    """
30
31    name: str
32    params: Dict[str, Any]
33
34    def to_yml_format(self) -> Dict[str, Any]:
35        """Format object configuration to a yml compatible dictionary.
36
37        Returns:
38            a dictionary containing the object configuration.
39        """
40        yml_format = { KEY_NAME: self.name }
41
42        # only include object params if it has entries
43        if len(self.params) > 0:
44            yml_format[KEY_PARAMS] = dict(self.params)
45
46        return yml_format
@dataclass
class ObjectConfig(src.fairreckitlib.core.config.config_yml.YmlConfig):
24@dataclass
25class ObjectConfig(YmlConfig):
26    """Base Object Configuration.
27
28    name: the name of the object.
29    params: the parameters of the object.
30    """
31
32    name: str
33    params: Dict[str, Any]
34
35    def to_yml_format(self) -> Dict[str, Any]:
36        """Format object configuration to a yml compatible dictionary.
37
38        Returns:
39            a dictionary containing the object configuration.
40        """
41        yml_format = { KEY_NAME: self.name }
42
43        # only include object params if it has entries
44        if len(self.params) > 0:
45            yml_format[KEY_PARAMS] = dict(self.params)
46
47        return yml_format

Base Object Configuration.

name: the name of the object. params: the parameters of the object.

ObjectConfig(name: str, params: Dict[str, Any])
def to_yml_format(self) -> Dict[str, Any]:
35    def to_yml_format(self) -> Dict[str, Any]:
36        """Format object configuration to a yml compatible dictionary.
37
38        Returns:
39            a dictionary containing the object configuration.
40        """
41        yml_format = { KEY_NAME: self.name }
42
43        # only include object params if it has entries
44        if len(self.params) > 0:
45            yml_format[KEY_PARAMS] = dict(self.params)
46
47        return yml_format

Format object configuration to a yml compatible dictionary.

Returns: a dictionary containing the object configuration.