Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
py-data-flask
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Georg Wechslberger
py-data-flask
Commits
c2995c65
Commit
c2995c65
authored
Jun 04, 2018
by
Georg Wechslberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
intial example
parents
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
data-service.py
data-service.py
+29
-0
No files found.
data-service.py
0 → 100644
View file @
c2995c65
from
flask
import
Flask
,
request
from
flask_cors
import
CORS
from
json_tricks
import
dumps
from
numpy
import
arange
,
reshape
,
sin
app
=
Flask
(
__name__
)
# CORS is required to query this service from other webservers than this local python server
CORS
(
app
)
# simple plot of a line
@app.route
(
"/plot/test1"
,
methods
=
[
'POST'
])
def
plotdata
():
# create a data structe of the form { x: [ ], y: [] } and send it back
data
=
{
'x'
:
arange
(
0
,
10
,
1
,
dtype
=
int
),
'y'
:
arange
(
2
,
12
,
dtype
=
int
)}
return
dumps
(
data
,
primitives
=
True
)
# plot of f(x;k) = sin(k*x) with paramter k being specified by the client
@app.route
(
"/plot/test2"
,
methods
=
[
'POST'
])
def
plotdata2
():
# parse the value of the parameter k from the request
options
=
request
.
get_json
()
k
=
options
[
'k'
]
# create a data structe of the form { x: [ x_i ], y: [sin(k*x_i)] } and send it back
data
=
{
'x'
:
arange
(
0
,
6.2
,
0.1
,
dtype
=
float
),
'y'
:
sin
(
k
*
arange
(
0
,
6.2
,
0.1
,
dtype
=
float
))}
return
dumps
(
data
,
primitives
=
True
)
if
__name__
==
"__main__"
:
app
.
run
()
\ No newline at end of file
Write
Preview
Markdown
is supported
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