IRC-SPHERE/HyperStream

View on GitHub
hyperstream/tools/asset_splitter/2016-11-24_v0.1.0.py

Summary

Maintainability
A
1 hr
Test Coverage
# The MIT License (MIT) # Copyright (c) 2014-2017 University of Bristol
#
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#
#  The above copyright notice and this permission notice shall be included in all
#  copies or substantial portions of the Software.
#
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
#  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
#  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
#  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
#  OR OTHER DEALINGS IN THE SOFTWARE.

from hyperstream.stream import StreamInstance, StreamMetaInstance
from hyperstream.tool import MultiOutputTool


class AssetSplitter(MultiOutputTool):
    def __init__(self, element=None):
        """
        Special tool to extract data from the asset channel
        :param element: The element to extract
        """
        super(AssetSplitter, self).__init__(element=element)

    def _execute(self, source, splitting_stream, interval, meta_data_id, output_plate_values):
        for timestamp, data in source.window(interval, force_calculation=True):
            if self.element in data:
                for key, value in data[self.element].items():
                    yield StreamMetaInstance(StreamInstance(timestamp=timestamp, value=value), (meta_data_id, key))