def test_heartbeat_reduce(): """Events should reduce""" now = datetime.now() td_1s = timedelta(seconds=1) # Check that empty list works assert not heartbeat_reduce([], pulsetime=1) events = [Event(timestamp=now, data={"label": "test"}), Event(timestamp=now + td_1s, data={"label": "test"})] reduced_events = heartbeat_reduce(events, pulsetime=2) assert len(reduced_events) == 1
def test_heartbeat_reduce(): """Events should reduce""" now = datetime.now() td_1s = timedelta(seconds=1) # Check that empty list works assert not heartbeat_reduce([], pulsetime=1) events = [Event(timestamp=now, data={"label": "test"}), Event(timestamp=now + td_1s, data={"label": "test"})] reduced_events = heartbeat_reduce(events, pulsetime=2) assert len(reduced_events) == 1
def test_heartbeat_same_timestamp(): now = datetime.now() td_1s = timedelta(seconds=1) td_0s = timedelta(seconds=0) e1 = Event(timestamp=now, duration=td_1s, data={"label": "test"}) e2 = Event(timestamp=now, duration=td_0s, data={"label": "test"}) # Should merge res = heartbeat_reduce(list([e1, e2]), pulsetime=5) assert len(res) == 1 assert res[0].duration == td_1s # Order shouldn't matter, should merge res = heartbeat_reduce([e2, e1], pulsetime=5) assert len(res) == 1 assert res[0].duration == td_1s
def test_heartbeat_reduce_fail(): """Events should not reduce""" now = datetime.now() td_1s = timedelta(seconds=1) events = [Event(timestamp=now, data={"label": "test"}), Event(timestamp=now + 3*td_1s, data={"label": "test"})] reduced_events = heartbeat_reduce(events, pulsetime=2) assert len(reduced_events) == 2
def test_heartbeat_reduce_fail(): """Events should not reduce""" now = datetime.now() td_1s = timedelta(seconds=1) events = [Event(timestamp=now, data={"label": "test"}), Event(timestamp=now + 3*td_1s, data={"label": "test"})] reduced_events = heartbeat_reduce(events, pulsetime=2) assert len(reduced_events) == 2
def _main_heartbeat_reduce(): logger.info("Retrieving events...") events = _get_window_events() events = simplify_string(events) logger.info("Beating hearts together...") merged_events = heartbeat_reduce(events, pulsetime=10) # Debugging assert_no_overlap(events) assert_no_overlap(merged_events) print_most_common_titles(events) print_most_common_titles(merged_events)