# Path: pycast/common/pycastobject.py
# class PyCastObject(object):
# 
# 
#     """The base class for all pycast objects.
# 
#     This class is used to introduce a common interface for potential
#     C/C++/OpenCL optimization within pycast, as well as other common
#     tasks.
#     """
# 
#     # stores, if pycast should only create optimized instances.
#     # default = False
#     _globalOptimize = False
# 
#     def __init__(self):
#         """Initializes the PyCastObject."""
#         super(PyCastObject, self).__init__()
#         self.optimizationEnabled = False
# 
#         if PyCastObject._globalOptimize:
#             self._enable_instance_optimization()
# 
#     def _enable_instance_optimization(self):
#         """Enables the optimization for the PyCastObject instance.
# 
#         :warning:    Do not forget to implement the disable_instance_optimization()
#             as well.
#         """
#         self.optimizationEnabled = True
# 
#     def _disable_instance_optimization(self):
#         """Disables the optimization for the PyCastObject instance."""
#         self.optimizationEnabled = False
# 
#     @classmethod
#     def enable_global_optimization(cls):
#         """Enables the global optimization of pycast methods, if possible.
# 
#         By default, optimization is turned off.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = True
# 
#     @classmethod
#     def disable_global_optimization(cls):
#         """Disables the global optimization of pycast methods.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = False
# 
# Path: pycast/common/timeseries.py
# _STR_EPOCHS = "UNIX-epochs"
# class TimeSeries(PyCastObject):
# class MultiDimensionalTimeSeries(TimeSeries):
#     def __init__(self, isNormalized=False, isSorted=False):
#     def set_timeformat(self, tsformat=None):
#     def to_gnuplot_datafile(self, datafilepath):
#     def __copy__(self):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def __str__(self):
#     def __add__(self, otherTimeSeries):
#     def __len__(self):
#     def __eq__(self, otherTimeSeries):
#     def __ne__(self, otherTimeSeries):
#     def __iter__(self):
#     def __getitem__(self, index):
#     def __setitem__(self, index, value):
#     def convert_timestamp_to_epoch(cls, timestamp, tsformat):
#     def convert_epoch_to_timestamp(cls, timestamp, tsformat):
#     def add_entry(self, timestamp, data):
#     def sort_timeseries(self, ascending=True):
#     def sorted_timeseries(self, ascending=True):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
#     def is_normalized(self):
#     def _check_normalization(self):
#     def is_sorted(self):
#     def apply(self, method):
#     def sample(self, percentage):
#     def __init__(self, dimensions=1, isNormalized=False, isSorted=False):
#     def dimension_count(self):
#     def add_entry(self, timestamp, data):
#     def sorted_timeseries(self, ascending=True):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None, dimensions=1):
#     def __add__(self, otherTimeSeries):
#     def __eq__(self, otherTimeSeries):
#     def __copy__(self):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def to_gnuplot_datafile(self, datafilepath):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
# 
# Path: pycast/errors/meansigneddifferenceerror.py
# MSD = MeanSignedDifferenceError


from pycast.common.pycastobject import PyCastObject
from pycast.common.timeseries import TimeSeries, FusionMethods
from pycast.errors.meansigneddifferenceerror import MSD
        """Calculate and return the parameters for the regression line

        Return the parameter for the line describing the relationship
        between the input variables.

        :param Timeseries independentTs: The Timeseries used for the
            independent variable (x-axis). The Timeseries must have
            at least 2 datapoints with different dates and values
        :param Timeseries dependentTs: The Timeseries used as the
            dependent variable (y-axis). The Timeseries must have
            at least 2 datapoints, which dates match with independentTs

        :return:    A tuple containing the y-axis intercept and the slope
                    used to execute the regression
        :rtype:     tuple
        :raise: Raises an :py:exc:`ValueError` if
                - independentTs and dependentTs have not at least two matching dates
                - independentTs has only one distinct value
                - The dates in one or both Timeseries are not distinct.
        """
        listX, listY = self.match_time_series(independentTs, dependentTs)

        if len(listX) == 0 or len(listY) == 0:
            raise ValueError("Lists need to have some equal dates or cannot be empty")
        if len(listX) != len(listY):
            raise ValueError("Each Timeseries need to have distinct dates")

        xValues = map(lambda item: item[1], listX)
        yValues = map(lambda item: item[1], listY)


