Ejemplo n.º 1
0
    def rows(self):
        """
        Returns a materialized list of tuples where each tuple contains the
        points from each stream at a unique time.  If a stream has no value for that
        time than None is provided instead of a point object.

        Parameters
        ----------
        None

        Returns
        -------
        list
            A list of tuples containing a RawPoint (or StatPoint) and the stream
            version (list(tuple(RawPoint, int))).

        """
        result = []
        streamset_data = self._streamset_data(as_iterators=True)
        buffer = PointBuffer(len(self._streams))

        while True:
            streams_empty = True

            # add next values from streams into buffer
            for stream_idx, data in enumerate(streamset_data):

                if buffer.active[stream_idx]:
                    try:
                        point, _ = next(data)
                        buffer.add_point(stream_idx, point)
                        streams_empty = False
                    except StopIteration:
                        buffer.deactivate(stream_idx)
                        continue

            key = buffer.next_key_ready()
            if key:
                result.append(tuple(buffer.pop(key)))

            if streams_empty and len(buffer.keys()) == 0:
                break

        return result
Ejemplo n.º 2
0
    def test_next_key_ready_if_none_are(self):
        """
        Assert next_key_ready returns None if nothing is ready
        """
        buffer = PointBuffer(3)
        assert buffer.next_key_ready() == None

        buffer.add_point(0, RawPoint(time=1000, value="leopard"))
        buffer.add_point(2, RawPoint(time=1000, value="giraffe"))
        buffer.add_point(0, RawPoint(time=2000, value="horse"))
        buffer.add_point(0, RawPoint(time=3000, value="pig"))
        assert buffer.next_key_ready() == None
Ejemplo n.º 3
0
    def test_next_key_ready_with_inactive(self):
        """
        Assert next_key_ready returns correct key with inactive stream
        """
        buffer = PointBuffer(3)
        buffer.deactivate(1)
        buffer.add_point(0, RawPoint(time=1000, value="leopard"))
        buffer.add_point(2, RawPoint(time=1000, value="leopard"))
        buffer.add_point(0, RawPoint(time=2000, value="leopard"))
        assert buffer.next_key_ready() == 1000


        # assert first key is 500 even though it was exhausted
        buffer = PointBuffer(3)
        buffer.add_point(1, RawPoint(time=500, value="leopard"))
        buffer.deactivate(1)
        buffer.add_point(0, RawPoint(time=1000, value="leopard"))
        buffer.add_point(2, RawPoint(time=1000, value="leopard"))
        assert buffer.next_key_ready() == 500
Ejemplo n.º 4
0
    def test_is_ready(self):
        """
        Assert is_ready returns correct value
        """
        buffer = PointBuffer(2)
        buffer.add_point(0, RawPoint(time=1000, value="zebra"))
        buffer.add_point(1, RawPoint(time=1000, value="giraffe"))
        buffer.add_point(0, RawPoint(time=2000, value="horse"))

        assert buffer.is_ready(1000) == True
        assert buffer.is_ready(2000) == False

        buffer.deactivate(1)
        assert buffer.is_ready(2000) == True
Ejemplo n.º 5
0
    def test_next_key_ready(self):
        """
        Assert next_key_ready returns correct key
        """
        buffer = PointBuffer(3)
        buffer.add_point(0, RawPoint(time=1000, value="zebra"))
        buffer.add_point(1, RawPoint(time=1000, value="leopard"))
        buffer.add_point(2, RawPoint(time=1000, value="giraffe"))
        buffer.add_point(0, RawPoint(time=2000, value="horse"))
        buffer.add_point(0, RawPoint(time=3000, value="pig"))
        assert buffer.next_key_ready() == 1000

        buffer = PointBuffer(2)
        buffer.add_point(0, RawPoint(time=1000, value="horse"))
        buffer.add_point(0, RawPoint(time=2000, value="zebra"))
        buffer.add_point(0, RawPoint(time=3000, value="pig"))
        buffer.add_point(1, RawPoint(time=2000, value="leopard"))
        assert buffer.next_key_ready() == 1000