From 18e5c667796eaaf67387b7c751a0c13a448b76cf Mon Sep 17 00:00:00 2001 From: Gabriel Ben Zenou <112394931+GabrielBeFr@users.noreply.github.com> Date: Mon, 10 Oct 2022 15:30:01 +0200 Subject: [PATCH] fix: adding documentation about the insights/annotate.py file (#944) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: adding documentation about the insights/annotate.py file * Format code with black and isort * Update robotoff/insights/annotate.py Co-authored-by: Raphaël Bournhonesque * Update robotoff/insights/annotate.py Co-authored-by: Raphaël Bournhonesque * Format code with black and isort * Update robotoff/insights/annotate.py Co-authored-by: Pierre Slamich * Update robotoff/insights/annotate.py Co-authored-by: Pierre Slamich * Update robotoff/insights/annotate.py Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> Co-authored-by: Raphaël Bournhonesque Co-authored-by: Pierre Slamich --- robotoff/insights/annotate.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/robotoff/insights/annotate.py b/robotoff/insights/annotate.py index 5bb435a046..9f75621658 100644 --- a/robotoff/insights/annotate.py +++ b/robotoff/insights/annotate.py @@ -23,6 +23,18 @@ from robotoff.products import get_image_id, get_product from robotoff.utils import get_logger +""" +This file allows to annotate products. + +To check whether the annotation already exists or not (and save it and send it to the Open Food Facts database), use the following commands: + from robotoff.insights.annotate import InsightAnnotatorFactor + annotator = InsightAnnotatorFactory.get(insight_type) + annotator.annotate(insight: ProductInsight, annotation: int, update: bool = True, data: Optional[Dict] = None, auth: Optional[OFFAuthentication] = None, automatic: bool = False) + +If you don't want to update the Open Food Facts database but only save the insight annotation (if the update is performed on the client side for example), you can call `annotate()` with `update=False`. +""" + + logger = get_logger(__name__) @@ -121,7 +133,9 @@ def _annotate( if annotation == 1 and update: # Save insight before processing the annotation insight.save() - annotation_result = self.process_annotation(insight, data=data, auth=auth) + annotation_result = self.process_annotation( + insight, data=data, auth=auth + ) # calls the process_annotation function of the class corresponding to the current insight type else: annotation_result = SAVED_ANNOTATION_RESULT