Commit 7cca2dc6 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

dashboard recent activity integrated

parent 2271353e
......@@ -71,28 +71,31 @@ def get_user_data_count_per_day(cur, username, day=0):
query = query[0:-10]
query += ') SELECT COUNT(*) FROM t WHERE utc > {} AND utc < {}'.format(utc_day, utc_day+24*60*60)
print(query)
cur.execute(query, ())
return (True,cur.fetchone())
@with_psql
def get_recent_activity(cur, apps, devs, n):
def get_recent_activity(cur, username, n=5):
apps = ad.get_list(username)[1]
devs = []
for a in apps:
devs.append(dd.get_list(a[1])[1])
query = ''
i = 0
for a in apps:
for d in devs[i]:
devs = dd.get_list(a[1])
for d in devs[1]:
query += """
(SELECT utc, appname, devname, data from
(SELECT utc, data from dev_{}_{} limit 5) AS utc,
(SELECT timedate, appname, devname, data, utc from
(SELECT utc, timedate, data from dev_{}_{} limit 5) AS utc,
(SELECT '{}' as appname) AS appname,
(SELECT {} as devname) AS devname)
UNION ALL
""".format(a[1],d[1], a[0],d[0])
i += 1
(SELECT '{}' as devname) AS devname)
UNION ALL""".format(a[1],d[1], a[0],d[0])
query = query[0:-9]
query += 'ORDER BY utc DESC LIMIT 5'
query += ' ORDER BY utc DESC LIMIT {}'.format(n)
print(query)
cur.execute(query, ())
......
......@@ -154,75 +154,21 @@
</thead>
<tbody>
<tr>
{% for ra in recent_activity %}
<th scope="row">
/argon/
{{ ra[1] }}
</th>
<td>
4,569
{{ ra[2] }}
</td>
<td>
340
{{ ra[0] }}
</td>
<td>
46,53%
</td>
</tr>
<tr>
<th scope="row">
/argon/index.html
</th>
<td>
3,985
</td>
<td>
319
</td>
<td>
46,53%
</td>
</tr>
<tr>
<th scope="row">
/argon/charts.html
</th>
<td>
3,513
</td>
<td>
294
</td>
<td>
36,49%
</td>
</tr>
<tr>
<th scope="row">
/argon/tables.html
</th>
<td>
2,050
</td>
<td>
147
</td>
<td>
50,87%
</td>
</tr>
<tr>
<th scope="row">
/argon/profile.html
</th>
<td>
1,795
</td>
<td>
190
</td>
<td>
46,53%
{{ ra[3] }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
......
......@@ -34,13 +34,16 @@ def index():
total_activity = md.get_user_data_count(session['name'])[1][0]
last_activity = md.get_user_data_count_per_day(session['name'])[1][0]
print('created_apps', created_apps)
print('active_devices', active_devices)
print('total_activity', total_activity)
print('last_activity', last_activity)
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)
return render_template('new/public/dashboard.html', info=info, recent_activity=recent_activity)
#apps = ad.get_list(session['name'])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment