def group_components_only_root(detections, ui_dict):
    detections_copy = detections.copy()
    root_box = ui_dict[ROOT_ID]["box"]
    for index, class_no in enumerate(detections_copy[KEY_CLASSES]):
        # Check for Widget counts saved
        if class_no in ui_dict[KEY_CLASSES_COUNT]:
            ui_dict[KEY_CLASSES_COUNT][class_no] = (
                ui_dict[KEY_CLASSES_COUNT][class_no] + 1)
        else:
            ui_dict[KEY_CLASSES_COUNT][class_no] = 1
        # get box of component
        box = change_box(detections_copy[KEY_BOXES][index])
        score = detections_copy[KEY_SCORES][index]
        widget_id = category_index[class_no]["name"] + str(
            ui_dict[KEY_CLASSES_COUNT][class_no])

        # Check box is inside root
        if OverlapAlgo.is_inside_by_full_overlap(
                root_box, box) or OverlapAlgo.is_inside_by_partial_overlap(
                    root_box, box):
            trimed_box = OverlapAlgo.trim_inside_stable_box(root_box, box)
            ui_dict[ROOT_ID]["content"][widget_id] = prepare_widget_dict(
                widget_id, class_no, trimed_box, score)
        else:
            print("component outside root")
Esempio n. 2
0
def resolve_overlaping_layouts(detections):
    copy_of_detections = detections.copy()
    # Create filter for detections
    filter_extract = np.full((len(copy_of_detections[KEY_CLASSES])), True)

    for index, class_no in enumerate(copy_of_detections[KEY_CLASSES]):
        score = copy_of_detections[KEY_SCORES][index]
        box = copy_of_detections[KEY_BOXES][index]
        if class_no == 24:  # If it is layout

            for index_child, class_no_child in enumerate(
                    copy_of_detections[KEY_CLASSES]):
                score_child = copy_of_detections[KEY_SCORES][index_child]
                box_child = copy_of_detections[KEY_BOXES][index_child]

                if class_no_child == 24:  # If it is layout
                    if OverlapAlgo.is_inside_by_full_overlap(
                            box, box_child
                    ) or OverlapAlgo.is_inside_by_partial_overlap(
                            box, box_child):
                        if score > score_child:
                            filter_extract[index_child] = False
                        else:
                            filter_extract[index] = False

    # Change detection dict
    detections[KEY_CLASSES] = detections[KEY_CLASSES][filter_extract]
    detections[KEY_SCORES] = detections[KEY_SCORES][filter_extract]
    detections[KEY_BOXES] = detections[KEY_BOXES][filter_extract]
def layout_grouping(content_dict):
    content_copy = content_dict.copy()
    layouts = list()
    cardviews = list()
    other_widgets = list()

    # Extract Layouts from content
    for widget_id in content_copy:
        if content_copy[widget_id]["class"] == 24:
            layouts.append(widget_id)
        elif content_copy[widget_id]["class"] == 13:
            cardviews.append(widget_id)
        else:
            other_widgets.append(widget_id)

    if len(layouts) < 1 and len(cardviews) < 1:
        return

    # resolve layout and cardview
    for layout_id in layouts:
        if len(cardviews) < 1:
            break
        layout_box = content_copy[layout_id]["box"]
        ids_to_remove = list()  # Cardview ids to be removed
        for cardview_id in cardviews:
            cardview_box = content_copy[cardview_id]["box"]
            if (OverlapAlgo.is_inside_by_full_overlap(layout_box, cardview_box)
                    or OverlapAlgo.is_inside_by_partial_overlap(
                        layout_box, cardview_box)
                    or check_if_box_cover(layout_box, cardview_box)):
                content_dict[layout_id]["alt"] = ["CardView"]
                content_dict.pop(cardview_id)
                ids_to_remove.append(cardview_id)
        for id_to_remove in ids_to_remove:
            cardviews.remove(id_to_remove)

    # Merge Cardview and Layout
    layouts.extend(cardviews)

    # Group Layouts
    for layout_id in layouts:
        if len(other_widgets) < 1:
            break
        content_dict[layout_id]["content"] = dict()
        layout_box = content_copy[layout_id]["box"]
        ids_to_remove = list()  # other widget Id's to be removed
        for widget_id in other_widgets:
            widget_box = content_copy[widget_id]["box"]
            if OverlapAlgo.is_inside_by_full_overlap(
                    layout_box,
                    widget_box) or OverlapAlgo.is_inside_by_partial_overlap(
                        layout_box, widget_box):
                content_dict[layout_id]["content"][widget_id] = content_dict[
                    widget_id]
                content_dict.pop(widget_id)
                ids_to_remove.append(widget_id)
        for id_to_remove in ids_to_remove:
            other_widgets.remove(id_to_remove)
