sources as classes

This commit is contained in:
scottsanderson
2012-08-02 16:13:23 -04:00
parent bc3394bc36
commit c49806187d
2 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -18,15 +18,15 @@ def date_sorted_sources(*sources):
"""
for source in sources:
assert source.__dict__.has_key('__init__')
assert source.__dict__.has_key('get_hash')
assert iter(source), "Source %s not iterable" % source
assert source.__class__.__dict__.has_key('get_hash'), "No get_hash"
# Get name hashes to pass to date_sort.
names = [source.get_hash for source in sources)
names = [source.get_hash() for source in sources]
# Convert the list of generators into a flat stream by pulling
# one element at a time from each.
stream_in = roundrobin(source_gens, names)
stream_in = roundrobin(sources, names)
# Guarantee the flat stream will be sorted by date, using source_id as
# tie-breaker, which is fully deterministic (given deterministic string
+3 -3
View File
@@ -23,7 +23,7 @@ if __name__ == "__main__":
'delta' : timedelta(minutes = 1),
'filter' : filter
}
bundle_a = SourceBundle(SpecificEquityTrades, args_a, kwargs_a)
source_a = SpecificEquityTrades(*args_a, **kwargs_a)
#Set up source b. Two minutes between events.
args_b = tuple()
@@ -33,12 +33,12 @@ if __name__ == "__main__":
'delta' : timedelta(minutes = 1),
'filter' : filter
}
bundle_b = SourceBundle(SpecificEquityTrades, args_b, kwargs_b)
source_b = SpecificEquityTrades(*args_b, **kwargs_b)
#Set up source c. Three minutes between events.
sort_out = date_sorted_sources(source_a, source_b)
# passthrough = TransformBundle(Passthrough, (), {})
# mavg_price = TransformBundle(MovingAverage, (timedelta(minutes = 20), ['price']), {})
# tnfm_bundles = (passthrough, mavg_price)