Source code for kappa_sdk.user_tasks.simulation.services
import datetime
from ..context import Context
from .event_publisher import EventPublisherSimulated
from ..scheduler import Scheduler
from .log import LogSimulated
from ..data_query_service import DataQueryService
from ..data_command_service import DataCommandService
from ..parameters import Parameters
from ..task_settings import TaskSettings
from ...connection import Connection
from ...field import Field
from ...well import Well
from ...unit_converter import UnitConverter
from ...rest_api import RestAPI
from ...enumerator import TimeRangeEnum, ExtrapolationMethodEnum, InterpolationMethodEnum, DataEnumerator, DataEnumeratorSettings
from .simulated_user_task import SimulatedUserTask
from ...user_task import UserTask
from typing import Dict, Optional
from ..services import Services
from ..redefinition import Redefinition
[docs]
class ServicesSimulated(Services):
[docs]
    def __init__(self, connection: Connection, context: Context, parameters: Parameters, name: str, outputs: Optional[Dict[str, Dict[str, str]]] = None, redefinition: Optional[Redefinition] = None):
        self.__connection: Connection = connection
        self.__event_publisher: EventPublisherSimulated = EventPublisherSimulated()
        self.__context: Context = context
        self.__redefinition: Optional[Redefinition] = redefinition
        if self.__context is not None and self.__context.field_id is not None:
            try:
                self.__field: Field = next(x for x in self.__connection.get_fields() if x.id == self.__context.field_id)
            except StopIteration:
                raise ValueError('Field {} cannot be found'.format(self.__context.field_id))
        else:
            raise ValueError('Field id must be specified')
        if self.__context is not None and self.__context.field_id is not None and self.__context.well_id is not None:
            try:
                self.__well: Well = next(x for x in self.__field.wells if x.id == self.__context.well_id)
            except StopIteration:
                raise ValueError('Well {} cannot be found'.format(self.__context.well_id))
        else:
            raise ValueError('Well id must be specified')
        outputs_data = []
        if outputs is not None:
            for output_name in list(outputs.keys()):
                if outputs[output_name]["type"] == "dataset":
                    try:
                        outputs_data.append(next(x for x in self.__well.data if x.name == str(output_name)))
                    except StopIteration:
                        raise ValueError('Output Data {} cannot be found'.format(output_name))
        self.__rest_api: RestAPI = self.__connection.rest_api
        self.__settings: TaskSettings = TaskSettings(TimeRangeEnum.total, ExtrapolationMethodEnum.zero, InterpolationMethodEnum.absent_value)
        self.__data_command_service: DataCommandService = DataCommandService(connection._Connection__cluster_apis.data_api, connection._Connection__connection_dto_converter.field_dto_converter.well_dto_converter.data_dto_converter)  # type:ignore[attr-defined]
        self.__scheduler: Scheduler = Scheduler()
        self.__log: LogSimulated = LogSimulated()
        data_enumerator_settings = DataEnumeratorSettings(self.__settings.time_range,
                                                          datetime.datetime.min,
                                                          datetime.datetime.max,
                                                          self.__settings.extrapolation_method,
                                                          self.__settings.absent_data_treatment,
                                                          100000)
        self.__data_enumerator: DataEnumerator = DataEnumerator(data_enumerator_settings, self.__rest_api)
        self.__parameters: Parameters = parameters
        self.__data_query_service: DataQueryService = DataQueryService(connection._Connection__cluster_apis.data_api, connection.unit_converter)  # type:ignore[attr-defined]
        self.__user_task: UserTask = SimulatedUserTask(self.well, name, outputs_data) 
    @property
    def rest_api(self) -> RestAPI:
        """ Gets the rest_api of the :class:`Service`.
        """
        return self.__connection.rest_api
    @property
    def unit_converter(self) -> UnitConverter:
        """ Gets the unit converter of the :class:`Service`.
        """
        return self.__connection.unit_converter
    @property
    def context(self) -> Context:
        """ Gets the context of the :class:`Service`.
        """
        return self.__context
    @property
    def redefinition(self) -> Optional[Redefinition]:
        """ Gets the redefine setting of the user task.
        """
        return self.__redefinition
    @property
    def field(self) -> Field:
        """ Gets the field of the :class:`Service`.
        """
        return self.__field
    @property
    def well(self) -> Well:
        """ Gets the well of the :class:`Service`.
        """
        return self.__well
    @property
    def event_publisher(self) -> EventPublisherSimulated:
        """ Gets the event_publisher of the :class:`Service`.
        """
        return self.__event_publisher
    @property
    def data_enumerator(self) -> DataEnumerator:
        """ Gets the data_enumerator of the :class:`Service`.
        """
        return self.__data_enumerator
    @property
    def data_command_service(self) -> DataCommandService:
        """ Gets the well of the :class:`Service`.
        """
        return self.__data_command_service
    @property
    def log(self) -> LogSimulated:
        """ Gets the log of the :class:`Service`.
        """
        return self.__log
    @property
    def scheduler(self) -> Scheduler:
        """ Gets the scheduler of the :class:`Service`.
        """
        return self.__scheduler
    @property
    def parameters(self) -> Parameters:
        """ Gets the parameters of this :class:`Service`.
        """
        return self.__parameters
    @property
    def data_query_service(self) -> DataQueryService:
        """ Gets the data query service of this :class:'Service'.
        """
        return self.__data_query_service
    @property
    def user_task(self) -> UserTask:
        """ Gets the user task of this :class:'Service'.
        """
        return self.__user_task