Skip to content

Commit

Permalink
fix: add logo_annotation.server_type field
Browse files Browse the repository at this point in the history
This is the same as ImageModel.server_type, but we store it here to
avoid performing a double join with ImageModel table when we need to
filter logos by server_type
(LogoAnnotation > ImagePrediction > ImageModel)
  • Loading branch information
raphael0202 committed Aug 19, 2024
1 parent 6ba5f7e commit 22ac1ec
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
23 changes: 23 additions & 0 deletions migrations/006_add_logo_annotation_server_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import peewee as pw
from peewee_migrate import Migrator


def migrate(migrator: Migrator, database: pw.Database, *, fake=False):
"""Write your migrations here."""

migrator.add_fields(
"logo_annotation",
server_type=pw.CharField(
null=True,
max_length=10,
help_text="project associated with the logo annotation, "
"one of 'off', 'obf', 'opff', 'opf', 'off-pro'",
index=False,
),
)


def rollback(migrator: Migrator, database: pw.Database, *, fake=False):
"""Write your rollback migrations here."""

migrator.remove_fields("logo_annotation", "server_type")
1 change: 1 addition & 0 deletions robotoff/cli/logos.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def import_logos(
bounding_box=item["bounding_box"],
barcode=image_instance.barcode,
source_image=image_instance.source_image,
server_type=server_type.name,
)
seen_set.add(key)

Expand Down
15 changes: 13 additions & 2 deletions robotoff/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ class Prediction(BaseModel):
server_type = peewee.CharField(
null=False,
max_length=10,
help_text="project associated with the insight, "
"one of 'off', 'obf', 'opff', 'opf'",
help_text="project associated with the prediction, "
"one of 'off', 'obf', 'opff', 'opf', 'off-pro'",
index=True,
default="off",
)
Expand Down Expand Up @@ -343,6 +343,17 @@ class LogoAnnotation(BaseModel):
source_image = peewee.TextField(null=True, index=True)
# The logo text extracted from the image using OCR
text = peewee.TextField(null=True)
# This is the same as ImageModel.server_type, but we store it here to
# avoid performing a double join with ImageModel table when we need to
# filter logos by server_type
# (LogoAnnotation > ImagePrediction > ImageModel)
server_type = peewee.CharField(
null=True,
max_length=10,
help_text="project associated with the logo annotation, "
"one of 'off', 'obf', 'opff', 'opf', 'off-pro'",
index=False,
)

class Meta:
constraints = [peewee.SQL("UNIQUE(image_prediction_id, index)")]
Expand Down
1 change: 1 addition & 0 deletions robotoff/workers/tasks/import_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def run_logo_object_detection(
barcode=image_model.barcode,
source_image=image_model.source_image,
text=text,
server_type=product_id.server_type.name,
)
)
logger.info("%s logos found for image %s", len(logos), source_image)
Expand Down
1 change: 1 addition & 0 deletions scripts/insert_image_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def insert_batch(
bounding_box=item["bounding_box"],
barcode=image_instance.barcode,
source_image=image_instance.source_image,
server_type=server_type.name,
)
seen_set.add(key)

Expand Down

0 comments on commit 22ac1ec

Please sign in to comment.