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
a49eb0c6
Commit
a49eb0c6
authored
Jun 10, 2021
by
Herman Andersen Dyrkorn
Browse files
Options
Downloads
Plain Diff
Merge branch '43-merge-salamanderid-and-salamanderclass-endpoint' into 'master'
Resolve "merge salamanderid and salamanderclass endpoint" Closes
#43
See merge request
!46
parents
4e85fd35
82f781c4
Branches
Branches containing commit
No related tags found
1 merge request
!46
Resolve "merge salamanderid and salamanderclass endpoint"
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/__init__.py
+7
-9
7 additions, 9 deletions
api/__init__.py
api/endpoints/editsalamander.py
+56
-1
56 additions, 1 deletion
api/endpoints/editsalamander.py
api/endpoints/salamanderimageid.py
+0
-75
0 additions, 75 deletions
api/endpoints/salamanderimageid.py
with
63 additions
and
85 deletions
api/__init__.py
+
7
−
9
View file @
a49eb0c6
...
...
@@ -11,7 +11,7 @@ app = Flask(__name__)
app
.
config
[
'
SECRET_KEY
'
]
=
'
randomchangethisshit
'
app
.
config
[
'
SQLALCHEMY_DATABASE_URI
'
]
=
'
sqlite:///database/database.db
'
app
.
config
[
'
JWT_AUTH_USERNAME_KEY
'
]
=
'
email
'
app
.
config
[
'
JWT_ACCESS_TOKEN_EXPIRES
'
]
=
5
*
3600
app
.
config
[
'
JWT_ACCESS_TOKEN_EXPIRES
'
]
=
12
*
3600
db
=
SQLAlchemy
(
app
)
jwt
=
JWTManager
(
app
)
bcrypt
=
Bcrypt
(
app
)
...
...
@@ -24,13 +24,12 @@ from api.endpoints.user import UserEndpoint
from
api.endpoints.location
import
LocationEndpoint
from
api.endpoints.manageuser
import
AdminManageUser
from
api.endpoints.verifypassword
import
VerifyPassword
from
api.endpoints.pendingusers
import
AdminPendingUsers
from
api.endpoints.salamander
import
SalamanderEndpoint
from
api.endpoints.salamander
s
import
Salamander
sEndpoint
from
api.endpoints.
salamanderimageid
import
SalamanderImageEndpoint
from
api.endpoints.
edit
salamander
import
Edit
Salamander
from
api.endpoints.
pendingusers
import
AdminPendingUsers
from
api.endpoints.matchsalamander
import
MatchSalamander
from
api.endpoints.salamanders
import
SalamandersEndpoint
from
api.endpoints.findsalamanderinfo
import
FindSalamanderInfo
from
api.endpoints.salamanderclass
import
SalamanderClass
api
.
add_resource
(
Login
,
"
/login
"
)
...
...
@@ -39,9 +38,8 @@ api.add_resource(LocationEndpoint, "/location")
api
.
add_resource
(
AdminManageUser
,
"
/manageUsers
"
)
api
.
add_resource
(
VerifyPassword
,
"
/verifyPassword
"
)
api
.
add_resource
(
AdminPendingUsers
,
"
/pendingUsers
"
)
api
.
add_resource
(
SalamandersEndpoint
,
"
/salamanders/<location_name>
"
)
api
.
add_resource
(
SalamanderEndpoint
,
"
/salamander/<salamander_id>
"
)
api
.
add_resource
(
SalamanderImageEndpoint
,
"
/salamanderImage/<salamander_id>/<image_id>
"
)
api
.
add_resource
(
MatchSalamander
,
"
/matchSalamander
"
)
api
.
add_resource
(
FindSalamanderInfo
,
"
/findSalamanderInfo
"
)
api
.
add_resource
(
SalamanderClass
,
"
/editSalamander
"
)
api
.
add_resource
(
SalamanderEndpoint
,
"
/salamander/<salamander_id>
"
)
api
.
add_resource
(
SalamandersEndpoint
,
"
/salamanders/<location_name>
"
)
api
.
add_resource
(
EditSalamander
,
"
/editSalamander
"
,
"
/editSalamander/<salamander_id>/<image_id>
"
)
This diff is collapsed.
Click to expand it.
api/endpoints/salamander
class
.py
→
api/endpoints/
edit
salamander.py
+
56
−
1
View file @
a49eb0c6
...
...
@@ -9,11 +9,66 @@ from api.endpoints.matchsalamander import sanitize_number_str
import
glob
from
shutil
import
move
from
path_constants
import
_ACCESS_DATABASE
from
image_encoder.image_encoder
import
*
import
cv2
class
Salamander
Class
(
Resource
):
class
Edit
Salamander
(
Resource
):
decorators
=
[
limiter
.
limit
(
"
60/minute
"
)]
@staticmethod
@jwt_required
def
get
(
salamander_id
,
image_id
):
user_id
=
get_jwt_identity
()
user
=
db
.
session
.
query
(
User
).
filter_by
(
id
=
user_id
).
first
()
if
user
.
admin
:
with
_ACCESS_DATABASE
:
salamander
=
db
.
session
.
query
(
Salamander
).
filter_by
(
id
=
salamander_id
).
first
()
salamander_growth
=
db
.
session
.
query
(
SalamanderGrowth
).
filter_by
(
salamander_id
=
salamander
.
id
,
image_id
=
image_id
).
first
()
if
salamander
and
salamander_growth
:
location
=
db
.
session
.
query
(
Location
).
filter_by
(
id
=
salamander
.
location_id
).
first
()
salamander_images
=
[]
path_to_salamander_images
=
os
.
path
.
join
(
"
./images
"
,
location
.
name
,
salamander
.
species
,
salamander
.
sex
,
str
(
salamander
.
id
))
list_of_paths
=
glob
.
glob
(
os
.
path
.
join
(
path_to_salamander_images
,
'
*.*
'
))
for
path
in
list_of_paths
:
basename
=
os
.
path
.
basename
(
path
)
if
basename
.
__contains__
(
str
(
image_id
)):
image
=
cv2
.
imread
(
path
)
if
not
basename
.
__contains__
(
"
str
"
):
# Scale only original to set size
height
,
width
,
_
=
image
.
shape
desired_long_side
=
320
scaling_factor
=
1
if
width
>
height
:
scaling_factor
=
desired_long_side
/
width
else
:
scaling_factor
=
desired_long_side
/
height
new_dim
=
(
int
(
width
*
scaling_factor
),
int
(
height
*
scaling_factor
))
# resize image
image
=
cv2
.
resize
(
image
,
new_dim
,
interpolation
=
cv2
.
INTER_AREA
)
_
,
buffer
=
cv2
.
imencode
(
'
.jpg
'
,
image
)
encoded
=
base64
.
b64encode
(
buffer
)
image_data
=
{
"
url
"
:
"
data:image/png;base64,
"
+
encoded
.
decode
()}
salamander_images
.
append
(
image_data
)
return
jsonify
({
"
images
"
:
salamander_images
,
"
length
"
:
salamander_growth
.
length
,
"
weight
"
:
salamander_growth
.
weight
,
"
imageId
"
:
image_id
,
"
location
"
:
location
.
name
,
"
salamanderId
"
:
salamander
.
id
,
"
sex
"
:
salamander
.
sex
,
"
species
"
:
salamander
.
species
,
'
status
'
:
200
})
else
:
return
jsonify
({
"
message
"
:
"
no salamander with this id or no growth data
"
,
'
status
'
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
no access to this endpoint
"
,
'
status
'
:
400
})
@staticmethod
@jwt_required
def
delete
():
...
...
This diff is collapsed.
Click to expand it.
api/endpoints/salamanderimageid.py
deleted
100644 → 0
+
0
−
75
View file @
4e85fd35
import
sys
from
flask
import
jsonify
from
flask_jwt_extended
import
jwt_required
,
get_jwt_identity
from
flask_restful
import
Resource
from
api
import
db
,
limiter
from
api.models.dbmodels
import
Location
,
User
,
Salamander
,
SalamanderGrowth
import
os
import
glob
import
cv2
import
sys
from
image_encoder.image_encoder
import
*
from
path_constants
import
_ACCESS_DATABASE
import
cv2
# get one specific image on a specific salamander based on s_id and i_id
class
SalamanderImageEndpoint
(
Resource
):
decorators
=
[
limiter
.
limit
(
"
60/minute
"
)]
@staticmethod
@jwt_required
def
get
(
salamander_id
,
image_id
):
user_id
=
get_jwt_identity
()
user
=
db
.
session
.
query
(
User
).
filter_by
(
id
=
user_id
).
first
()
if
user
.
admin
:
with
_ACCESS_DATABASE
:
salamander
=
db
.
session
.
query
(
Salamander
).
filter_by
(
id
=
salamander_id
).
first
()
salamander_growth
=
db
.
session
.
query
(
SalamanderGrowth
).
filter_by
(
salamander_id
=
salamander
.
id
,
image_id
=
image_id
).
first
()
if
salamander
and
salamander_growth
:
location
=
db
.
session
.
query
(
Location
).
filter_by
(
id
=
salamander
.
location_id
).
first
()
salamander_images
=
[]
path_to_salamander_images
=
os
.
path
.
join
(
"
./images
"
,
location
.
name
,
salamander
.
species
,
salamander
.
sex
,
str
(
salamander
.
id
))
list_of_paths
=
glob
.
glob
(
os
.
path
.
join
(
path_to_salamander_images
,
'
*.*
'
))
for
path
in
list_of_paths
:
basename
=
os
.
path
.
basename
(
path
)
if
basename
.
__contains__
(
str
(
image_id
)):
image
=
cv2
.
imread
(
path
)
if
not
basename
.
__contains__
(
"
str
"
):
#Scale only original to set size
height
,
width
,
_
=
image
.
shape
print
(
sys
.
getsizeof
(
image
))
desired_long_side
=
320
scaling_factor
=
1
if
width
>
height
:
scaling_factor
=
desired_long_side
/
width
else
:
scaling_factor
=
desired_long_side
/
height
new_dim
=
(
int
(
width
*
scaling_factor
),
int
(
height
*
scaling_factor
))
# resize image
image
=
cv2
.
resize
(
image
,
new_dim
,
interpolation
=
cv2
.
INTER_AREA
)
print
(
sys
.
getsizeof
(
image
))
_
,
buffer
=
cv2
.
imencode
(
'
.jpg
'
,
image
)
encoded
=
base64
.
b64encode
(
buffer
)
image_data
=
{
"
url
"
:
"
data:image/png;base64,
"
+
encoded
.
decode
()}
salamander_images
.
append
(
image_data
)
return
jsonify
({
"
images
"
:
salamander_images
,
"
length
"
:
salamander_growth
.
length
,
"
weight
"
:
salamander_growth
.
weight
,
"
imageId
"
:
image_id
,
"
location
"
:
location
.
name
,
"
salamanderId
"
:
salamander
.
id
,
"
sex
"
:
salamander
.
sex
,
"
species
"
:
salamander
.
species
,
'
status
'
:
200
})
else
:
return
jsonify
({
"
message
"
:
"
no salamander with this id or no growth data
"
,
'
status
'
:
400
})
else
:
return
jsonify
({
"
message
"
:
"
no access to this endpoint
"
,
'
status
'
:
400
})
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