# Path: pycast/common/pycastobject.py
# class PyCastObject(object):
# 
# 
#     """The base class for all pycast objects.
# 
#     This class is used to introduce a common interface for potential
#     C/C++/OpenCL optimization within pycast, as well as other common
#     tasks.
#     """
# 
#     # stores, if pycast should only create optimized instances.
#     # default = False
#     _globalOptimize = False
# 
#     def __init__(self):
#         """Initializes the PyCastObject."""
#         super(PyCastObject, self).__init__()
#         self.optimizationEnabled = False
# 
#         if PyCastObject._globalOptimize:
#             self._enable_instance_optimization()
# 
#     def _enable_instance_optimization(self):
#         """Enables the optimization for the PyCastObject instance.
# 
#         :warning:    Do not forget to implement the disable_instance_optimization()
#             as well.
#         """
#         self.optimizationEnabled = True
# 
#     def _disable_instance_optimization(self):
#         """Disables the optimization for the PyCastObject instance."""
#         self.optimizationEnabled = False
# 
#     @classmethod
#     def enable_global_optimization(cls):
#         """Enables the global optimization of pycast methods, if possible.
# 
#         By default, optimization is turned off.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = True
# 
#     @classmethod
#     def disable_global_optimization(cls):
#         """Disables the global optimization of pycast methods.
# 
#         :note:    Only new created instances will be affected.
#         """
#         cls._globalOptimize = False
# 
# Path: pycast/common/timeseries.py
# _STR_EPOCHS = "UNIX-epochs"
# class TimeSeries(PyCastObject):
# class MultiDimensionalTimeSeries(TimeSeries):
#     def __init__(self, isNormalized=False, isSorted=False):
#     def set_timeformat(self, tsformat=None):
#     def to_gnuplot_datafile(self, datafilepath):
#     def __copy__(self):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def __str__(self):
#     def __add__(self, otherTimeSeries):
#     def __len__(self):
#     def __eq__(self, otherTimeSeries):
#     def __ne__(self, otherTimeSeries):
#     def __iter__(self):
#     def __getitem__(self, index):
#     def __setitem__(self, index, value):
#     def convert_timestamp_to_epoch(cls, timestamp, tsformat):
#     def convert_epoch_to_timestamp(cls, timestamp, tsformat):
#     def add_entry(self, timestamp, data):
#     def sort_timeseries(self, ascending=True):
#     def sorted_timeseries(self, ascending=True):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
#     def is_normalized(self):
#     def _check_normalization(self):
#     def is_sorted(self):
#     def apply(self, method):
#     def sample(self, percentage):
#     def __init__(self, dimensions=1, isNormalized=False, isSorted=False):
#     def dimension_count(self):
#     def add_entry(self, timestamp, data):
#     def sorted_timeseries(self, ascending=True):
#     def to_twodim_list(self):
#     def from_twodim_list(cls, datalist, tsformat=None, dimensions=1):
#     def __add__(self, otherTimeSeries):
#     def __eq__(self, otherTimeSeries):
#     def __copy__(self):
#     def initialize_from_sql_cursor(self, sqlcursor):
#     def to_gnuplot_datafile(self, datafilepath):
#     def normalize(self, normalizationLevel="minute", fusionMethod="mean", interpolationMethod="linear"):
# 
# Path: pycast/errors/meansigneddifferenceerror.py
# MSD = MeanSignedDifferenceError


# Path: pycast/methods/regression.py
from pycast.common.pycastobject import PyCastObject
from pycast.common.timeseries import TimeSeries, FusionMethods
from pycast.errors.meansigneddifferenceerror import MSD

        """Calculate and return the parameters for the regression line

        Return the parameter for the line describing the relationship
        between the input variables.

        :param Timeseries independentTs: The Timeseries used for the
            independent variable (x-axis). The Timeseries must have
            at least 2 datapoints with different dates and values
        :param Timeseries dependentTs: The Timeseries used as the
            dependent variable (y-axis). The Timeseries must have
            at least 2 datapoints, which dates match with independentTs

        :return:    A tuple containing the y-axis intercept and the slope
                    used to execute the regression
        :rtype:     tuple
        :raise: Raises an :py:exc:`ValueError` if
                - independentTs and dependentTs have not at least two matching dates
                - independentTs has only one distinct value
                - The dates in one or both Timeseries are not distinct.
        """
        listX, listY = self.match_time_series(independentTs, dependentTs)

        if len(listX) == 0 or len(listY) == 0:
            raise ValueError("Lists need to have some equal dates or cannot be empty")
        if len(listX) != len(listY):
            raise ValueError("Each Timeseries need to have distinct dates")

        xValues = map(lambda item: item[1], listX)
        yValues = map(lambda item: item[1], listY)


        xMean = FusionMethods["mean"](xValues)