def group_components_appbar_bottomnav(detections, ui_dict):
    detections_copy = detections.copy()
    root_box = ui_dict[ROOT_ID]["box"]
    appbar_box = ui_dict[APPBAR_ID]["box"]
    bottomnav_box = ui_dict[BOTTOMNAV_ID]["box"]

    for index, class_no in enumerate(detections_copy[KEY_CLASSES]):
        # Check for Widget counts saved
        if class_no in ui_dict[KEY_CLASSES_COUNT]:
            ui_dict[KEY_CLASSES_COUNT][class_no] = (
                ui_dict[KEY_CLASSES_COUNT][class_no] + 1)
        else:
            ui_dict[KEY_CLASSES_COUNT][class_no] = 1

        # get box of component
        box = detections_copy[KEY_BOXES][index]
        score = detections_copy[KEY_SCORES][index]
        widget_id = ClassMap.get_name_for_class(class_no) + str(
            ui_dict[KEY_CLASSES_COUNT][class_no])

        # Check box is inside root
        if OverlapAlgo.is_inside_by_full_overlap(
                root_box, box) or OverlapAlgo.is_inside_by_partial_overlap(
                    root_box, box):
            root_trimed_box = OverlapAlgo.trim_inside_stable_box(root_box, box)
            # Check box inside app bar
            if OverlapAlgo.is_inside_by_full_overlap(
                    appbar_box, root_trimed_box
            ) or OverlapAlgo.is_inside_by_partial_overlap(
                    appbar_box, root_trimed_box):
                trimed_box = OverlapAlgo.trim_inside_stable_box(
                    appbar_box, root_trimed_box)
                ui_dict[APPBAR_ID]["content"][widget_id] = prepare_widget_dict(
                    widget_id, class_no, trimed_box, score)

            # Check box inside BottomNav bar
            elif OverlapAlgo.is_inside_by_full_overlap(
                    bottomnav_box, root_trimed_box
            ) or OverlapAlgo.is_inside_by_partial_overlap(
                    bottomnav_box, root_trimed_box):
                trimed_box = OverlapAlgo.trim_inside_stable_box(
                    bottomnav_box, root_trimed_box)
                ui_dict[BOTTOMNAV_ID]["content"][
                    widget_id] = prepare_widget_dict(widget_id, class_no,
                                                     trimed_box, score)
            # add box inside content
            else:
                ui_dict[ROOT_ID]["content"][widget_id] = prepare_widget_dict(
                    widget_id, class_no, root_trimed_box, score)
        else:
            print("component outside root")
def group_only_content(detections, ui_dict):
    detections_copy = detections.copy()
    content_box = ui_dict[CONTENT_ID]["box"]

    for index, class_no in enumerate(detections_copy[KEY_CLASSES]):
        # get box of component
        box = detections_copy[KEY_BOXES][index]
        score = detections_copy[KEY_SCORES][index]
        if OverlapAlgo.is_inside_by_full_overlap(
                content_box, box) or OverlapAlgo.is_inside_by_partial_overlap(
                    content_box, box):  # Check box is inside content
            trimed_box = OverlapAlgo.trim_inside_stable_box(content_box, box)
            add_widget_to_container(
                container_dict=ui_dict[CONTENT_ID],
                box=trimed_box,
                score=score,
                class_no=class_no,
            )
