# 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/decorators.py
# def optimized(fn):
#     """Decorator that will call the optimized c++ version
#     of a pycast function if available rather than theo
#     original pycast function
# 
#     :param function fn: original pycast function
# 
#     :return: return the wrapped function
#     :rtype: function
#     """
# 
#     def _optimized(self, *args, **kwargs):
#         """ This method calls the pycastC function if
#         optimization is enabled and the pycastC function
#         is available.
# 
#         :param: PyCastObject self: reference to the calling object.
#                                     Needs to be passed to the pycastC function,
#                                     so that all uts members are available.
#         :param: list *args: list of arguments the function is called with.
#         :param: dict **kwargs: dictionary of parameter  names and values the function has been called with.
# 
#         :return result of the function call either from pycast or pycastC module.
#         :rtype: function
#         """
#         if self.optimizationEnabled:
#             class_name = self.__class__.__name__
#             module     = self.__module__.replace("pycast", "pycastC")
#             try:
#                 imported = __import__("%s.%s" % (module, class_name), globals(), locals(), [fn.__name__])
#                 function = getattr(imported, fn.__name__)
#                 return function(self, *args, **kwargs)
#             except ImportError:
#                 print  "[WARNING] Could not enable optimization for %s, %s" % (fn.__name__, self)
#                 return fn(self, *args, **kwargs)
#         else:
#             return fn(self, *args, **kwargs)
# 
#     setattr(_optimized, "__name__", fn.__name__)
#     setattr(_optimized, "__repr__", fn.__repr__)
#     setattr(_optimized, "__str__",  fn.__str__)
#     setattr(_optimized, "__doc__",  fn.__doc__)
# 
#     return _optimized


from pycast.common.pycastobject import PyCastObject
from pycast.common.decorators import optimized
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


class BaseErrorMeasure(PyCastObject):

    """Baseclass for all error measures."""

    def __init__(self, minimalErrorCalculationPercentage=60):
        """Initializes the error measure.

        :param integer minimalErrorCalculationPercentage:    The number of entries in an
            original TimeSeries that have to have corresponding partners in the calculated
            TimeSeries. Corresponding partners have the same time stamp.
            Valid values are in [0.0, 100.0].

        :raise: Raises a :py:exc:`ValueError` if minimalErrorCalculationPercentage is not
            in [0.0, 100.0].
        """
        super(BaseErrorMeasure, self).__init__()

        if not 0.0 <= minimalErrorCalculationPercentage <= 100.0:
            raise ValueError("minimalErrorCalculationPercentage has to be in [0.0, 100.0].")

        self._minimalErrorCalculationPercentage = minimalErrorCalculationPercentage / 100.0

        self._errorValues = []
        self._errorDates  = []


# 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/decorators.py
# def optimized(fn):
#     """Decorator that will call the optimized c++ version
#     of a pycast function if available rather than theo
#     original pycast function
# 
#     :param function fn: original pycast function
# 
#     :return: return the wrapped function
#     :rtype: function
#     """
# 
#     def _optimized(self, *args, **kwargs):
#         """ This method calls the pycastC function if
#         optimization is enabled and the pycastC function
#         is available.
# 
#         :param: PyCastObject self: reference to the calling object.
#                                     Needs to be passed to the pycastC function,
#                                     so that all uts members are available.
#         :param: list *args: list of arguments the function is called with.
#         :param: dict **kwargs: dictionary of parameter  names and values the function has been called with.
# 
#         :return result of the function call either from pycast or pycastC module.
#         :rtype: function
#         """
#         if self.optimizationEnabled:
#             class_name = self.__class__.__name__
#             module     = self.__module__.replace("pycast", "pycastC")
#             try:
#                 imported = __import__("%s.%s" % (module, class_name), globals(), locals(), [fn.__name__])
#                 function = getattr(imported, fn.__name__)
#                 return function(self, *args, **kwargs)
#             except ImportError:
#                 print  "[WARNING] Could not enable optimization for %s, %s" % (fn.__name__, self)
#                 return fn(self, *args, **kwargs)
#         else:
#             return fn(self, *args, **kwargs)
# 
#     setattr(_optimized, "__name__", fn.__name__)
#     setattr(_optimized, "__repr__", fn.__repr__)
#     setattr(_optimized, "__str__",  fn.__str__)
#     setattr(_optimized, "__doc__",  fn.__doc__)
# 
#     return _optimized


# Path: pycast/errors/baseerrormeasure.py
from pycast.common.pycastobject import PyCastObject
from pycast.common.decorators import optimized

# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


class BaseErrorMeasure(PyCastObject):

    """Baseclass for all error measures."""

    def __init__(self, minimalErrorCalculationPercentage=60):
        """Initializes the error measure.

        :param integer minimalErrorCalculationPercentage:    The number of entries in an
            original TimeSeries that have to have corresponding partners in the calculated
            TimeSeries. Corresponding partners have the same time stamp.
            Valid values are in [0.0, 100.0].

        :raise: Raises a :py:exc:`ValueError` if minimalErrorCalculationPercentage is not
            in [0.0, 100.0].
        """
        super(BaseErrorMeasure, self).__init__()

        if not 0.0 <= minimalErrorCalculationPercentage <= 100.0:
            raise ValueError("minimalErrorCalculationPercentage has to be in [0.0, 100.0].")

        self._minimalErrorCalculationPercentage = minimalErrorCalculationPercentage / 100.0

        self._errorValues = []
        self._errorDates  = []


    @optimized