# 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
        for subval in value:
            if type(subval) is tuple:
                subval = subval[1]
            validate_VALUERANGE(subval, restriction)
    else:
        min_val = Decimal(restriction[0])
        max_val = Decimal(restriction[1])
        val     = Decimal(value)
        if val < min_val or val > max_val:
            raise ValidationError("VALUERANGE: %s, %s"%(min_val, max_val))

def validate_DATERANGE(value, restriction):
    """
        Test to ensure that the times in a timeseries fall between a lower and upper bound
        Parameters: A timeseries in the form [(datetime, val), (datetime, val)..]
        and a tuple containing the lower and upper bound as datetime objects.
    """
    if len(restriction) != 2:
        raise ValidationError("Template ERROR: Only two values can be specified in a date range.")

    if type(value) == pd.DataFrame:
        dates = [get_datetime(v) for v in list(value.index)]
    else:
        dates = value

    if type(dates) is list:
        for date in dates:
            validate_DATERANGE(date, restriction)
        return


# 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

        for subval in value:
            if type(subval) is tuple:
                subval = subval[1]
            validate_VALUERANGE(subval, restriction)
    else:
        min_val = Decimal(restriction[0])
        max_val = Decimal(restriction[1])
        val     = Decimal(value)
        if val < min_val or val > max_val:
            raise ValidationError("VALUERANGE: %s, %s"%(min_val, max_val))

def validate_DATERANGE(value, restriction):
    """
        Test to ensure that the times in a timeseries fall between a lower and upper bound
        Parameters: A timeseries in the form [(datetime, val), (datetime, val)..]
        and a tuple containing the lower and upper bound as datetime objects.
    """
    if len(restriction) != 2:
        raise ValidationError("Template ERROR: Only two values can be specified in a date range.")

    if type(value) == pd.DataFrame:
        dates = [get_datetime(v) for v in list(value.index)]
    else:
        dates = value

    if type(dates) is list:
        for date in dates:
            validate_DATERANGE(date, restriction)
        return


    min_date = get_datetime(restriction[0])