def listview_grouping(content_dict):
    content_copy = content_dict.copy()
    listviews = list()
    h_list = list()
    v_list = list()
    layouts = list()
    recycler = list()

    # Resolve ListView, horizontal and vertical list view as Recycler view
    for widget_id in content_copy:
        if content_copy[widget_id]["class"] == 14:
            listviews.append(widget_id)
        elif content_copy[widget_id]["class"] == 27:
            h_list.append(widget_id)
        elif content_copy[widget_id]["class"] == 28:
            v_list.append(widget_id)
        elif content_copy[widget_id]["class"] == 24:
            layouts.append(widget_id)
        elif (content_copy[widget_id]["class"] == 13
              ):  # change made for cardview grouping
            layouts.append(widget_id)

    # Resolve for Horizontal listview
    for hlist_id in h_list:
        # If no listviews box break the loop
        if len(listviews) < 1:
            break
        hlist_box = content_copy[hlist_id]["box"]
        ids_to_remove = list()  # Listview ids to be removed

        # Loop through listviews list()
        for listview_id in listviews:
            listview_box = content_copy[listview_id]["box"]
            if (OverlapAlgo.is_inside_by_full_overlap(hlist_box, listview_box)
                    or OverlapAlgo.is_inside_by_partial_overlap(
                        hlist_box, listview_box)
                    or check_if_box_cover(hlist_box, listview_box)):
                recycler.append(hlist_id)  # add horizontal list view id
                content_dict.pop(
                    listview_id)  # remove listview from dictionary
                ids_to_remove.append(listview_id)
        for id_to_remove in ids_to_remove:
            listviews.remove(id_to_remove)

    # Resolve for Vertical listview
    for vlist_id in v_list:
        # If no listviews box break the loop
        if len(listviews) < 1:
            break
        vlist_box = content_copy[vlist_id]["box"]
        ids_to_remove = list()  # Listview ids to be removed

        # Loop through listviews list()
        for listview_id in listviews:
            listview_box = content_copy[listview_id]["box"]
            if (OverlapAlgo.is_inside_by_full_overlap(vlist_box, listview_box)
                    or OverlapAlgo.is_inside_by_partial_overlap(
                        vlist_box, listview_box)
                    or check_if_box_cover(vlist_box, listview_box)):
                recycler.append(vlist_id)  # add horizontal list view id
                content_dict.pop(
                    listview_id)  # remove listview from dictionary
                ids_to_remove.append(listview_id)
        for id_to_remove in ids_to_remove:
            listviews.remove(id_to_remove)

    # check if recycler list is not empty
    if len(recycler) < 1:
        print("No List views")
    else:
        listview_name = "ListView"
        for index, list_id in enumerate(recycler):
            list_key = listview_name + str(index + 1)
            content_dict[list_key] = dict()
            content_dict[list_key]["id"] = list_key
            content_dict[list_key]["class"] = 14
            content_dict[list_key]["box"] = content_dict[list_id]["box"]
            content_dict[list_key]["score"] = content_dict[list_id]["score"]
            content_dict[list_key]["content"] = dict()
            # Orientation Horizontal = 0 ,Vertical = 1
            if content_copy[list_id]["class"] == 27:
                content_dict[list_key]["orientation"] = 0
            elif content_copy[list_id]["class"] == 28:
                content_dict[list_key]["orientation"] = 1
            else:
                content_dict[list_key]["orientation"] = 1

            # remove listview from content dict
            content_dict.pop(list_id)

            listview_box = content_dict[list_key]["box"]
            ids_to_remove = list()  # other widget Id's to be removed
            # Group Layouts inside list dict
            for layout_id in layouts:
                layout_box = content_copy[layout_id]["box"]
                if OverlapAlgo.is_inside_by_full_overlap(
                        listview_box, layout_box
                ) or OverlapAlgo.is_inside_by_partial_overlap(
                        listview_box, layout_box):
                    content_dict[list_key]["content"][
                        layout_id] = content_dict[layout_id]
                    content_dict[list_key]["content"][layout_id][
                        "box"] = trim_inside_stable_box(
                            listview_box, layout_box)
                    content_dict.pop(layout_id)
                    ids_to_remove.append(layout_id)
            for id_to_remove in ids_to_remove:
                layouts.remove(id_to_remove)
