Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seed_id for batch import #115

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading