diff options
author | Étienne Simon <esimon@esimon.eu> | 2015-04-24 16:38:12 -0400 |
---|---|---|
committer | Étienne Simon <esimon@esimon.eu> | 2015-04-24 16:38:12 -0400 |
commit | b1da6fb4e644dcdec6d90c3f0ae018001a98a4b6 (patch) | |
tree | aa9bf1925eb84a6b2f228891498606cc9e3857fa /transformers.py | |
parent | 0be3ebaa19f2cf8a630565434e785e5c24929a14 (diff) | |
download | taxi-b1da6fb4e644dcdec6d90c3f0ae018001a98a4b6.tar.gz taxi-b1da6fb4e644dcdec6d90c3f0ae018001a98a4b6.zip |
Add basic transformers
Diffstat (limited to 'transformers.py')
-rw-r--r-- | transformers.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/transformers.py b/transformers.py new file mode 100644 index 0000000..2a49a11 --- /dev/null +++ b/transformers.py @@ -0,0 +1,25 @@ +from fuel.transformers import Transformer, Filter, Mapping + +class Select(Transformer): + def __init__(self, data_stream, sources): + super(Select, self).__init__(data_stream) + self.ids = [data_stream.sources.index(source) for source in sources] + self.sources=sources + + def get_data(self, request=None): + if request is not None: + raise ValueError + data=next(self.child_epoch_iterator) + return [data[id] for id in self.ids] + +def add_extremities(stream, k): + id_polyline=stream.sources.index('polyline') + def extremities(x): + return (x[id_polyline][:k], x[id_polyline][-k:]) + stream = Filter(stream, lambda x: len(x[id_polyline])>=k) + stream = Mapping(stream, extremeties, ('first_k', 'last_k')) + return stream + +def add_destination(stream): + id_polyline=stream.sources.index('polyline') + return Mapping(stream, lambda x: x[id_polyline][-1], ('destination',)) |