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

follow pep 8 and cleanup

parent 4f3fd7a8
Branches
No related tags found
1 merge request!38Resolve "remove dead code and cleanup"
......@@ -29,8 +29,6 @@ class MatchSalamander(Resource):
if data['sex'] in APPROVED_SEX and data['species'] in APPROVED_SPECIES and data['location'].lower() in approved_locations:
temp_img_path = os.path.abspath("./temp_images/")
img_path = os.path.abspath("./images/")
print(temp_img_path)
print(img_path)
list_of_name = glob.glob(os.path.join(temp_img_path, str(user_id) + '.*'))
list_of_name_str = glob.glob(os.path.join(temp_img_path, str(user_id) + '_str.*'))
if len(list_of_name_str) > 0 and len(list_of_name) > 0:
......@@ -47,32 +45,23 @@ class MatchSalamander(Resource):
if data['sex'] != "juvenile":
result = match_file_structure(path_to_processed_image, path_to_images)
if result:
if result > -1:
number_of_files = int(len(os.listdir(os.path.join(path_to_images, str(result)))) / 2)
add_salamander_growth(weight, length, result, number_of_files)
move_and_rename_images(os.path.join(path_to_images, str(result)), path_to_original_image,
path_to_processed_image)
return jsonify(
{"matching": "Match!", "message": "Matched with salamander", "id": result, 'status': 200})
move_and_rename_images(os.path.join(path_to_images, str(result)), path_to_original_image, path_to_processed_image)
return jsonify({"matching": "Match!", "message": "Matched with salamander", "id": result, 'status': 200})
else:
salamander_id = add_salamander(data['location'], data['species'],data['sex'], path_to_images, user_id, path_to_original_image,
path_to_processed_image)
salamander_id = add_salamander(data['location'], data['species'], data['sex'], path_to_images, user_id, path_to_original_image, path_to_processed_image)
number_of_files = int(len(os.listdir(os.path.join(path_to_images, str(salamander_id)))) / 2) - 1
add_salamander_growth(weight, length, salamander_id, number_of_files)
return jsonify(
{"matching": "No Match.", "message": "New salamander in database", "id": salamander_id,
'status': 200})
return jsonify({"matching": "No Match.", "message": "New salamander in database", "id": salamander_id, 'status': 200})
else:
return jsonify({"message": "Internal server error", 'status': 500})
else:
salamander_id = add_salamander(data['location'], data['species'],data['sex'], path_to_images, user_id, path_to_original_image,
path_to_processed_image)
salamander_id = add_salamander(data['location'], data['species'], data['sex'], path_to_images, user_id, path_to_original_image, path_to_processed_image)
number_of_files = int(len(os.listdir(os.path.join(path_to_images, str(salamander_id)))) / 2) - 1
add_salamander_growth(weight, length, salamander_id, number_of_files)
return jsonify({"matching": "No Match.", "message": "New juvenile in database", "id": salamander_id,
'status': 200})
return jsonify({"matching": "No Match.", "message": "New juvenile in database", "id": salamander_id, 'status': 200})
else:
return jsonify({"message": "internal server error", 'status': 500})
else:
......@@ -89,27 +78,17 @@ def add_salamander(location, species, sex, path_to_images, user_id, path_to_orig
salamander_id = db.session.query(Salamander.id).filter_by(uid=user_id).order_by(Salamander.id.desc()).first()
path_for_new_salamander = os.path.join(path_to_images, str(salamander_id[0]))
os.makedirs(path_for_new_salamander)
print("1",path_for_new_salamander)
print("2",path_to_original_image)
print("3",path_to_processed_image)
move_and_rename_images(path_for_new_salamander, path_to_original_image, path_to_processed_image)
return salamander_id[0]
def move_and_rename_images(path_to_salamander: str = "", path_to_original_image: str = "",
path_to_processed_image: str = ""):
print("MOVING")
def move_and_rename_images(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_original = str(path_to_original_image).split('.')
split_name_processed = str(path_to_processed_image).split('.')
number_of_files = int(len(os.listdir(path_to_salamander)) / 2)
print(path_to_original_image)
print(path_to_processed_image)
print(split_name_org)
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]
print("a: ", a)
print("b: ", b)
a = os.path.join(path_to_salamander, str(number_of_files)) + "." + split_name_original[len(split_name_original)-1]
b = os.path.join(path_to_salamander, str(number_of_files)) + "_str." + split_name_processed[len(split_name_original)-1]
move(path_to_original_image, a)
move(path_to_processed_image, b)
......@@ -134,7 +113,7 @@ def sanitize_number_str(string_num: str = None):
if string_num == "":
return None
string_num = string_num.replace(',', '.')
string_num = sub('[^\d\.]', '', string_num)
string_num = sub("[^\d.]", '', string_num)
string_list = string_num.split('.')
# if string_list is greater that 2 the rest is ignored:
if len(string_list) > 1:
......@@ -144,11 +123,12 @@ def sanitize_number_str(string_num: str = None):
string_num = string_list[0] + '.' + string_list[1]
return float(string_num)
def sanitize_int_str(string_num: str = None):
if string_num is None:
return None
if string_num == "":
return None
string_num = sub('[^\d]', '', string_num)
string_num = sub("[^\d]", '', string_num)
# if string_list is greater that 2 the rest is ignored:
return int(string_num)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment