Skip to content

Application

Module for Application class

Classes

Application

Application

Application for running command-line

Source code in decoimpact/business/application.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Application:
    """Application for running command-line"""

    def __init__(
        self,
        logger: ILogger,
        da_layer: IDataAccessLayer,
        model_builder: IModelBuilder,
    ):
        """Creates an application based on provided logger, data-access layer
        and model builder

        Args:
            logger (ILogger): Logger that takes care of logging
            da_layer (IDataAccessLayer): data-access layer for reading/writing
            model_builder (IModelBuilder): builder for creating a model based on
            IModelData
        """
        self._logger = logger
        self._da_layer = da_layer
        self._model_builder = model_builder

    def run(self, input_path: Path):
        """Runs application

        Args:
            input_path (Path): path to input file
        """

        model_data: IModelData = self._da_layer.read_input_file(input_path)
        model = self._model_builder.build_model(model_data)

        _ModelRunner.run_model(model, self._logger)

        if model.status == _ModelStatus.FINALIZED:
            self._da_layer.write_output_file(
                model.output_dataset, model_data.output_path
            )

__init__(logger: ILogger, da_layer: IDataAccessLayer, model_builder: IModelBuilder)

Creates an application based on provided logger, data-access layer and model builder

Parameters:

Name Type Description Default
logger ILogger

Logger that takes care of logging

required
da_layer IDataAccessLayer

data-access layer for reading/writing

required
model_builder IModelBuilder

builder for creating a model based on

required
Source code in decoimpact/business/application.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    logger: ILogger,
    da_layer: IDataAccessLayer,
    model_builder: IModelBuilder,
):
    """Creates an application based on provided logger, data-access layer
    and model builder

    Args:
        logger (ILogger): Logger that takes care of logging
        da_layer (IDataAccessLayer): data-access layer for reading/writing
        model_builder (IModelBuilder): builder for creating a model based on
        IModelData
    """
    self._logger = logger
    self._da_layer = da_layer
    self._model_builder = model_builder

run(input_path: Path)

Runs application

Parameters:

Name Type Description Default
input_path Path

path to input file

required
Source code in decoimpact/business/application.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def run(self, input_path: Path):
    """Runs application

    Args:
        input_path (Path): path to input file
    """

    model_data: IModelData = self._da_layer.read_input_file(input_path)
    model = self._model_builder.build_model(model_data)

    _ModelRunner.run_model(model, self._logger)

    if model.status == _ModelStatus.FINALIZED:
        self._da_layer.write_output_file(
            model.output_dataset, model_data.output_path
        )

IDataAccessLayer

Bases: ABC

Interface for the data layer

Source code in decoimpact/data/api/i_data_access_layer.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class IDataAccessLayer(ABC):
    """Interface for the data layer"""

    @abstractmethod
    def read_input_file(self, path: Path) -> IModelData:
        """Reads input file from provided path

        Args:
            path (str): path to input file

        Returns:
            IModelData: Data regarding model
        """

    @abstractmethod
    def read_input_dataset(self, dataset_data: IDatasetData) -> _xr.Dataset:
        """Uses the provided dataset_data to create/read a xarray Dataset

        Args:
            dataset_data (IDatasetData): dataset data for creating an
                                         xarray dataset

        Returns:
            _xr.Dataset: Dataset based on provided dataset_data
        """

    @abstractmethod
    def write_output_file(self, dataset: _xr.Dataset, path: Path) -> None:
        """Write output files to provided path

        Args:
            dataset (XArray dataset): dataset to write
            path (str): path to output file

        Returns:
            None
        """

read_input_dataset(dataset_data: IDatasetData) -> _xr.Dataset abstractmethod

Uses the provided dataset_data to create/read a xarray Dataset

Parameters:

Name Type Description Default
dataset_data IDatasetData

dataset data for creating an xarray dataset

required

Returns:

Type Description
_xr.Dataset

_xr.Dataset: Dataset based on provided dataset_data

Source code in decoimpact/data/api/i_data_access_layer.py
38
39
40
41
42
43
44
45
46
47
48
@abstractmethod
def read_input_dataset(self, dataset_data: IDatasetData) -> _xr.Dataset:
    """Uses the provided dataset_data to create/read a xarray Dataset

    Args:
        dataset_data (IDatasetData): dataset data for creating an
                                     xarray dataset

    Returns:
        _xr.Dataset: Dataset based on provided dataset_data
    """

read_input_file(path: Path) -> IModelData abstractmethod

Reads input file from provided path

Parameters:

Name Type Description Default
path str

path to input file

required

Returns:

Name Type Description
IModelData IModelData

Data regarding model

