Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Commits
b4bf4a7b
Commit
b4bf4a7b
authored
Mar 22, 2021
by
Herman Andersen Dyrkorn
Browse files
Options
Downloads
Patches
Plain Diff
follow pep 8 and cleanup
parent
4f3fd7a8
Branches
Branches containing commit
No related tags found
1 merge request
!38
Resolve "remove dead code and cleanup"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/endpoints/matchsalamander.py
+18
-38
18 additions, 38 deletions
api/endpoints/matchsalamander.py
with
18 additions
and
38 deletions
api/endpoints/matchsalamander.py
+
18
−
38
View file @
b4bf4a7b
...
...
@@ -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_or
g
=
str
(
path_to_original_image
).
split
(
'
.
'
)
split_name_pr
cc
d
=
str
(
path_to_processed_image
).
split
(
'
.
'
)
split_name_or
iginal
=
str
(
path_to_original_image
).
split
(
'
.
'
)
split_name_pr
ocesse
d
=
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment