예제 #1
0
def modeleval_window(timed_templates, window_size=60, remove_junk_drawer=False):
    windows = window(timed_templates, window_size, remove_junk_drawer, template_ids_only=False)

    modeleval_windows = []
    for window_id, timed_templates in windows.iteritems():
        # It doesn't matter which TimedTemplate we take since all in the same window will resolve to the same start/end times.
        m = timed_templates[0].ts % window_size
        start_time = timed_templates[0].ts - m
        end_time = start_time + window_size
        modeleval_windows.append(ModelEvalWindow(start_time=start_time, end_time=end_time, timed_templates=timed_templates))
    return modeleval_windows
예제 #2
0
def modelgen_window(timed_templates, window_size=60, remove_junk_drawer=False):
    """
    This function was written to take in the output of the apply_template function.
    It groups template occurrences into "windows" (aka transactions) that will be passed on to a
    market basket analysis algorithm in events/events.py.

    By default the window size is 60 seconds.

    Args:
        timed_templates: iterable of timed_templates

    Kwargs:
        window_size: # of seconds to allow for each window size (default: 60)

    Returns:
        windows: list of sets containing TimedTemplate named tuples
    """
    windows = window(timed_templates, window_size, remove_junk_drawer, template_ids_only=True)
    modelgen_windows = [ModelGenWindow(template_ids=template_ids) for window_id, template_ids in windows.iteritems()]
    return modelgen_windows