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
Vladislav Rykov
THSO.server
Commits
20afa51b
Commit
20afa51b
authored
Apr 14, 2020
by
Vladislav Rykov
Browse files
dev-data view works
parent
df4cbc69
Changes
7
Hide whitespace changes
Inline
Side-by-side
dao/data/__init.py
__
→
dao/data/__init
__
.py
View file @
20afa51b
File moved
dao/data/__init__.pyc
0 → 100644
View file @
20afa51b
File added
dao/data/data.py
View file @
20afa51b
...
...
@@ -23,8 +23,8 @@ def with_psql(f):
@
with_psql
def
create_table
(
cur
,
appkey
,
dev
_
id
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev
_
id
)
def
create_table
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
cur
.
execute
(
sql
.
SQL
(
"""CREATE TABLE {} (
...
...
@@ -37,8 +37,8 @@ def create_table(cur, appkey, dev_id):
@
with_psql
def
delete_table
(
cur
,
appkey
,
dev
_
id
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev
_
id
)
def
delete_table
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
cur
.
execute
(
psycopg2
.
sql
.
SQL
(
"DROP TABLE {}"
...
...
@@ -47,8 +47,8 @@ def delete_table(cur, appkey, dev_id):
@
with_psql
def
get_last_n
(
cur
,
appkey
,
dev
_
id
,
n
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev
_
id
)
def
get_last_n
(
cur
,
appkey
,
devid
,
n
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
query
=
"""
SELECT * FROM
{}
...
...
@@ -56,24 +56,36 @@ def get_last_n(cur, appkey, dev_id, n):
utc DESC
LIMIT %s
"""
cur
.
execute
(
sql
.
SQL
(
query
).
format
(
sql
.
Identifier
(
tn
)),
[
n
])
data
=
cur
.
fetchall
()
cur
.
execute
(
sql
.
SQL
(
query
).
format
(
sql
.
Identifier
(
tn
)),
[
n
])
data
=
cur
.
fetchall
()
if
(
data
==
[]):
return
(
False
,
'There is no data for the device.'
)
else
:
return
(
True
,
data
)
if
(
data
==
[]):
return
(
False
,
'There is no data for the device.'
)
else
:
return
(
True
,
data
)
@
with_psql
def
get_all
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
dev
_
id
)
query
=
"""
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
query
=
"""
SELECT * FROM
{}
"""
cur
.
execute
(
sql
.
SQL
(
query
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,
cur
.
fetchall
())
cur
.
execute
(
sql
.
SQL
(
query
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,
cur
.
fetchall
())
@
with_psql
def
get_count
(
cur
,
appkey
,
devid
):
tn
=
'dev_'
+
str
(
appkey
)
+
'_'
+
str
(
devid
)
query
=
"""
SELECT COUNT(utc) FROM
{}
"""
cur
.
execute
(
sql
.
SQL
(
query
).
format
(
sql
.
Identifier
(
tn
)))
return
(
True
,
cur
.
fetchone
())
dao/data/data.pyc
0 → 100644
View file @
20afa51b
File added
server.py
View file @
20afa51b
...
...
@@ -6,6 +6,7 @@ import dao.user.user as ud
import
dao.application.application
as
ad
import
dao.device.device
as
dd
import
dao.pend.pend
as
pend
import
dao.data.data
as
data
import
binascii
...
...
@@ -126,7 +127,7 @@ def delete_app():
devs
=
dh
.
get_list
(
session
[
'appkey'
])
for
dev
in
devs
[
1
]:
d
h
.
delete_
data
table
(
session
[
'appkey'
],
dev
[
1
])
d
ata
.
delete_table
(
session
[
'appkey'
],
dev
[
1
])
dh
.
delete_table
(
session
[
'appkey'
])
...
...
@@ -169,7 +170,7 @@ def dev():
if
not
res
[
0
]:
return
render_template
(
'add-dev.html'
,
feedback
=
res
[
1
])
else
:
res
=
d
h
.
create_
data
table
(
session
[
'appkey'
],
request
.
form
[
'devid'
])
res
=
d
ata
.
create_table
(
session
[
'appkey'
],
request
.
form
[
'devid'
])
if
not
res
[
0
]:
dh
.
delete
(
session
[
'appkey'
],
request
.
form
[
'devid'
])
...
...
@@ -210,15 +211,21 @@ def dev_conf():
@
server
.
route
(
'/delete-dev'
)
def
delete_dev
():
dh
=
dd
.
DeviceDao
()
d
h
.
delete_
data
table
(
session
[
'appkey'
],
request
.
args
.
get
(
'
id'
)
)
res
=
dh
.
delete
(
session
[
'appkey'
],
request
.
args
.
get
(
'
id'
)
)
d
ata
.
delete_table
(
session
[
'appkey'
],
session
[
'dev
id'
]
)
res
=
dh
.
delete
(
session
[
'appkey'
],
session
[
'dev
id'
]
)
return
redirect
(
url_for
(
'app'
,
appkey
=
session
[
'appkey'
]))
@
server
.
route
(
'/dev-data'
)
def
dev_data
():
pass
last
=
data
.
get_last_n
(
session
[
'appkey'
],
session
[
'devid'
],
5
)
count
=
data
.
get_count
(
session
[
'appkey'
],
session
[
'devid'
])
print
(
last
)
print
(
count
)
return
render_template
(
'dev-data.html'
,
data
=
last
[
1
],
total
=
count
[
1
][
0
])
if
__name__
==
'__main__'
:
server
.
secret_key
=
'sdjfklsjf^$654sd^#sPH'
...
...
templates/dev-data.html
View file @
20afa51b
...
...
@@ -8,16 +8,22 @@
<div
class=
"col-md-6 col-md-offset-3"
>
<p>
Last 5 messages:
</p>
<table>
{% for data %}
<table
class=
"table"
>
<thead>
<th>
Time
</th>
<th>
Content
</th>
</thead>
<tbody>
{% for d in data %}
<tr>
<th>
{{ d
ata
[1] }}
</th>
<th>
{{ d
ata
[2] }}
</th>
<th>
{{ d[1] }}
</th>
<th>
{{ d[2] }}
</th>
</tr>
{% endfor %}
</tbody>
</table>
<p>
Total {{ total }} messages.
</p>
<p>
Total
:
{{ total }} messages.
</p>
<a
href=
"/data-csv"
><button
type=
"submit"
class=
"btn btn-primary"
>
Download CSV
</button></a>
</div>
...
...
templates/dev.html
View file @
20afa51b
...
...
@@ -12,9 +12,9 @@
<p>
Description : {{ dev[2] }}
</p>
<p>
Last time up : {{ ltup }}
</p>
<a
href=
"/d
ata?id={{ dev[1] }}
"
><button
type=
"submit"
class=
"btn btn-primary"
>
Data
</button></a>
<a
href=
"/dev-conf
?id={{ dev[1] }}
"
><button
type=
"submit"
class=
"btn btn-primary"
>
Configure
</button></a>
<a
href=
"/delete-dev
?id={{ dev[1] }}
"
><button
type=
"submit"
class=
"btn btn-danger"
onclick=
"return conf();"
>
Delete Device
</button></a>
<a
href=
"/d
ev-data
"
><button
type=
"submit"
class=
"btn btn-primary"
>
Data
</button></a>
<a
href=
"/dev-conf"
><button
type=
"submit"
class=
"btn btn-primary"
>
Configure
</button></a>
<a
href=
"/delete-dev"
><button
type=
"submit"
class=
"btn btn-danger"
onclick=
"return conf();"
>
Delete Device
</button></a>
</div>
</div>
...
...
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