Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HEV - High Energy Ventilator
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Projects
HEV - High Energy Ventilator
Commits
5f6c442b
Commit
5f6c442b
authored
4 years ago
by
Stephen Farry
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
ssh://gitlab.cern.ch:7999/hev-sw/hev-sw
parents
1b4b9ada
c7bb8752
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
raspberry-backend/app.py
+37
-0
37 additions, 0 deletions
raspberry-backend/app.py
raspberry-backend/templates/base.html
+9
-2
9 additions, 2 deletions
raspberry-backend/templates/base.html
with
46 additions
and
2 deletions
raspberry-backend/app.py
+
37
−
0
View file @
5f6c442b
...
...
@@ -17,6 +17,8 @@ from datetime import datetime
import
logging
logging
.
basicConfig
(
level
=
logging
.
WARNING
,
format
=
'
%(asctime)s - %(levelname)s - %(message)s
'
)
import
io
import
csv
import
sys
import
argparse
import
sqlite3
...
...
@@ -440,6 +442,41 @@ def send_ack():
return
(
''
,
204
)
@WEBAPP.route
(
"
/downloadCSV
"
,
methods
=
[
'
POST
'
])
def
downloadCSV
():
sqlSelect
=
"
SELECT * FROM hev_monitor_data;
"
timestr
=
time
.
strftime
(
"
%Y%m%d-%H%M%S
"
)
fileName
=
'
export_
'
+
timestr
+
'
.csv
'
try
:
conn
=
sqlite3
.
connect
(
SQLITE_FILE
,
check_same_thread
=
False
,
uri
=
True
)
cursor
=
conn
.
cursor
()
si
=
io
.
StringIO
()
cw
=
csv
.
writer
(
si
,
dialect
=
'
excel
'
,
delimiter
=
'
,
'
)
for
row
in
cursor
.
execute
(
sqlSelect
):
cw
.
writerow
(
row
)
#results = cursor.fetchall()
#print(results)
# Extract the table headers.
#headers = [i[0] for i in cursor.description]
#cw.writerows(headers)
#csv.writer.writerow (results)
output
=
make_response
(
si
.
getvalue
())
output
.
headers
[
"
Content-Disposition
"
]
=
"
attachment; filename=
"
+
fileName
output
.
headers
[
"
Content-type
"
]
=
"
text/csv
"
output
.
headers
[
"
charset
"
]
=
'
utf-8-sig
'
print
(
"
Data export successful.
"
)
except
sqlite3
.
Error
as
err
:
conn
.
close
()
raise
Exception
(
"
sqlite3 error. CSV export failed: {}
"
.
format
(
str
(
err
)))
finally
:
conn
.
close
()
return
output
@WEBAPP.route
(
'
/live-data
'
,
methods
=
[
'
GET
'
])
def
live_data
():
...
...
This diff is collapsed.
Click to expand it.
raspberry-backend/templates/base.html
+
9
−
2
View file @
5f6c442b
...
...
@@ -87,15 +87,22 @@
</div></a>
</div>
</div>
<form
action=
"{{ url_for('send_cmd') }}"
method=
"post"
>
<div
class =
"controls py-1 ml-auto mr-auto"
>
<input
type=
"submit"
name=
"start"
value=
"START"
onclick=
"cmdNotification(this.value)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
<input
type=
"submit"
name=
"stop"
value=
"STOP"
onclick=
"cmdNotification(this.value)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
</div>
</form>
<!-- <input type="submit" name="reset" value="RESET" onclick="cmdNotification(this.value)" class="sb-nav-button py-1 mb-1"></input> -->
<form
action=
"{{ url_for('downloadCSV') }}"
method=
"post"
>
<div
class =
"controls py-1 ml-auto mr-auto"
>
<input
type=
"submit"
name=
"export"
value=
"EXPORT"
onclick=
"cmdNotification(this.value)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
</div>
</form>
</div>
</nav>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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