Source code in decoimpact/data/api/i_data_access_layer.py
27
28
29
30
31
32
33
34
35
36
@abstractmethod
def read_input_file(self, path: Path) -> IModelData:
    """Reads input file from provided path

    Args:
        path (str): path to input file

    Returns:
        IModelData: Data regarding model
    """

write_output_file(dataset: _xr.Dataset, path: Path) -> None abstractmethod

Write output files to provided path

Parameters:

Name Type Description Default
dataset XArray dataset

dataset to write

required
path str

path to output file

required

Returns:

Type Description
None

None

Source code in decoimpact/data/api/i_data_access_layer.py
50
51
52
53
54
55
56
57
58
59
60
@abstractmethod
def write_output_file(self, dataset: _xr.Dataset, path: Path) -> None:
    """Write output files to provided path

    Args:
        dataset (XArray dataset): dataset to write
        path (str): path to output file

    Returns:
        None
    """

ILogger

Bases: ABC

Interface for a Logger

Source code in decoimpact/crosscutting/i_logger.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class ILogger(ABC):
    """Interface for a Logger"""

    @abstractmethod
    def log_error(self, message: str) -> None:
        """Logs an error message

        Args:
            message (str): message to log
        """

    @abstractmethod
    def log_warning(self, message: str) -> None:
        """Logs a warning message

        Args:
            message (str): message to log
        """

    @abstractmethod
    def log_info(self, message: str) -> None:
        """Logs a info message

        Args:
            message (str): message to log
        """

    @abstractmethod
    def log_debug(self, message: str) -> None:
        """Logs a debug message

        Args:
            message (str): message to log
        """

log_debug(message: str) -> None abstractmethod

Logs a debug message

Parameters:

Name Type Description Default
message str

message to log

required
Source code in decoimpact/crosscutting/i_logger.py
45
46
47
48
49
50
51
@abstractmethod
def log_debug(self, message: str) -> None:
    """Logs a debug message

    Args:
        message (str): message to log
    """

log_error(message: str) -> None abstractmethod

Logs an error message

Parameters:

Name Type Description Default
message str

message to log

required
Source code in decoimpact/crosscutting/i_logger.py
21
22
23
24
25
26
27
@abstractmethod
def log_error(self, message: str) -> None:
    """Logs an error message

    Args:
        message (str): message to log
    """

log_info(message: str) -> None abstractmethod

Logs a info message

Parameters:

Name Type Description Default
message str

message to log

required
Source code in decoimpact/crosscutting/i_logger.py
37
38
39
40
41
42
43
@abstractmethod
def log_info(self, message: str) -> None:
    """Logs a info message

    Args:
        message (str): message to log
    """

log_warning(message: str) -> None abstractmethod

Logs a warning message

Parameters:

Name Type Description Default
message str

message to log

required
Source code in decoimpact/crosscutting/i_logger.py
29
30
31
32
33
34
35
@abstractmethod
def log_warning(self, message: str) -> None:
    """Logs a warning message

    Args:
        message (str): message to log
    """

IModelBuilder

Bases: ABC

Factory for creating models

Source code in decoimpact/business/workflow/i_model_builder.py
22
23
24
25
26
27
28
29
30
31
class IModelBuilder(ABC):
    """Factory for creating models"""

    @ abstractmethod
    def build_model(self, model_data: IModelData) -> IModel:
        """Creates an model based on model data

        Returns:
            IModel: instance of a model based on model data
        """

build_model(model_data: IModelData) -> IModel abstractmethod

Creates an model based on model data

Returns:

Name Type Description
IModel IModel

instance of a model based on model data

Source code in decoimpact/business/workflow/i_model_builder.py
25
26
27
28
29
30
31
@ abstractmethod
def build_model(self, model_data: IModelData) -> IModel:
    """Creates an model based on model data

    Returns:
        IModel: instance of a model based on model data
    """

IModelData

Bases: ABC

Interface for the model data

Source code in decoimpact/data/api/i_model_data.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class IModelData(ABC):
    """Interface for the model data"""

    @property
    @abstractmethod
    def name(self) -> str:
        """Name of the model"""

    @property
    @abstractmethod
    def datasets(self) -> List[IDatasetData]:
        """Datasets of the model"""

    @property
    @abstractmethod
    def output_path(self) -> Path:
        """Model path to the output file"""

    @property
    @abstractmethod
    def rules(self) -> List[IRuleData]:
        """Rules of the model"""

datasets: List[IDatasetData] abstractmethod property

Datasets of the model

name: str abstractmethod property

Name of the model

output_path: Path abstractmethod property

Model path to the output file

rules: List[IRuleData] abstractmethod property

Rules of the model