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
5b12e9a8
Commit
5b12e9a8
authored
May 04, 2020
by
Vladislav Rykov
Browse files
dev data javascript improvement
parent
ed30c99e
Changes
3
Show whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-35.pyc
View file @
5b12e9a8
No preview for this file type
app/app/templates/public/dev-data-t.html
View file @
5b12e9a8
...
...
@@ -104,19 +104,12 @@
{% if data %}
<script
type=
"text/javascript"
>
google
.
charts
.
load
(
'
current
'
,
{
'
packages
'
:[
'
corechart
'
]});
google
.
charts
.
setOnLoadCallback
(
drawChart
);
{
%
for
k
in
data
[
0
][
2
]
%
}
function
drawChart_
{{
k
}}
()
{
var
data_
{{
k
}}
=
google
.
visualization
.
arrayToDataTable
([
[
'
Time
'
,
'
{{ k }}
'
],
{
%
for
d
in
data
|
reverse
%
}
[
new
Date
({{
d
[
0
]
}}
*
1000
),
{{
d
[
2
][
k
]
}}],
{
%
endfor
%
}
]);
function
drawChart
(
dname
,
ddata
)
{
var
data
=
google
.
visualization
.
arrayToDataTable
(
ddata
);
var
options
_
{{
k
}}
=
{
title
:
'
{{ devname}} >
{{ k }}
'
,
var
options
=
{
title
:
'
{{ devname
}} >
'
+
dname
,
curveType
:
'
function
'
,
hAxis
:
{
format
:
'
dd/MM/yy hh:mm:ss
'
,
...
...
@@ -133,12 +126,10 @@
chartArea
:
{
left
:
0
,
top
:
10
,
width
:
'
100%
'
}
};
var
container_
{{
k
}}
=
document
.
getElementById
(
'
curve_chart_{{ k }}
'
);
var
chart_
{{
k
}}
=
new
google
.
visualization
.
LineChart
(
container_
{{
k
}});
//google.visualization.events.addListener(chart_{{ k }}, 'ready', function () { container_{{ k }}.className = ''; });
chart_
{{
k
}}.
draw
(
data_
{{
k
}},
options_
{{
k
}});
var
container
=
document
.
getElementById
(
'
curve_chart_
'
+
dname
);
var
chart
=
new
google
.
visualization
.
LineChart
(
container
);
chart
.
draw
(
data
,
options
);
}
{
%
endfor
%
}
function
display_data
(
evt
,
dname
)
{
// Declare all variables
...
...
@@ -160,7 +151,8 @@
document
.
getElementById
(
dname
).
style
.
display
=
"
block
"
;
evt
.
currentTarget
.
className
+=
"
active
"
;
eval
(
'
drawChart_
'
+
dname
+
'
()
'
);
fetch
(
window
.
origin
+
'
/dev-data/
'
+
dname
+
'
/graph/200/1
'
).
then
(
res
=>
res
.
text
()).
then
(
data
=>
drawChart
(
dname
,
eval
(
data
)));
}
document
.
getElementById
(
"
tab_{{ data[0][2] | first }}
"
).
click
();
...
...
app/app/views.py
View file @
5b12e9a8
...
...
@@ -470,5 +470,21 @@ def settings():
return
redirect
(
request
.
url
)
@
app
.
route
(
'/dev-data/<var>/<dest>/<cnt>/<page>'
)
def
dev_data
(
var
,
dest
,
cnt
,
page
):
if
dest
==
'graph'
:
# for graph <cnt> is in hours
last
=
data
.
get_last_range
(
session
[
'appkey'
],
session
[
'devid'
],
[
int
(
cnt
),
(
int
(
page
)
-
1
)
*
int
(
cnt
)])
arr
=
'[["Time", "{}"],'
.
format
(
var
)
if
last
[
0
]:
for
d
in
last
[
1
]:
arr
+=
'[new Date('
+
str
(
d
[
0
])
+
'*1000),'
+
str
(
d
[
2
][
var
])
+
'],'
arr
+=
']'
return
arr
elif
dest
==
'table'
:
# for table <cnt> is in items
pass
def
pend_delete_all_ack
():
pend
.
delete_all_ack
()
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