Esempio n. 1
0
def test_streams_init() -> None:
    stream_a = Stream('a')
    stream_b = Stream('b')
    streams = Streams([stream_a, stream_b])

    assert streams.stream_list == [stream_a, stream_b]
    assert streams.stream_names == ['a', 'b']
Esempio n. 2
0
    async def _main() -> None:
        stream1 = Stream("test_stream_join_1")
        stream2 = Stream("test_stream_join_2")

        async with Streams([stream1, stream2]) as streams:
            async for value in streams.join():
                print(value)
async def main() -> None:
    stream1 = Stream("test_stream_1")
    stream2 = Stream("test_stream_2")
    async with Streams([stream1, stream2]) as streams:
        async for value in streams.join("update_state"):
            print("===")
            pp(value)
            print("===\n")
Esempio n. 4
0
async def main():
    stream1 = Stream('test_stream_1')
    stream2 = Stream('test_stream_2')
    async with Streams([stream1, stream2]) as streams:
        async for value in streams.merge():
            # Return a tuple:
            #  (stream name, record id, record content)
            print(f"{value[0].decode()}: {value[1].decode()}")
Esempio n. 5
0
async def main():
    stream1 = Stream('test_stream_1')
    stream2 = Stream('test_stream_2')
    async with Streams([stream1, stream2]) as streams:
        async for value in streams.join('time_catch', 2):
            print("===")
            pp(value)
            print("===")
Esempio n. 6
0
    async def _main() -> None:
        stream1 = Stream("test_stream_1")
        stream2 = Stream("test_stream_2")

        async with Streams([stream1, stream2]) as streams:
            async for value in streams.join("time_catch"):
                return value

        with pytest.raises(TypeError):
            await _main()
Esempio n. 7
0
def test_sumbar_init() -> None:
    stream1 = Stream("test_stream")
    stream2 = Stream("another_test_stream")
    sb1 = SumBar(stream1, ("x", 5))
    sb2 = SumBar(stream2, [("x", 5), ("y", 2)])

    assert sb1.source_name == "test_stream"
    assert sb1.node_name == "sum_bar(test_stream)[(x, 5)]"
    assert sb2.source_name == "another_test_stream"
    assert sb2.node_name == "sum_bar(another_test_stream)[(x, 5), (y, 2)]"
def test_moving_average_init() -> None:
    stream1 = Stream("test_stream")
    stream2 = Stream("another_test_stream")
    ma1 = MovingAverage(stream1, ("x", 5))
    ma2 = MovingAverage(stream2, [("x", 5), ("y", 2)])

    assert ma1.source_name == "test_stream"
    assert ma1.node_name == "moving_average(test_stream)[(x, 5)]"
    assert ma2.source_name == "another_test_stream"
    assert ma2.node_name == ("moving_average(another_test_stream)"
                             "[(x, 5), (y, 2)]")
Esempio n. 9
0
 async def _main() -> List[Tuple[bytes, bytes, Dict[bytes, bytes]]]:
     stream1 = Stream("test_stream_merge_1")
     stream2 = Stream("test_stream_merge_2")
     async with Streams([stream1, stream2]) as streams:
         i = 0
         result = []
         async for value in streams.merge():
             if i < 5:
                 result.append(value)
                 i += 1
             else:
                 break
     return result
Esempio n. 10
0
    async def _main() -> List[Dict[bytes, Dict[bytes, bytes]]]:
        stream1 = Stream("test_stream_1")
        stream2 = Stream("test_stream_2")

        async with Streams([stream1, stream2]) as streams:
            i = 0
            result = []
            async for value in streams.join("time_catch", 0.3):
                if i < 5:
                    # value: {b'stream_name': (
                    #     b'id', OrderedDict(b'k': b'v')
                    # )}
                    result.append({k: dict(v[1]) for k, v in value.items()})
                    i += 1
                else:
                    break
            return result
Esempio n. 11
0
def test_sumbar_with_wrong_init_args() -> None:
    stream = Stream("test_stream")
    with pytest.raises(TypeError):
        SumBar(stream)
    with pytest.raises(TypeError):
        SumBar(stream, 5)
    with pytest.raises(TypeError):
        SumBar(stream, "x")
    with pytest.raises(TypeError):
        SumBar(stream, {"x": 5})
def test_moving_average_wrong_init_args() -> None:
    stream = Stream("test_stream")
    with pytest.raises(TypeError):
        MovingAverage(stream)
    with pytest.raises(TypeError):
        MovingAverage(stream, 5)
    with pytest.raises(TypeError):
        MovingAverage(stream, "x")
    with pytest.raises(TypeError):
        MovingAverage(stream, {"x": 5})
Esempio n. 13
0
 async def _main() -> List[Tuple[bytes, bytes, StreamValue]]:
     async with Stream("test_stream_1") as stream:
         i = 0
         result = []
         async for value in stream.read():
             if i < 5:
                 result.append(value)
                 i += 1
             else:
                 break
     return result
 async def _main():
     stream = Stream("test_stream")
     async with stream:
         i = 0
         result = []
         async for value in MovingAverage(stream, [("x", 3), ("z", 2)]):
             if i < 4:
                 result.append(dict(value[2]))
                 i += 1
             else:
                 break
         return result
Esempio n. 15
0
 async def _main():
     stream = Stream("test_stream")
     async with stream:
         i = 0
         data_result = []
         idxs = []
         async for value in SumBar(stream, [("x", 5), ("y", 10)]):
             if i < 2:
                 data_result.append(dict(value[2]))
                 idxs.append(value[1])
                 i += 1
             else:
                 break
         return data_result
Esempio n. 16
0
async def main():
    model = creme.linear_model.LogisticRegression()

    stream1 = Stream('test_stream_1')
    stream2 = Stream('test_stream_2')

    async with Streams([stream1, stream2]) as streams:
        async for value in streams.join('time_catch', 5):
            try:
                val_1 = float(value[b'test_stream_1'][1][b'val'])
                val_2 = float(value[b'test_stream_2'][1][b'val'])
            except KeyError as e:
                logging.warning(f'key error: {e}')
            else:
                model.fit_one(
                    {'f1': val_1, 'f2': val_2},
                    random.choice([True, False])
                )
                print("===")
                print(f'a: {model.intercept}')
                print(f'b1: {model.weights["f1"]}')
                print(f'b2: {model.weights["f2"]}')
                print("===")
Esempio n. 17
0
 async def _main() -> Tuple[bytes, bytes, Dict[bytes, bytes]]:
     async with Stream("test_stream_1") as s:
         async for value in s.read():
             result = value
             break
         return result
Esempio n. 18
0
async def main() -> None:
    async with Stream("stream_1") as s:
        async for value in s.read():
            print(value)
Esempio n. 19
0
def test_stream_init() -> None:
    stream = Stream("test")
    assert stream.name == "test"
Esempio n. 20
0
async def main() -> None:
    stream = Stream("stream_1")
    async with stream:
        async for value in MovingAverage(stream, ("x", 3)):
            print(value)