diff --git a/datastore/__init__.py b/datastore/__init__.py index 89f98211..33be8bf1 100644 --- a/datastore/__init__.py +++ b/datastore/__init__.py @@ -248,6 +248,23 @@ async def register_inference_result( raise Exception("Unhandled Error") +async def new_perfect_inference_feeback(cursor, inference_id, user_id, boxes_id) : + """ + Args: + cursor: The cursor object to interact with the database. + inference_id (str): id of the inference on which feedback is given + user_id (str): id of the user giving a feedback + boxes_id (str array): array of id of the objects that are correctly identified + """ + try: + for object_id in boxes_id: + top_inference_id = inference.get_inference_object_top_id(cursor, object_id) + inference.set_inference_object_verified_id(cursor, object_id, top_inference_id ) + inference.set_inference_object_valid(cursor, object_id, True) + except Exception as e: + print(e) + raise Exception("Datastore Unhandled Error") + async def import_ml_structure_from_json_version(cursor, ml_version: dict): """ TODO: build tests diff --git a/datastore/db/queries/inference/__init__.py b/datastore/db/queries/inference/__init__.py index 292dce8d..fb7a24d5 100644 --- a/datastore/db/queries/inference/__init__.py +++ b/datastore/db/queries/inference/__init__.py @@ -112,6 +112,31 @@ def set_inference_object_top_id(cursor, inference_object_id: str, top_id:str): except Exception: raise Exception(f"Error: could not set top_inference_id {top_id} for inference {inference_object_id}") +def get_inference_object_top_id(cursor, inference_object_id: str): + """ + This function gets the top_id of an inference. + + Parameters: + - cursor (cursor): The cursor of the database. + - inference_id (str): The UUID of the inference. + + Returns: + - The UUID of the top. + """ + try: + query = """ + SELECT + top_inference_id + FROM + object + WHERE + id = %s + """ + cursor.execute(query, (inference_object_id,)) + res = cursor.fetchone()[0] + return res + except Exception: + raise Exception(f"Error: could not get top_inference_id for inference {inference_object_id}") def new_seed_object(cursor, seed_id: str, object_id:str,score:float): """ This function uploads a new seed object (seed prediction) to the database. @@ -173,3 +198,48 @@ def get_inference(cursor, inference_id: str): return res except Exception: raise InferenceNotFoundError(f"Error: could not get inference {inference_id}") + + +def set_inference_object_verified_id(cursor, inference_object_id: str, verified_id:str): + """ + This function sets the verified_id of an object. + + Parameters: + - cursor (cursor): The cursor of the database. + - inference_object_id (str): The UUID of the object. + - verified_id (str): The UUID of the verified. + """ + try: + query = """ + UPDATE + object + SET + verified_id = %s + WHERE + id = %s + """ + cursor.execute(query, (verified_id,inference_object_id)) + except Exception: + raise Exception(f"Error: could not update verified_id for object {inference_object_id}") + +def set_inference_object_valid(cursor, inference_object_id: str, is_valid:bool): + """ + This function sets the is_valid of an object. + + Parameters: + - cursor (cursor): The cursor of the database. + - inference_object_id (str): The UUID of the object. + - is_valid (bool): if the inference object is valid + """ + try: + query = """ + UPDATE + object + SET + valid = %s + WHERE + id = %s + """ + cursor.execute(query, (is_valid,inference_object_id)) + except Exception: + raise Exception(f"Error: could not update valid for object {inference_object_id}") \ No newline at end of file