Skip to content

Commit

Permalink
Merge pull request #115 from ai-cfia/98-Update-batch-upload-to-work-a…
Browse files Browse the repository at this point in the history
…round-seed_id

datastore main branch
  • Loading branch information
sylvanie85 authored Aug 2, 2024
2 parents 52e779d + 779ce49 commit 2cf56cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ async def new_batch_import():

container_name = data["container_name"]
user_id = container_name
folder_name = data["folder_name"]
folder_name = data.get("folder_name")
if folder_name == "" :
folder_name = None
nb_pictures = data["nb_pictures"]
Expand Down Expand Up @@ -772,12 +772,13 @@ async def upload_picture():
container_name = data["container_name"]
user_id = container_name
seed_name = data["seed_name"]
seed_id = data.get("seed_id")
zoom_level = data["zoom_level"]
nb_seeds = data["nb_seeds"]
image_base64 = data["image"]
picture_set_id = data["session_id"]

if not (container_name and seed_name and image_base64 and picture_set_id):
if not (container_name and (seed_name or seed_id) and image_base64 and picture_set_id):
raise BatchImportError(
"wrong request arguments: either seed_name, session_id, container_name or image is wrong")

Expand All @@ -788,11 +789,11 @@ async def upload_picture():
_, encoded_data = image_base64.split(",", 1)

image_bytes = base64.b64decode(encoded_data)
image_hash_value = await azure_storage.generate_hash(image_bytes)


connection = datastore.get_connection()
cursor = datastore.get_cursor(connection)
response = await datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, [image_hash_value], seed_name, zoom_level, nb_seeds)
response = await datastore.upload_pictures(cursor, user_id, picture_set_id, container_client, [image_bytes], seed_name, seed_id, zoom_level, nb_seeds)
datastore.end_query(connection, cursor)

if response:
Expand Down
4 changes: 2 additions & 2 deletions storage/datastore_storage_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ async def get_picture_id(cursor, user_id, image, container_client) :
picture_id = await nachet_datastore.upload_picture_unknown(cursor, str(user_id), image, 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) :
def upload_pictures(cursor, user_id, picture_set_id, container_client, pictures, seed_name, seed_id: str, zoom_level: float = None, nb_seeds: int = None) :
try :
return nachet_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, seed_id, zoom_level, nb_seeds)
except Exception as error:
raise DatastoreError(error)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_image_batch_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def setUp(self):
self.session_id = result_json.get("session_id")

self.seed_name = "Ambrosia artemisiifolia"
self.seed_id = "14e96554-aadf-42e4-8665-d141354800d1"
self.zoom_level = None
self.nb_seeds = None
current_dir = os.path.dirname(__file__)
Expand Down Expand Up @@ -204,6 +205,7 @@ def test_upload_picture_successfull(self):
"container_name": self.container_name,
"session_id": self.session_id,
"seed_name": self.seed_name,
"seed_id" : self.seed_id,
"zoom_level": self.zoom_level,
"nb_seeds": self.nb_seeds,
"image": self.image
Expand All @@ -230,6 +232,7 @@ def test_upload_picture_missing_arguments_error(self):
"container_name": self.container_name,
# missing session_id
"seed_name": self.seed_name,
"seed_id" : self.seed_id,
"zoom_level": self.zoom_level,
"nb_seeds": self.nb_seeds,
"image": self.image
Expand Down Expand Up @@ -257,6 +260,7 @@ def test_upload_picture_wrong_arguments_error(self):
"container_name": "", # wrong container_name
"session_id": self.session_id,
"seed_name": self.seed_name,
"seed_id" : self.seed_id,
"zoom_level": self.zoom_level,
"nb_seeds": self.nb_seeds,
"image": self.image
Expand Down

0 comments on commit 2cf56cd

Please sign in to comment.