Ejemplo n.º 1
0
    def fetch_all(self, entity_id: int):
        anns = AnnotationEntity.alias()
        lbl = LabelEntity.alias()
        query = (
            anns.select(
                anns.id.alias("annot_id"),
                anns.entry.alias("annot_entry"),
                anns.kind.alias("annot_kind"),
                anns.points.alias("annot_points"),
                lbl.id.alias("label_id"),
                lbl.name.alias("label_name"),
                lbl.color.alias("label_color")
            )
                .join(lbl, on=(anns.label == lbl.id), join_type="LEFT")
                .where(anns.entry == entity_id)
        )
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            ann_vo = AnnotaVO()
            ann_vo.id = row["annot_id"]
            ann_vo.entry = row["annot_entry"]
            ann_vo.kind = row["annot_kind"]
            ann_vo.points = row["annot_points"]
            ann_vo.label = None
            if row["label_id"]:
                label = LabelVO()
                label.id = row["label_id"]
                label.name = row["label_name"]
                label.color = row["label_color"]
                ann_vo.label = label
            result.append(ann_vo)

        return result
Ejemplo n.º 2
0
    def fetch_all_by_dataset(self, dataset_id: int = None):
        a = AnnotationEntity.alias("a")
        i = DatasetEntryEntity.alias("i")
        l = LabelEntity.alias("l")

        query = (a.select(
            i.file_path.alias("image"), a.kind.alias("annot_kind"),
            a.points.alias("annot_points"), l.name.alias("label_name"),
            l.color.alias("label_color")).join(i, on=(a.entry == i.id)).join(
                l, on=(a.label == l.id),
                join_type="LEFT").where(i.dataset == dataset_id))
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            result.append(row)

        return result
Ejemplo n.º 3
0
    def fetch_all_by_dataset(self, dataset_id: int = None):
        ann = AnnotationEntity.alias("a")
        ds_entry = DatasetEntryEntity.alias("i")
        lbl = LabelEntity.alias("l")
        query = (ann.select(ds_entry.file_path.alias("image"),
                            ann.kind.alias("annot_kind"),
                            ann.points.alias("annot_points"),
                            lbl.name.alias("label_name"),
                            lbl.color.alias("label_color")).join(
                                ds_entry, on=(ann.entry == ds_entry.id)).join(
                                    lbl,
                                    on=(ann.label == lbl.id),
                                    join_type=JOIN.LEFT_OUTER).where(
                                        ds_entry.dataset == dataset_id))
        cursor = query.dicts().execute()
        result = []
        for row in cursor:
            result.append(row)

        return result