Skip to content

Commit

Permalink
fix: fix extreme weight detection for multi-packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Dec 18, 2023
1 parent 9c6a4ee commit f5a73e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions robotoff/prediction/ocr/product_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def process_multi_packaging(match) -> Optional[dict]:
return None

normalized_value, normalized_unit = normalize_weight(value, unit)

# Check that the weight is not extreme
if is_extreme_weight(normalized_value, normalized_unit):
return None

text = f"{count} x {value} {unit}"
result = {
"text": text,
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/prediction/ocr/test_product_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,42 @@ def test_is_suspicious_weight(value: float, unit: str, expected: bool):
),
],
),
(
"10 x 60g",
[
Prediction(
type=PredictionType.product_weight,
data={
"raw": "10 x 60g",
"unit": "g",
"count": "10",
"value": "60",
"notify": False,
"priority": 2,
"matcher_type": "multi_packaging",
"normalized_unit": "g",
"normalized_value": 60,
"automatic_processing": True,
},
value_tag=None,
value="10 x 60 g",
automatic_processing=True,
predictor="regex",
predictor_version="1",
barcode=None,
timestamp=None,
source_image=None,
id=None,
confidence=None,
server_type=ServerType.off,
),
],
),
# Extreme weight should not trigger a prediction
(
"50 x 50kg",
[],
),
],
)
def test_find_product_weight(text: str, expected: list[dict]):
Expand Down

0 comments on commit f5a73e3

Please sign in to comment.