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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Herman Andersen Dyrkorn
Salamander - API
Commits
613cbc38
Commit
613cbc38
authored
3 years ago
by
Herman Andersen Dyrkorn
Browse files
Options
Downloads
Patches
Plain Diff
fix bug for new id when salamander is not rematched
parent
921afc8f
Branches
Branches containing commit
No related tags found
1 merge request
!50
Resolve "refactor edit salamander"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/endpoints/editsalamander.py
+17
-12
17 additions, 12 deletions
api/endpoints/editsalamander.py
with
17 additions
and
12 deletions
api/endpoints/editsalamander.py
+
17
−
12
View file @
613cbc38
...
...
@@ -144,9 +144,12 @@ class EditSalamander(Resource):
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
'
]
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
'
])
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
:
...
...
@@ -156,7 +159,8 @@ class EditSalamander(Resource):
last_id
=
int
(
len
(
os
.
listdir
(
salamander_path
))
/
2
)
-
1
if
data
[
'
new_sex
'
]
!=
"
juvenile
"
:
result
=
match_file_structure
(
input_image
=
processed_path
,
match_directory
=
new_path_to_images
)
result
=
match_file_structure
(
input_image
=
processed_path
,
match_directory
=
new_path_to_images
)
if
result
:
# if salamander already exist:
if
result
>
-
1
:
...
...
@@ -172,18 +176,19 @@ class EditSalamander(Resource):
data
[
'
new_sex
'
],
new_path_to_images
,
user_id
,
original_path
,
processed_path
)
return
handle_remaining_images
(
salamander
,
salamander_path
,
image_id
,
last_id
,
True
,
result
)
True
,
result
,
0
)
else
:
return
jsonify
(
{
"
message
"
:
"
Salamander image,
"
+
data
[
'
image_id
'
]
+
"
does not exist
"
,
'
status
'
:
400
})
# if last image was moved:
else
:
add_salamander
(
salamander
.
id
,
image_id
,
data
[
'
new_location
'
],
data
[
'
new_species
'
],
data
[
'
new_sex
'
],
new_path_to_images
,
user_id
,
original_path
,
processed_path
)
new_id
=
add_salamander
(
salamander
.
id
,
image_id
,
data
[
'
new_location
'
],
data
[
'
new_species
'
],
data
[
'
new_sex
'
],
new_path_to_images
,
user_id
,
original_path
,
processed_path
)
return
handle_remaining_images
(
salamander
,
salamander_path
,
image_id
,
last_id
,
False
,
0
)
False
,
0
,
new_id
)
else
:
return
jsonify
({
"
message
"
:
"
Image id,
"
+
data
[
'
image_id
'
]
+
"
does not exist in salamander_id,
"
+
data
[
'
id
'
],
'
status
'
:
400
})
...
...
@@ -205,7 +210,7 @@ def delete_growth_row(salamander_id, image_id):
db
.
session
.
commit
()
def
handle_remaining_images
(
salamander
,
salamander_path
:
str
,
image_id
:
int
,
last_id
:
int
,
match_bool
,
result
):
def
handle_remaining_images
(
salamander
,
salamander_path
:
str
,
image_id
:
int
,
last_id
:
int
,
match_bool
,
result
,
new_id
):
# if last image was moved:
if
len
(
os
.
listdir
(
salamander_path
))
==
0
:
os
.
rmdir
(
salamander_path
)
...
...
@@ -215,7 +220,7 @@ def handle_remaining_images(salamander, salamander_path: str, image_id: int, las
return
jsonify
({
"
id
"
:
result
,
"
matching
"
:
"
Match!
"
,
"
message
"
:
"
Matched with salamander
"
,
'
status
'
:
200
})
else
:
return
jsonify
(
{
"
id
"
:
salamander
.
id
,
"
matching
"
:
"
No match.
"
,
"
message
"
:
"
New salamander in database
"
,
'
status
'
:
200
})
{
"
id
"
:
new_
id
,
"
matching
"
:
"
No match.
"
,
"
message
"
:
"
New salamander in database
"
,
'
status
'
:
200
})
else
:
if
image_id
!=
last_id
:
...
...
@@ -233,7 +238,7 @@ def handle_remaining_images(salamander, salamander_path: str, image_id: int, las
return
jsonify
({
"
id
"
:
result
,
"
matching
"
:
"
Match!
"
,
"
message
"
:
"
Matched with salamander
"
,
'
status
'
:
200
})
else
:
return
jsonify
(
{
"
id
"
:
salamander
.
id
,
"
matching
"
:
"
No match.
"
,
"
message
"
:
"
New salamander in database
"
,
'
status
'
:
200
})
{
"
id
"
:
new_
id
,
"
matching
"
:
"
No match.
"
,
"
message
"
:
"
New salamander in database
"
,
'
status
'
:
200
})
def
lower_image_id_growth_row
(
salamander_id
,
old_id
,
new_id
):
...
...
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