# Path: alephnull/gens/utils.py
# def hash_args(*args, **kwargs):
#     """Define a unique string for any set of representable args."""
#     arg_string = '_'.join([str(arg) for arg in args])
#     kwarg_string = '_'.join([str(key) + '=' + str(value)
#                              for key, value in kwargs.iteritems()])
#     combined = ':'.join([arg_string, kwarg_string])
# 
#     hasher = md5()
#     hasher.update(combined)
#     return hasher.hexdigest()
# 
# Path: alephnull/sources/data_source.py
# class DataSource(object):
# 
#     __metaclass__ = ABCMeta
# 
#     @property
#     def event_type(self):
#         return DATASOURCE_TYPE.TRADE
# 
#     @property
#     def mapping(self):
#         """
#         Mappings of the form:
#         target_key: (mapping_function, source_key)
#         """
#         return {}
# 
#     @abstractproperty
#     def raw_data(self):
#         """
#         An iterator that yields the raw datasource,
#         in chronological order of data, one event at a time.
#         """
#         NotImplemented
# 
#     @abstractproperty
#     def instance_hash(self):
#         """
#         A hash that represents the unique args to the source.
#         """
#         pass
# 
#     def get_hash(self):
#         return self.__class__.__name__ + "-" + self.instance_hash
# 
#     def apply_mapping(self, raw_row):
#         """
#         Override this to hand craft conversion of row.
#         """
#         row = {target: mapping_func(raw_row[source_key])
#                for target, (mapping_func, source_key)
#                in self.mapping.items()}
#         row.update({'source_id': self.get_hash()})
#         row.update({'type': self.event_type})
#         return row
# 
#     @property
#     def mapped_data(self):
#         for row in self.raw_data:
#             yield Event(self.apply_mapping(row))
# 
#     def __iter__(self):
#         return self
# 
#     def next(self):
#         return self.mapped_data.next()


import pandas as pd
from alephnull.gens.utils import hash_args
from alephnull.sources.data_source import DataSource

    sids   : list of values representing simulated internal sids
    start  : start date
    delta  : timedelta between internal events
    filter : filter to remove the sids
    """

    def __init__(self, data, **kwargs):
        """
        Data must be a DataFrame formatted like this:

        #################################################################################################
        #                     # GS                                # TW                                  #
        #                     # N10             # H10             # G14              # H14              #
        #                     # Price  # Volume # Price  # Volume # Price  # Metric3 # Price  # Metric3 #
        # 2013-12-20 00:09:15 # 101.00 # 1000   # 60.34  # 2500   # 400.00 # -0.0034 # Price # -5.0     #
        # 2013-12-20 00:09:17 # 201.00 # 2000   # 20.34  # 2500   # 200.00 # -2.0034 # Price # -2.0     #
        # etc...                                                                                        #
        #################################################################################################

        """
        assert isinstance(data.index, pd.tseries.index.DatetimeIndex)

        self.data = data
        # Unpack config dictionary with default values.
        self.sids = kwargs.get('sids', list(set(['.'.join(tup[:2]) for tup in data.columns])))
        self.start = kwargs.get('start', data.index[0])
        self.end = kwargs.get('end', data.index[-1])

        # Hash_value for downstream sorting.

# Path: alephnull/gens/utils.py
# def hash_args(*args, **kwargs):
#     """Define a unique string for any set of representable args."""
#     arg_string = '_'.join([str(arg) for arg in args])
#     kwarg_string = '_'.join([str(key) + '=' + str(value)
#                              for key, value in kwargs.iteritems()])
#     combined = ':'.join([arg_string, kwarg_string])
# 
#     hasher = md5()
#     hasher.update(combined)
#     return hasher.hexdigest()
# 
# Path: alephnull/sources/data_source.py
# class DataSource(object):
# 
#     __metaclass__ = ABCMeta
# 
#     @property
#     def event_type(self):
#         return DATASOURCE_TYPE.TRADE
# 
#     @property
#     def mapping(self):
#         """
#         Mappings of the form:
#         target_key: (mapping_function, source_key)
#         """
#         return {}
# 
#     @abstractproperty
#     def raw_data(self):
#         """
#         An iterator that yields the raw datasource,
#         in chronological order of data, one event at a time.
#         """
#         NotImplemented
# 
#     @abstractproperty
#     def instance_hash(self):
#         """
#         A hash that represents the unique args to the source.
#         """
#         pass
# 
#     def get_hash(self):
#         return self.__class__.__name__ + "-" + self.instance_hash
# 
#     def apply_mapping(self, raw_row):
#         """
#         Override this to hand craft conversion of row.
#         """
#         row = {target: mapping_func(raw_row[source_key])
#                for target, (mapping_func, source_key)
#                in self.mapping.items()}
#         row.update({'source_id': self.get_hash()})
#         row.update({'type': self.event_type})
#         return row
# 
#     @property
#     def mapped_data(self):
#         for row in self.raw_data:
#             yield Event(self.apply_mapping(row))
# 
#     def __iter__(self):
#         return self
# 
#     def next(self):
#         return self.mapped_data.next()


# Path: alephnull/sources/futures_data_frame_source.py
import pandas as pd
from alephnull.gens.utils import hash_args
from alephnull.sources.data_source import DataSource


    sids   : list of values representing simulated internal sids
    start  : start date
    delta  : timedelta between internal events
    filter : filter to remove the sids
    """

    def __init__(self, data, **kwargs):
        """
        Data must be a DataFrame formatted like this:

        #################################################################################################
        #                     # GS                                # TW                                  #
        #                     # N10             # H10             # G14              # H14              #
        #                     # Price  # Volume # Price  # Volume # Price  # Metric3 # Price  # Metric3 #
        # 2013-12-20 00:09:15 # 101.00 # 1000   # 60.34  # 2500   # 400.00 # -0.0034 # Price # -5.0     #
        # 2013-12-20 00:09:17 # 201.00 # 2000   # 20.34  # 2500   # 200.00 # -2.0034 # Price # -2.0     #
        # etc...                                                                                        #
        #################################################################################################

        """
        assert isinstance(data.index, pd.tseries.index.DatetimeIndex)

        self.data = data
        # Unpack config dictionary with default values.
        self.sids = kwargs.get('sids', list(set(['.'.join(tup[:2]) for tup in data.columns])))
        self.start = kwargs.get('start', data.index[0])
        self.end = kwargs.get('end', data.index[-1])

        # Hash_value for downstream sorting.

        self.arg_string = hash_args(data, **kwargs)