Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pump, Cedric
lab-rest
Commits
5c3f1c2e
Commit
5c3f1c2e
authored
Mar 28, 2021
by
CedricPump
Browse files
- added plot
parent
2cc8e7b5
Pipeline
#38140
passed with stages
in 1 minute and 22 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
5c3f1c2e
.idea/
token.txt
api/plot.svg
api/api.py
View file @
5c3f1c2e
import
flask
from
flask
import
request
,
jsonify
import
sqlite3
import
matplotlib.pyplot
as
plt
import
numpy
as
np
app
=
flask
.
Flask
(
__name__
)
app
.
config
[
"DEBUG"
]
=
True
...
...
@@ -67,4 +69,34 @@ def api_filter():
return
jsonify
(
results
)
@
app
.
route
(
'/api/v1/resources/books/plot'
,
methods
=
[
'GET'
])
def
book_plot
():
db
=
sqlite3
.
connect
(
'books.db'
)
db
.
row_factory
=
dict_factory
cur
=
db
.
cursor
()
books
=
cur
.
execute
(
'SELECT * FROM books;'
).
fetchall
()
seq
=
np
.
array
([
len
(
book
[
'first_sentence'
])
for
book
in
books
])
pub
=
np
.
array
([
book
[
'published'
]
for
book
in
books
])
plt
.
figure
()
# add pionts
plt
.
scatter
(
pub
,
seq
)
# add linear kurve
fac
,
off
=
np
.
polyfit
(
pub
,
seq
,
1
)
plt
.
plot
(
pub
,
fac
*
pub
+
off
)
# add labels
plt
.
xlabel
(
"date of publication"
)
plt
.
ylabel
(
"length of first sentence in cahrs"
)
# create and open svg
plt
.
savefig
(
"plot.svg"
)
svg
=
open
(
"plot.svg"
).
read
()
return
flask
.
Response
(
svg
,
mimetype
=
'image/svg+xml'
)
app
.
run
()
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment