# Path: hydra_base/exceptions.py
# class HydraError(Exception):
#     __error_code__ = None
# 
#     def __init__(self, message="A hydra error has occurred"):
#         # Call the base class constructor with the parameters it needs
#         self.code = error_codes.get(self.__error_code__, '0000')
#         self.message = message # Added for Py3
#         super(HydraError, self).__init__({"message": message, "code": self.code})
# 
# class ValidationError(HydraError):
#     pass
# 
# Path: hydra_base/util/hydra_dateutil.py
# def get_datetime(timestamp):
#     """
#         Turn a string timestamp into a date time. First tries to use dateutil.
#         Failing that it tries to guess the time format and converts it manually
#         using stfptime.
# 
#         @returns: A timezone unaware timestamp.
#     """
#     timestamp_is_float = False
#     try:
#         float(timestamp)
#         timestamp_is_float = True
#     except (ValueError, TypeError):
#         pass
# 
#     if timestamp_is_float == True:
#         raise ValueError("Timestamp %s is a float"%(timestamp,))
# 
#     #First try to use date util. Failing that, continue
#     try:
#         parsed_dt = parse(timestamp, dayfirst=False)
#         return parsed_dt.astimezone(pytz.utc)
#     except:
#         pass
# 
#     if isinstance(timestamp, datetime):
#         return timestamp.astimezone(pytz.utc)
# 
#     fmt = guess_timefmt(timestamp)
#     if fmt is None:
#         fmt = FORMAT
# 
#     # and proceed as usual
#     try:
#         ts_time = datetime.strptime(timestamp, fmt)
#     except ValueError as e:
#         if e.message.split(' ', 1)[0].strip() == 'unconverted':
#             utcoffset = e.message.split()[3].strip()
#             timestamp = timestamp.replace(utcoffset, '')
#             ts_time = datetime.strptime(timestamp, fmt)
#             # Apply offset
#             tzoffset = timedelta(hours=int(utcoffset[0:3]),
#                                           minutes=int(utcoffset[3:5]))
#             ts_time -= tzoffset
#         else:
#             raise e
# 
#     return ts_time


import logging
import numpy as np
import pandas as pd
import re
import json
from decimal import Decimal
from operator import mul
from ..exceptions import HydraError, ValidationError
from functools import reduce
from hydra_base.util.hydra_dateutil import get_datetime
    LESSTHANEQ = validate_LESSTHANEQ,
    GREATERTHAN = validate_GREATERTHAN,
    GREATERTHANEQ = validate_GREATERTHANEQ,
    MULTIPLEOF = validate_MULTIPLEOF,
    SUMTO = validate_SUMTO,
    INCREASING = validate_INCREASING,
    DECREASING = validate_DECREASING,
    EQUALTIMESTEPS = validate_EQUALTIMESTEPS,
    NOTNULL        = validate_NOTNULL,
    ISNULL         = validate_ISNULL,
)

def validate_value(restriction_dict, inval):
    if len(restriction_dict) == 0:
        return

    try:
        for restriction_type, restriction in restriction_dict.items():
            func = validation_func_map.get(restriction_type)
            if func is None:
                raise Exception("Validation type {} does not exist".format(restriction_type,))
            func(inval, restriction)
    except ValidationError as e:
        log.exception(e)
        err_val = re.sub('\s+', ' ', str(inval)).strip()
        if len(err_val) > 60:
            err_val = "{}...".format(err_val[:60])
        raise HydraError("Validation error ({}). Val {} does not conform with rule {}".format(restriction_type, err_val, e.args[0]))
    except Exception as e:
        log.exception(e)

# Path: hydra_base/exceptions.py
# class HydraError(Exception):
#     __error_code__ = None
# 
#     def __init__(self, message="A hydra error has occurred"):
#         # Call the base class constructor with the parameters it needs
#         self.code = error_codes.get(self.__error_code__, '0000')
#         self.message = message # Added for Py3
#         super(HydraError, self).__init__({"message": message, "code": self.code})
# 
# class ValidationError(HydraError):
#     pass
# 
# Path: hydra_base/util/hydra_dateutil.py
# def get_datetime(timestamp):
#     """
#         Turn a string timestamp into a date time. First tries to use dateutil.
#         Failing that it tries to guess the time format and converts it manually
#         using stfptime.
# 
#         @returns: A timezone unaware timestamp.
#     """
#     timestamp_is_float = False
#     try:
#         float(timestamp)
#         timestamp_is_float = True
#     except (ValueError, TypeError):
#         pass
# 
#     if timestamp_is_float == True:
#         raise ValueError("Timestamp %s is a float"%(timestamp,))
# 
#     #First try to use date util. Failing that, continue
#     try:
#         parsed_dt = parse(timestamp, dayfirst=False)
#         return parsed_dt.astimezone(pytz.utc)
#     except:
#         pass
# 
#     if isinstance(timestamp, datetime):
#         return timestamp.astimezone(pytz.utc)
# 
#     fmt = guess_timefmt(timestamp)
#     if fmt is None:
#         fmt = FORMAT
# 
#     # and proceed as usual
#     try:
#         ts_time = datetime.strptime(timestamp, fmt)
#     except ValueError as e:
#         if e.message.split(' ', 1)[0].strip() == 'unconverted':
#             utcoffset = e.message.split()[3].strip()
#             timestamp = timestamp.replace(utcoffset, '')
#             ts_time = datetime.strptime(timestamp, fmt)
#             # Apply offset
#             tzoffset = timedelta(hours=int(utcoffset[0:3]),
#                                           minutes=int(utcoffset[3:5]))
#             ts_time -= tzoffset
#         else:
#             raise e
# 
#     return ts_time


# Path: hydra_base/util/dataset_util.py
import logging
import numpy as np
import pandas as pd
import re
import json
from decimal import Decimal
from operator import mul
from ..exceptions import HydraError, ValidationError
from functools import reduce
from hydra_base.util.hydra_dateutil import get_datetime

    LESSTHANEQ = validate_LESSTHANEQ,
    GREATERTHAN = validate_GREATERTHAN,
    GREATERTHANEQ = validate_GREATERTHANEQ,
    MULTIPLEOF = validate_MULTIPLEOF,
    SUMTO = validate_SUMTO,
    INCREASING = validate_INCREASING,
    DECREASING = validate_DECREASING,
    EQUALTIMESTEPS = validate_EQUALTIMESTEPS,
    NOTNULL        = validate_NOTNULL,
    ISNULL         = validate_ISNULL,
)

def validate_value(restriction_dict, inval):
    if len(restriction_dict) == 0:
        return

    try:
        for restriction_type, restriction in restriction_dict.items():
            func = validation_func_map.get(restriction_type)
            if func is None:
                raise Exception("Validation type {} does not exist".format(restriction_type,))
            func(inval, restriction)
    except ValidationError as e:
        log.exception(e)
        err_val = re.sub('\s+', ' ', str(inval)).strip()
        if len(err_val) > 60:
            err_val = "{}...".format(err_val[:60])
        raise HydraError("Validation error ({}). Val {} does not conform with rule {}".format(restriction_type, err_val, e.args[0]))
    except Exception as e:
        log.exception(e)

        raise HydraError("An error occurred in validation. ({})".format(e))