Skip to content
Snippets Groups Projects
Commit 38b4cf04 authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

clean file

parent fa95003d
No related branches found
No related tags found
1 merge request!37Resolve "rematch function and endpoint"
......@@ -81,18 +81,16 @@ class SalamanderClass(Resource):
if salamander:
growth_row = db.session.query(SalamanderGrowth).filter_by(
salamander_id=salamander.id, image_id=int(data['image_id'])).first()
if "weight" in data and data['weight'] != "":
if "weight" in data:
growth_row.weight = sanitize_number_str(str(data['weight']))
db.session.commit()
if "length" in data and data['length'] != "":
if "length" in data:
growth_row.length = sanitize_number_str(str(data['length']))
db.session.commit()
if "location" in data and "new_location" in data and "new_sex" in data and "new_species" in data:
if data['location'] != data['new_location'] and data['sex'] != data['new_sex'] and data['species'] != data['new_species']:
salamander_path = os.path.join("images", data['location'], salamander.species, salamander.sex,
str(salamander.id))
new_path_to_images = os.path.join("images", data['new_location'], data['new_species'],
data['new_sex'])
if data['location'] != data['new_location'] or salamander.sex != data['new_sex'] or salamander.species != data['new_species']:
salamander_path = os.path.join("images", data['location'], salamander.species, salamander.sex, str(salamander.id))
new_path_to_images = os.path.join("images", data['new_location'], data['new_species'], data['new_sex'])
original_path = glob.glob(os.path.join(salamander_path, data['image_id'] + '.*'))
processed_path = glob.glob(os.path.join(salamander_path, data['image_id'] + '_str.*'))
if len(original_path) > 0 and len(processed_path) > 0:
......@@ -102,19 +100,17 @@ class SalamanderClass(Resource):
if result:
image_id = int(data['image_id'])
last_id = int(len(os.listdir(salamander_path)) / 2) - 1
debug_str = ""
path_to_images = os.path.join("images", data['new_location'].lower(),
data['new_species'], data['new_sex'])
# if salamander already exist:
if result > -1:
# move all images and delete previous ID.:
debug_str = " Found a match with ID: " + str(result) + "."
move_images(salamander.id, result, image_id,
path_to_salamander=os.path.join(path_to_images, str(result)),
path_to_original_image=original_path,
path_to_processed_image=processed_path)
else:
debug_str = " It was a new salamander!"
add_salamander(salamander.id, image_id, data['new_location'], data['new_species'],
data['new_sex'], path_to_images, user_id, original_path, processed_path)
# if last image was moved:
......@@ -142,7 +138,7 @@ class SalamanderClass(Resource):
os.rename(original_path,
os.path.join(salamander_path, str(image_id) + original_extension))
return jsonify(
{"id": salamander.id, "message": "salamander moved. " + debug_str, 'status': 200})
{"id": salamander.id, "message": "salamander moved", 'status': 200})
else:
return jsonify(
{"message": "Salamander image, " + data['image_id'] + " does not exist", 'status': 400})
......@@ -183,10 +179,10 @@ def move_images(salamander_id: int = None, new_salamander_id: int = None, image_
path_to_salamander: str = "", path_to_original_image: str = "", path_to_processed_image: str = ""):
path_to_salamander = os.path.abspath(path_to_salamander)
split_name_org = str(path_to_original_image).split('.')
split_name_prccd = str(path_to_processed_image).split('.')
split_name_proc = str(path_to_processed_image).split('.')
number_of_files = int(len(os.listdir(path_to_salamander)) / 2)
a = os.path.join(path_to_salamander, str(number_of_files)) + "." + split_name_org[len(split_name_org) - 1]
b = os.path.join(path_to_salamander, str(number_of_files)) + "_str." + split_name_prccd[len(split_name_org) - 1]
b = os.path.join(path_to_salamander, str(number_of_files)) + "_str." + split_name_proc[len(split_name_org) - 1]
move(path_to_original_image, a)
move(path_to_processed_image, b)
salamander_growth_row = db.session.query(SalamanderGrowth).filter_by(salamander_id=salamander_id,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment