From dcd3fee0f3cf61baca0b709d78094d6b2aa954cd Mon Sep 17 00:00:00 2001 From: sylvanie85 Date: Thu, 18 Jul 2024 15:57:21 +0000 Subject: [PATCH 1/3] Update of datastore calls after repo restructuring #107 --- requirements.txt | 2 +- storage/datastore_storage_api.py | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index 30070c8..0805835 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ cryptography pyyaml pydantic python-magic -nachet-datastore @git+https://github.com/ai-cfia/nachet-datastore.git@main +nachet-datastore @git+https://github.com/ai-cfia/nachet-datastore.git@b0d85ce68ed08928b7240c35d9d462cda48ba294 diff --git a/storage/datastore_storage_api.py b/storage/datastore_storage_api.py index 1108e11..0c4f944 100644 --- a/storage/datastore_storage_api.py +++ b/storage/datastore_storage_api.py @@ -1,9 +1,11 @@ """ This module provide an absraction to the nachet-datastore interface. """ +import os import datastore from datastore import db from datastore import user as user_datastore +from datastore import Nachet as nachet_datastore import datastore.bin.deployment_mass_import import datastore.bin.upload_picture_set @@ -21,8 +23,11 @@ class GetPipelinesError(DatastoreError): class UserNotFoundError(DatastoreError): pass +NACHET_DB_URL = os.getenv("NACHET_DB_URL") +NACHET_SCHEMA = os.getenv("NACHET_SCHEMA") + def get_connection() : - return db.connect_db() + return db.connect_db(NACHET_DB_URL, NACHET_SCHEMA) def get_cursor(connection): return db.cursor(connection) @@ -38,7 +43,7 @@ async def get_all_seeds() -> list: try: connection = get_connection() cursor = get_cursor(connection) - return await datastore.get_seed_info(cursor) + return await nachet_datastore.get_seed_info(cursor) except Exception as error: # TODO modify Exception for more specific exception raise SeedNotFoundError(error.args[0]) @@ -89,12 +94,12 @@ async def get_picture_id(cursor, user_id, image_hash_value, container_client) : """ Return the picture_id of the image """ - picture_id = await datastore.upload_picture_unknown(cursor, str(user_id), image_hash_value, container_client) + picture_id = await nachet_datastore.upload_picture_unknown(cursor, str(user_id), image_hash_value, container_client) return picture_id def upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name: str, zoom_level: float = None, nb_seeds: int = None) : try : - return datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name, zoom_level, nb_seeds) + return nachet_datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name, zoom_level, nb_seeds) except Exception as error: raise DatastoreError(error) @@ -112,23 +117,23 @@ async def get_pipelines() -> list: try: connection = get_connection() cursor = get_cursor(connection) - pipelines = await datastore.get_ml_structure(cursor) + pipelines = await nachet_datastore.get_ml_structure(cursor) return pipelines except Exception as error: # TODO modify Exception for more specific exception raise GetPipelinesError(error.args[0]) async def save_inference_result(cursor, user_id:str, inference_dict, picture_id:str, pipeline_id:str, type:int): - return await datastore.register_inference_result(cursor, user_id, inference_dict, picture_id, pipeline_id, type) + return await nachet_datastore.register_inference_result(cursor, user_id, inference_dict, picture_id, pipeline_id, type) async def save_perfect_feedback(cursor, inference_id:str, user_id:str, boxes_id): - await datastore.new_perfect_inference_feeback(cursor, inference_id, user_id, boxes_id) + await nachet_datastore.new_perfect_inference_feeback(cursor, inference_id, user_id, boxes_id) async def save_annoted_feedback(cursor, feedback_dict): - await datastore.new_correction_inference_feedback(cursor, feedback_dict) + await nachet_datastore.new_correction_inference_feedback(cursor, feedback_dict) async def delete_directory_request(cursor, user_id, picture_set_id): try : - return len(await datastore.find_validated_pictures(cursor, user_id, picture_set_id)) > 0 + return len(await nachet_datastore.find_validated_pictures(cursor, user_id, picture_set_id)) > 0 except Exception as error: raise DatastoreError(error) @@ -140,7 +145,7 @@ async def delete_directory_permanently(cursor, user_id, picture_set_id, containe async def delete_directory_with_archive(cursor, user_id, picture_set_id, container_client): try : - return await datastore.delete_picture_set_with_archive(cursor, user_id, picture_set_id, container_client) + return await nachet_datastore.delete_picture_set_with_archive(cursor, user_id, picture_set_id, container_client) except Exception as error: raise DatastoreError(error) From 72678a090b3774cf7132a7bcfa6b9fca31b0ef30 Mon Sep 17 00:00:00 2001 From: sylvanie85 Date: Fri, 26 Jul 2024 15:24:44 +0000 Subject: [PATCH 2/3] datastore repo name and branch --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0805835..1291083 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ cryptography pyyaml pydantic python-magic -nachet-datastore @git+https://github.com/ai-cfia/nachet-datastore.git@b0d85ce68ed08928b7240c35d9d462cda48ba294 +nachet-datastore @git+https://github.com/ai-cfia/ailab-datastore.git@main From 997713c849f3dfe6365b15c99fc3551e22a90c92 Mon Sep 17 00:00:00 2001 From: sylvanie85 Date: Mon, 29 Jul 2024 19:14:16 +0000 Subject: [PATCH 3/3] fix inference request test --- tests/test_inference_request.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_inference_request.py b/tests/test_inference_request.py index e2fb94e..c56fc62 100644 --- a/tests/test_inference_request.py +++ b/tests/test_inference_request.py @@ -70,7 +70,9 @@ def test_inference_request_successful(self, mock_container): "box_id", "inference_id", "object_type_id", - "top_id" + "top_id", + "models", + "pipeline_id" } # Test the answers from inference_request