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
b54e43a4
Commit
b54e43a4
authored
May 21, 2020
by
Vladislav Rykov
Browse files
dashboard recent activity retrieval optimization
parent
aa74c771
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/app/__pycache__/views.cpython-37.pyc
View file @
b54e43a4
No preview for this file type
app/app/dao/misc/.misc.py.swp
View file @
b54e43a4
No preview for this file type
app/app/dao/misc/__pycache__/misc.cpython-37.pyc
View file @
b54e43a4
No preview for this file type
app/app/dao/misc/misc.py
View file @
b54e43a4
...
...
@@ -41,10 +41,10 @@ def get_user_data_count_per_hour(cur, username, hour):
i
=
0
for
a
in
apps
:
for
d
in
devs
[
i
]:
query
+=
'SELECT
COUNT(*)
FROM dev_{}_{} UNION ALL '
.
format
(
a
[
1
],
d
[
1
])
query
+=
'SELECT
utc
FROM dev_{}_{} UNION ALL '
.
format
(
a
[
1
],
d
[
1
])
i
+=
1
query
=
query
[
0
:
-
10
]
query
+=
') SELECT
SUM(count
) FROM t WHERE utc > {} AND utc < {}'
.
format
(
utc_hour
,
utc_hour
+
60
*
60
)
query
+=
') SELECT
COUNT(*
) FROM t WHERE utc > {} AND utc < {}'
.
format
(
utc_hour
,
utc_hour
+
60
*
60
)
#print(query)
cur
.
execute
(
query
,
())
...
...
@@ -52,6 +52,34 @@ def get_user_data_count_per_hour(cur, username, hour):
return
(
True
,
cur
.
fetchone
())
@
with_psql
def
get_user_data_count_per_hour_period
(
cur
,
username
,
period
):
apps
=
ad
.
get_list
(
username
)[
1
]
devs
=
[]
for
a
in
apps
:
devs
.
append
(
dd
.
get_list
(
a
[
1
])[
1
])
utc_hour
=
[
utc_roundhour
(
x
)
for
x
in
range
(
period
,
-
1
,
-
1
)]
query
=
'WITH t AS ('
i
=
0
for
a
in
apps
:
for
d
in
devs
[
i
]:
query
+=
'SELECT utc FROM dev_{}_{} UNION ALL '
.
format
(
a
[
1
],
d
[
1
])
i
+=
1
query
=
query
[
0
:
-
10
]
query
+=
') SELECT * FROM ('
for
uh
in
utc_hour
:
query
+=
' SELECT COUNT(*) FROM t WHERE utc > {} AND utc < {} UNION ALL'
.
format
(
uh
,
uh
+
60
*
60
)
query
=
query
[
0
:
-
9
]
query
+=
') w'
cur
.
execute
(
query
,
())
return
(
True
,
cur
.
fetchall
())
@
with_psql
def
get_user_data_count_per_day
(
cur
,
username
,
day
=
0
):
apps
=
ad
.
get_list
(
username
)[
1
]
...
...
@@ -76,6 +104,31 @@ def get_user_data_count_per_day(cur, username, day=0):
return
(
True
,
cur
.
fetchone
())
@
with_psql
def
get_user_data_count_per_day_period
(
cur
,
username
,
period
):
apps
=
ad
.
get_list
(
username
)[
1
]
devs
=
[]
for
a
in
apps
:
devs
.
append
(
dd
.
get_list
(
a
[
1
])[
1
])
utc_day
=
utc_roundday
(
day
)
query
=
'WITH t AS ('
i
=
0
for
a
in
apps
:
for
d
in
devs
[
i
]:
query
+=
'SELECT utc FROM dev_{}_{} UNION ALL '
.
format
(
a
[
1
],
d
[
1
])
i
+=
1
query
=
query
[
0
:
-
10
]
query
+=
') SELECT COUNT(*) FROM t WHERE utc > {} AND utc < {}'
.
format
(
utc_day
,
utc_day
+
24
*
60
*
60
)
cur
.
execute
(
query
,
())
return
(
True
,
cur
.
fetchone
())
@
with_psql
def
get_recent_activity
(
cur
,
username
,
n
=
5
):
apps
=
ad
.
get_list
(
username
)[
1
]
...
...
@@ -96,7 +149,6 @@ def get_recent_activity(cur, username, n=5):
UNION ALL"""
.
format
(
a
[
1
],
d
[
1
],
a
[
0
],
d
[
0
])
query
=
query
[
0
:
-
9
]
query
+=
' ORDER BY utc DESC LIMIT {}'
.
format
(
n
)
print
(
query
)
cur
.
execute
(
query
,
())
...
...
app/app/views.py
View file @
b54e43a4
...
...
@@ -33,17 +33,22 @@ def index():
active_devices
=
dd
.
get_count_by_user
(
session
[
'name'
])
total_activity
=
md
.
get_user_data_count
(
session
[
'name'
])[
1
][
0
]
last_activity
=
md
.
get_user_data_count_per_day
(
session
[
'name'
])[
1
][
0
]
recent_activity
=
md
.
get_recent_activity
(
session
[
'name'
])[
1
]
#print('created_apps', created_apps)
#print('active_devices', active_devices)
#print('total_activity', total_activity)
#print('last_activity', last_activity)
info
=
[
created_apps
,
active_devices
,
total_activity
,
last_activity
]
return
render_template
(
'new/public/dashboard.html'
,
info
=
info
,
recent_activity
=
recent_activity
)
r
=
md
.
get_user_data_count_per_hour_period
(
session
[
'name'
],
12
)[
1
]
r
=
[
x
[
0
]
for
x
in
r
]
day_chart
=
{}
for
i
in
range
(
12
,
-
1
,
-
1
):
day_chart
[
misc
.
utc_hour
(
i
)]
=
r
[
i
]
return
render_template
(
'new/public/dashboard.html'
,
info
=
info
,
recent_activity
=
recent_activity
,
day_chart
=
day_chart
)
#apps = ad.get_list(session['name'])
...
...
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