Esempio n. 7
0
def resolve_icon_and_action_button(appbar_dict):
    copy_of_appbar = appbar_dict.copy()
    # Create filter for detections
    filter_extract = np.full((len(copy_of_appbar[KEY_CLASSES])), True)

    for index, class_no in enumerate(copy_of_appbar[KEY_CLASSES]):
        score = copy_of_appbar[KEY_SCORES][index]
        box = copy_of_appbar[KEY_BOXES][index]

        if class_no == 8:  # If it is action button
            for index_child, class_no_child in enumerate(
                    copy_of_appbar[KEY_CLASSES]):
                if index != index_child:
                    score_child = copy_of_appbar[KEY_SCORES][index_child]
                    box_child = copy_of_appbar[KEY_BOXES][index_child]

                    if class_no_child == 8:
                        if OverlapAlgo.is_inside_by_full_overlap(
                                box, box_child
                        ) or OverlapAlgo.is_inside_by_partial_overlap(
                                box, box_child
                        ):  # actionButton actionButton overlap
                            if score > score_child:
                                filter_extract[index_child] = False
                            else:
                                filter_extract[index] = False

                    if class_no_child == 6:
                        if OverlapAlgo.is_inside_by_full_overlap(
                                box, box_child
                        ) or OverlapAlgo.is_inside_by_partial_overlap(
                                box, box_child
                        ):  # actionButton Icon overlap priority to action button
                            filter_extract[index_child] = False

                else:
                    continue

        if class_no == 6:  # If it is Icon
            for index_child, class_no_child in enumerate(
                    copy_of_appbar[KEY_CLASSES]):
                if index != index_child:
                    score_child = copy_of_appbar[KEY_SCORES][index_child]
                    box_child = copy_of_appbar[KEY_BOXES][index_child]

                    if OverlapAlgo.is_inside_by_full_overlap(
                            box, box_child
                    ) or OverlapAlgo.is_inside_by_partial_overlap(
                            box, box_child):
                        if (
                                class_no_child == 8
                        ):  # Action Button Icon Overlapped priority to action button
                            filter_extract[index] = False
                        if class_no_child == 6:  # Icon Overlaped
                            if score > score_child:
                                filter_extract[index_child] = False
                            else:
                                filter_extract[index] = False
                else:
                    continue

    # Change detection dict
    appbar_dict[KEY_CLASSES] = appbar_dict[KEY_CLASSES][filter_extract]
    appbar_dict[KEY_SCORES] = appbar_dict[KEY_SCORES][filter_extract]
    appbar_dict[KEY_BOXES] = appbar_dict[KEY_BOXES][filter_extract]
Esempio n. 8
0
def resolve_icon_and_bottomnav(bottomnav_dict):
    copy_of_appbar = bottomnav_dict.copy()
    # Create filter for detections
    filter_extract = np.full((len(copy_of_appbar[KEY_CLASSES])), True)

    for index, class_no in enumerate(copy_of_appbar[KEY_CLASSES]):
        score = copy_of_appbar[KEY_SCORES][index]
        box = copy_of_appbar[KEY_BOXES][index]

        if class_no == 25:  # If it is bottomnavItem
            for index_child, class_no_child in enumerate(
                    copy_of_appbar[KEY_CLASSES]):
                if index != index_child:
                    score_child = copy_of_appbar[KEY_SCORES][index_child]
                    box_child = copy_of_appbar[KEY_BOXES][index_child]

                    if class_no_child == 25:  # bottomnavItem - bottomnavItem overlap
                        if OverlapAlgo.is_inside_by_full_overlap(
                                box, box_child
                        ) or OverlapAlgo.is_inside_by_partial_overlap(
                                box, box_child):
                            if score > score_child:
                                filter_extract[index_child] = False
                            else:
                                filter_extract[index] = False

                    if (
                            class_no_child == 6
                    ):  # bottomnavItem -Icon overlap priority to bottom nav
                        if OverlapAlgo.is_inside_by_full_overlap(
                                box, box_child
                        ) or OverlapAlgo.is_inside_by_partial_overlap(
                                box, box_child):
                            filter_extract[index_child] = False

                else:
                    continue

        if class_no == 6:  # If it is Icon
            for index_child, class_no_child in enumerate(
                    copy_of_appbar[KEY_CLASSES]):
                if index != index_child:
                    score_child = copy_of_appbar[KEY_SCORES][index_child]
                    box_child = copy_of_appbar[KEY_BOXES][index_child]

                    if OverlapAlgo.is_inside_by_full_overlap(
                            box, box_child
                    ) or OverlapAlgo.is_inside_by_partial_overlap(
                            box, box_child):
                        if (
                                class_no_child == 25
                        ):  # bottomnav icon Overlapped priority to bottom nav
                            filter_extract[index] = False
                        if class_no_child == 6:  # Icons Overlaped
                            if score > score_child:
                                filter_extract[index_child] = False
                            else:
                                filter_extract[index] = False
                else:
                    continue

    # Change detection dict
    bottomnav_dict[KEY_CLASSES] = bottomnav_dict[KEY_CLASSES][filter_extract]
    bottomnav_dict[KEY_SCORES] = bottomnav_dict[KEY_SCORES][filter_extract]
    bottomnav_dict[KEY_BOXES] = bottomnav_dict[KEY_BOXES][filter_extract]