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
06685f0e
Commit
06685f0e
authored
4 years ago
by
adam-abed-abud
Browse files
Options
Downloads
Patches
Plain Diff
Export CSV
parent
19485d81
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
+34
-34
34 additions, 34 deletions
raspberry-backend/app.py
raspberry-backend/templates/base.html
+6
-3
6 additions, 3 deletions
raspberry-backend/templates/base.html
with
40 additions
and
37 deletions
raspberry-backend/app.py
+
34
−
34
View file @
06685f0e
...
...
@@ -324,38 +324,6 @@ class ArduinoClient(HEVClient):
def
progress
(
status
,
remaining
,
total
):
logging
.
debug
(
f
'
Copied
{
total
-
remaining
}
of
{
total
}
pages...
'
)
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
=
Flask
(
__name__
)
...
...
@@ -402,6 +370,38 @@ def fan():
def
multiple_appends
(
listname
,
*
element
):
listname
.
extend
(
element
)
@WEBAPP.route
(
'
/downloadCSV
'
,
methods
=
[
'
get
'
])
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()
# Extract the table headers.
#headers = [i[0] for i in cursor.description]
#cw.writerows(headers)
#csv.writer.writerow (results)
output
=
make_response
(
si
.
getvalue
())
print
(
"
benzinaaaa
\n\n
"
)
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
(
'
/send_cmd
'
,
methods
=
[
'
POST
'
])
def
send_cmd
():
"""
...
...
@@ -412,8 +412,8 @@ def send_cmd():
print
(
client
.
send_cmd
(
"
GENERAL
"
,
"
START
"
))
elif
web_form
.
get
(
'
stop
'
)
==
"
STOP
"
:
print
(
client
.
send_cmd
(
"
GENERAL
"
,
"
STOP
"
))
elif
web_form
.
get
(
'
reset
'
)
==
"
RESET
"
:
print
(
client
.
send_cmd
(
"
GENERAL
"
,
"
RESET
"
))
#
elif web_form.get('reset') == "RESET":
#
print(client.send_cmd("GENERAL", "RESET"))
elif
web_form
.
get
(
'
export
'
)
==
"
EXPORT
"
:
downloadCSV
()
#return render_template('index.html', result=live_data())
...
...
This diff is collapsed.
Click to expand it.
raspberry-backend/templates/base.html
+
6
−
3
View file @
06685f0e
...
...
@@ -85,15 +85,18 @@
<a
href=
"settings"
class =
"nav-link-href nav-link-disabled"
>
<div
class =
"sb-nav-link-icon d-flex justify-content-center border-invisible {{'active' if settings_active}}"
>
<svg
aria-hidden=
"true"
focusable=
"false"
data-prefix=
"fas"
data-icon=
"sliders-h"
class=
"fa-sliders-h fa-w-15"
role=
"img"
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 512 512"
><path
class=
"path-icon"
d=
"M496 384H160v-16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v16H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h80v16c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16v-16h336c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-160h-80v-16c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v16H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h336v16c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16v-16h80c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-160H288V48c0-8.8-7.2-16-16-16h-32c-8.8 0-16 7.2-16 16v16H16C7.2 64 0 71.2 0 80v32c0 8.8 7.2 16 16 16h208v16c0 8.8 7.2 16 16 16h32c8.8 0 16-7.2 16-16v-16h208c8.8 0 16-7.2 16-16V80c0-8.8-7.2-16-16-16z"
></path></svg>
</div></a>
<a
href=
"downloadCSV"
class =
"nav-link-href nav-link-disabled"
>
<div
class =
"sb-nav-link-icon d-flex justify-content-center border-invisible {{'active' if downloadCSV_active}}"
>
<svg
aria-hidden=
"true"
focusable=
"false"
data-prefix=
"fas"
data-icon=
"file-export"
class=
"fa-file-export fa-w-15"
role=
"img"
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 576 512"
><path
fill=
"gray"
d=
"M384 121.9c0-6.3-2.5-12.4-7-16.9L279.1 7c-4.5-4.5-10.6-7-17-7H256v128h128zM571 308l-95.7-96.4c-10.1-10.1-27.4-3-27.4 11.3V288h-64v64h64v65.2c0 14.3 17.3 21.4 27.4 11.3L571 332c6.6-6.6 6.6-17.4 0-24zm-379 28v-32c0-8.8 7.2-16 16-16h176V160H248c-13.2 0-24-10.8-24-24V0H24C10.7 0 0 10.7 0 24v464c0 13.3 10.7 24 24 24h336c13.3 0 24-10.7 24-24V352H208c-8.8 0-16-7.2-16-16z"
></path></svg>
</div></a>
</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>
<input
type=
"submit"
name=
"export"
value=
"EXPORT"
onclick=
"cmdNotification(this
.value
)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
<input
type=
"submit"
name=
"start"
value=
"START"
onclick=
"cmdNotification(this)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
<input
type=
"submit"
name=
"stop"
value=
"STOP"
onclick=
"cmdNotification(this)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
<input
type=
"submit"
name=
"export"
value=
"EXPORT"
onclick=
"cmdNotification(this)"
class=
"lockable sb-nav-button py-1 mb-1"
disabled
></input>
</div>
</form>
...
...
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