Skip to content

Commit

Permalink
positive feedback functions #27
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvanie85 committed Jun 5, 2024
1 parent 8f9cabe commit 8759c9a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
17 changes: 17 additions & 0 deletions datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions datastore/db/queries/inference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}")

0 comments on commit 8759c9a

Please sign in to comment.