Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add logo_annotation.server_type field #1396

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading