Module tim_client.prediction

Expand source code
from typing import Dict, List, Tuple
from pandas import DataFrame
import logging
from logging import Logger

from tim_client.helpers import dict_to_dataframe, aggregated_predictions_to_dataframes


class Prediction:
    """TIM Prediction result."""

    __logger: Logger = None
    status: str = None
    request_uuid: str = None
    events: List[Dict] = None
    result_explanations: List[Dict] = None
    progress: float = None
    engine_result: str = None
    requested_configuration: Dict = None
    prediction: DataFrame = None
    aggregated_predictions: List[Dict] = None
    raw_predictions: List[Dict] = None
    data_difficulty: float = None

    def __init__(self,
                 status: str,
                 request_uuid: str,
                 events: List[Dict] = None,
                 result_explanations: List[Dict] = None,
                 progress: float = None,
                 engine_result: str = None,
                 requested_configuration: Dict = None,
                 prediction: DataFrame = None,
                 aggregated_predictions: List[Dict] = None,
                 raw_predictions: List[Dict] = None,
                 data_difficulty: float = None,
                 logger: Logger = None
                 ):
        self.status = status
        self.request_uuid = request_uuid
        self.events = events
        self.result_explanations = result_explanations
        self.progress = progress
        self.engine_result = engine_result
        self.requested_configuration = requested_configuration
        self.prediction = prediction
        self.aggregated_predictions = aggregated_predictions
        self.raw_predictions = raw_predictions
        self.data_difficulty = data_difficulty
        
        if self.__logger is None:
            self.__logger = logging.getLogger(__name__)

    def __str__(self) -> str:
        return f'Prediction {self.request_uuid}: {self.status}'

    def get_prediction(self) -> DataFrame:
        """Return pandas DataFrame containing predicton values."""
        return self.prediction
    
    @classmethod
    def from_json(cls, data):
        return cls(
            status=data['status'] if 'status' in data else None,
            request_uuid=data['requestUUID'] if 'requestUUID' in data else None,
            events=data['events'] if 'events' in data else None,
            result_explanations=data['resultExplanations'] if 'resultExplanations' in data else None,
            progress=float(data['progress']) if 'progress' in data else None,
            engine_result=data['engineResult'] if 'engineResult' in data else None,
            requested_configuration=data['requestedConfiguration'] if 'requestedConfiguration' in data else None,
            prediction=dict_to_dataframe(data['prediction']['values'], {0: 'Timestamp', 1: 'Prediction'}) if 'prediction' in data and 'values' in data['prediction'] else None,
            aggregated_predictions=aggregated_predictions_to_dataframes(data['aggregatedPredictions']) if 'aggregatedPredictions' in data else None,
            raw_predictions=data['rawPredictions'] if 'rawPredictions' in data else None,
            data_difficulty=float(data['dataDifficulty']) if 'dataDifficulty' in data else None
        )

Classes

class Prediction (status: str, request_uuid: str, events: List[Dict] = None, result_explanations: List[Dict] = None, progress: float = None, engine_result: str = None, requested_configuration: Dict = None, prediction: pandas.core.frame.DataFrame = None, aggregated_predictions: List[Dict] = None, raw_predictions: List[Dict] = None, data_difficulty: float = None, logger: logging.Logger = None)

TIM Prediction result.

Expand source code
class Prediction:
    """TIM Prediction result."""

    __logger: Logger = None
    status: str = None
    request_uuid: str = None
    events: List[Dict] = None
    result_explanations: List[Dict] = None
    progress: float = None
    engine_result: str = None
    requested_configuration: Dict = None
    prediction: DataFrame = None
    aggregated_predictions: List[Dict] = None
    raw_predictions: List[Dict] = None
    data_difficulty: float = None

    def __init__(self,
                 status: str,
                 request_uuid: str,
                 events: List[Dict] = None,
                 result_explanations: List[Dict] = None,
                 progress: float = None,
                 engine_result: str = None,
                 requested_configuration: Dict = None,
                 prediction: DataFrame = None,
                 aggregated_predictions: List[Dict] = None,
                 raw_predictions: List[Dict] = None,
                 data_difficulty: float = None,
                 logger: Logger = None
                 ):
        self.status = status
        self.request_uuid = request_uuid
        self.events = events
        self.result_explanations = result_explanations
        self.progress = progress
        self.engine_result = engine_result
        self.requested_configuration = requested_configuration
        self.prediction = prediction
        self.aggregated_predictions = aggregated_predictions
        self.raw_predictions = raw_predictions
        self.data_difficulty = data_difficulty
        
        if self.__logger is None:
            self.__logger = logging.getLogger(__name__)

    def __str__(self) -> str:
        return f'Prediction {self.request_uuid}: {self.status}'

    def get_prediction(self) -> DataFrame:
        """Return pandas DataFrame containing predicton values."""
        return self.prediction
    
    @classmethod
    def from_json(cls, data):
        return cls(
            status=data['status'] if 'status' in data else None,
            request_uuid=data['requestUUID'] if 'requestUUID' in data else None,
            events=data['events'] if 'events' in data else None,
            result_explanations=data['resultExplanations'] if 'resultExplanations' in data else None,
            progress=float(data['progress']) if 'progress' in data else None,
            engine_result=data['engineResult'] if 'engineResult' in data else None,
            requested_configuration=data['requestedConfiguration'] if 'requestedConfiguration' in data else None,
            prediction=dict_to_dataframe(data['prediction']['values'], {0: 'Timestamp', 1: 'Prediction'}) if 'prediction' in data and 'values' in data['prediction'] else None,
            aggregated_predictions=aggregated_predictions_to_dataframes(data['aggregatedPredictions']) if 'aggregatedPredictions' in data else None,
            raw_predictions=data['rawPredictions'] if 'rawPredictions' in data else None,
            data_difficulty=float(data['dataDifficulty']) if 'dataDifficulty' in data else None
        )

Class variables

var aggregated_predictions : List[Dict]
var data_difficulty : float
var engine_result : str
var events : List[Dict]
var prediction : pandas.core.frame.DataFrame
var progress : float
var raw_predictions : List[Dict]
var request_uuid : str
var requested_configuration : Dict
var result_explanations : List[Dict]
var status : str

Static methods

def from_json(data)
Expand source code
@classmethod
def from_json(cls, data):
    return cls(
        status=data['status'] if 'status' in data else None,
        request_uuid=data['requestUUID'] if 'requestUUID' in data else None,
        events=data['events'] if 'events' in data else None,
        result_explanations=data['resultExplanations'] if 'resultExplanations' in data else None,
        progress=float(data['progress']) if 'progress' in data else None,
        engine_result=data['engineResult'] if 'engineResult' in data else None,
        requested_configuration=data['requestedConfiguration'] if 'requestedConfiguration' in data else None,
        prediction=dict_to_dataframe(data['prediction']['values'], {0: 'Timestamp', 1: 'Prediction'}) if 'prediction' in data and 'values' in data['prediction'] else None,
        aggregated_predictions=aggregated_predictions_to_dataframes(data['aggregatedPredictions']) if 'aggregatedPredictions' in data else None,
        raw_predictions=data['rawPredictions'] if 'rawPredictions' in data else None,
        data_difficulty=float(data['dataDifficulty']) if 'dataDifficulty' in data else None
    )

Methods

def get_prediction(self) -> pandas.core.frame.DataFrame

Return pandas DataFrame containing predicton values.

Expand source code
def get_prediction(self) -> DataFrame:
    """Return pandas DataFrame containing predicton values."""
    return self.prediction