def test_period_union(): now = datetime.now(timezone.utc) # Events overlapping events1 = [Event(timestamp=now, duration=timedelta(seconds=10))] events2 = [ Event(timestamp=now + timedelta(seconds=9), duration=timedelta(seconds=10)) ] unioned_events = period_union(events1, events2) assert len(unioned_events) == 1 # Events adjacent but not overlapping events1 = [Event(timestamp=now, duration=timedelta(seconds=10))] events2 = [ Event(timestamp=now + timedelta(seconds=10), duration=timedelta(seconds=10)) ] unioned_events = period_union(events1, events2) assert len(unioned_events) == 1 # Events not overlapping or adjacent events1 = [Event(timestamp=now, duration=timedelta(seconds=10))] events2 = [ Event(timestamp=now + timedelta(seconds=11), duration=timedelta(seconds=10)) ] unioned_events = period_union(events1, events2) assert len(unioned_events) == 2
def test_period_union(): now = datetime.now(timezone.utc) # Events overlapping events1 = [Event(timestamp=now, duration=timedelta(seconds=10))] events2 = [Event(timestamp=now + timedelta(seconds=9), duration=timedelta(seconds=10))] unioned_events = period_union(events1, events2) assert len(unioned_events) == 1 # Events adjacent but not overlapping events1 = [Event(timestamp=now, duration=timedelta(seconds=10))] events2 = [Event(timestamp=now + timedelta(seconds=10), duration=timedelta(seconds=10))] unioned_events = period_union(events1, events2) assert len(unioned_events) == 1 # Events not overlapping or adjacent events1 = [Event(timestamp=now, duration=timedelta(seconds=10))] events2 = [Event(timestamp=now + timedelta(seconds=11), duration=timedelta(seconds=10))] unioned_events = period_union(events1, events2) assert len(unioned_events) == 2
def _query_complete(): # noqa from aw_transform import (query_bucket, find_bucket, filter_keyvals, exclude_keyvals, period_union, concat) hostname = "" # set in preprocessing browsernames_chrome = ["Chromium"] # TODO: Include more browsers browsernames_ff = ["Firefox"] # TODO: Include more browsers events = flood(query_bucket(find_bucket("aw-watcher-window", hostname))) events_afk = query_bucket( find_bucket("aw-watcher-afk", hostname) ) # TODO: Readd flooding for afk-events once a release has been made that includes the flooding-fix events_web_chrome = flood( query_bucket(find_bucket("aw-watcher-web-chrome"))) events_web_ff = flood(query_bucket(find_bucket("aw-watcher-web-firefox"))) # Combine window events with web events events_browser_chrome = filter_keyvals(events, "app", browsernames_chrome) events_web_chrome = filter_period_intersect(events_web_chrome, events_browser_chrome) events_browser_ff = filter_keyvals(events, "app", browsernames_ff) events_web_ff = filter_period_intersect(events_web_ff, events_browser_ff) events_web = concat(events_web_chrome, events_web_ff) # TODO: Browser events should only be excluded when there's a web-event replacing it events = exclude_keyvals(events, "app", browsernames_chrome) events = exclude_keyvals(events, "app", browsernames_ff) events = concat(events, events_web) # Filter away all inactive (afk and non-audible) time events_notafk = filter_keyvals(events_afk, "status", ["not-afk"]) events_audible = filter_keyvals(events_web, "audible", [True]) events_active = period_union(events_notafk, events_audible) events = filter_period_intersect(events, events_active) return events
def q2_period_union(events1: list, events2: list) -> List[Event]: return period_union(events1, events2)
def q2_period_union(events1: list, events2: list) -> List[Event]: _verify_variable_is_type(events1, list) _verify_variable_is_type(events2, list) return period_union(events1, events2)