user_model = UserModel()

    for window_event in proc_events:


        window_model = gen_window_model(window_event, proc_events)

        if window_model is None:
            continue

        user_model.add_window_model(window_event, window_model)

    default_model = gen_window_model(None, proc_events)

    user_model.set_default_model(default_model)

    for i in range(100):
        print("Gen:", default_model.next())

    if not os.path.isdir(output_dir):
        os.makedirs(output_dir, exist_ok=True)
        try:
            os.mkdir(output_dir)
        except OSError as e:
            #folder exists
            pass

    with open(output_dir + "/user_model.mdl", "bw+") as f:
        pickle.dump(user_model, f)
def process_inputs(input_dirs, output_dir):
    event_constructor = EventConstructor()
    events = []
    window_event = default_window_event

    for f in input_dirs:
        file = f + "/" + "events.evnt"

        if not os.path.isfile(file):
            print("Cannot find file: " + file)
            continue



        with open(file, "r") as f:
            for line in f:
                events.append(event_constructor.construct(line))
        events.append(Event(events[-1].timestamp+1, EventType.NONE))

    events = sorted(events, key=lambda x : x.timestamp)

    proc_events = {}

    windowed_events = {}

    for e in events:

        key = window_event.filename_string()

        if isinstance(e, WindowChangeEvent):
            window_event = e
            windows.append(e)

        if not key in proc_events:
            proc_events[key] = {}

        if not e.event_type in proc_events[key]:
            proc_events[key][e.event_type] = []

        if not None in proc_events:
            proc_events[None] = {}

        if not e.event_type in proc_events[None]:
            proc_events[None][e.event_type] = []


        if normalise and not window_event == default_window_event:
            e.change_window(window_event)

        proc_events[key][e.event_type].append(e)
        proc_events[None][e.event_type].append(e)

        if not isinstance(e, WindowChangeEvent) or window_event.filename_string() != key:

            if not None in windowed_events:
                windowed_events[None] = []

            windowed_events[None].append(e)

            if not key in windowed_events:
                windowed_events[key] = []

            windowed_events[key].append(e)

    user_model = UserModel()

    for window_event in proc_events:

        window_model = gen_window_model(window_event, proc_events, windowed_events)

        if window_model is None:
            continue

        user_model.add_window_model(window_event, window_model)

        if not window_event is None:

            for input_file_num in range(len(input_dirs)):

                screenshot = find(window_event, input_dirs[input_file_num] + "/images/")

                cols = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255), (255, 0, 255), (0, 0, 0)]

                if not screenshot is None and os.path.isfile(screenshot):
                    img = cv2.imread(screenshot)
                    if not img is None:
                        ci = 0
                        h, w = img.shape[:2]
                        for c in window_model.clusters:
                            if c[-4:] == "DOWN":
                                for cl in window_model.clusters[c]:
                                    print(cl)
                                    cv2.rectangle(img,
                                                  (int(cl[0]*w)-2, int(cl[1]*h)-2),
                                                  (int(cl[0]*w)+2, int(cl[1]*h)+2),
                                                  cols[ci], -1, 8)
                                ci += 1
                        imgout = output_dir + "/imgs/"

                        if not os.path.isdir(imgout):
                            os.makedirs(imgout, exist_ok=True)
                            try:
                                os.mkdir(imgout)
                            except OSError as e:
                                #folder exists
                                pass


                        cv2.imwrite(imgout + window_event + ".png", img)

                        continue

    default_model = gen_window_model(None, proc_events, windowed_events)

    user_model.set_default_model(default_model)

    for i in range(100):
        print("Gen:", default_model.next())

    if not os.path.isdir(output_dir):
        os.makedirs(output_dir, exist_ok=True)
        try:
            os.mkdir(output_dir)
        except OSError as e:
            #folder exists
            pass

    with open(output_dir + "/user_model.mdl", "bw+") as f:
        pickle.dump(user_model, f)