Commit eae6de73 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

dashboard completely integrated

parent b54e43a4
...@@ -104,7 +104,6 @@ def get_user_data_count_per_day(cur, username, day=0): ...@@ -104,7 +104,6 @@ def get_user_data_count_per_day(cur, username, day=0):
return (True,cur.fetchone()) return (True,cur.fetchone())
@with_psql @with_psql
def get_user_data_count_per_day_period(cur, username, period): def get_user_data_count_per_day_period(cur, username, period):
apps = ad.get_list(username)[1] apps = ad.get_list(username)[1]
...@@ -113,7 +112,7 @@ def get_user_data_count_per_day_period(cur, username, period): ...@@ -113,7 +112,7 @@ def get_user_data_count_per_day_period(cur, username, period):
for a in apps: for a in apps:
devs.append(dd.get_list(a[1])[1]) devs.append(dd.get_list(a[1])[1])
utc_day = utc_roundday(day) utc_hour = [utc_roundday(x) for x in range(period,-1,-1)]
query = 'WITH t AS (' query = 'WITH t AS ('
i = 0 i = 0
...@@ -122,11 +121,15 @@ def get_user_data_count_per_day_period(cur, username, period): ...@@ -122,11 +121,15 @@ def get_user_data_count_per_day_period(cur, username, period):
query += 'SELECT utc FROM dev_{}_{} UNION ALL '.format(a[1], d[1]) query += 'SELECT utc FROM dev_{}_{} UNION ALL '.format(a[1], d[1])
i += 1 i += 1
query = query[0:-10] query = query[0:-10]
query += ') SELECT COUNT(*) FROM t WHERE utc > {} AND utc < {}'.format(utc_day, utc_day+24*60*60) query += ') SELECT * FROM ('
for uh in utc_hour:
query +=' SELECT COUNT(*) FROM t WHERE utc > {} AND utc < {} UNION ALL'.format(uh, uh+24*60*60)
query = query[0:-9]
query += ') w'
cur.execute(query, ()) cur.execute(query, ())
return (True,cur.fetchone()) return (True,cur.fetchall())
@with_psql @with_psql
......
...@@ -143,3 +143,10 @@ def utc_hour(hour_offset): ...@@ -143,3 +143,10 @@ def utc_hour(hour_offset):
def utc_weekday(day_offset = 0): def utc_weekday(day_offset = 0):
d = {0:'Mo',1:'Tu',2:'We',3:'Th',4:'Fr',5:'Sa',6:'Su'} d = {0:'Mo',1:'Tu',2:'We',3:'Th',4:'Fr',5:'Sa',6:'Su'}
return (d[((datetime.utcnow().weekday() - day_offset) % 7)]) return (d[((datetime.utcnow().weekday() - day_offset) % 7)])
def local_hour(hour_offset):
return ((datetime.now().hour - hour_offset) % 24)
def local_weekday(day_offset = 0):
d = {0:'Mo',1:'Tu',2:'We',3:'Th',4:'Fr',5:'Sa',6:'Su'}
return (d[((datetime.now().weekday() - day_offset) % 7)])
...@@ -223,11 +223,11 @@ ...@@ -223,11 +223,11 @@
}, },
data: data:
{ {
labels: ["Sun", "Mon", "Tue", "Wen", "Thu", "Fri", "Sat"], labels: {{ week_chart[0]|safe }},
datasets: [ datasets: [
{ {
label: "Sales", label: "Sales",
data: [25, 20, 30, 22, 36, 29, 15] data: {{ week_chart[1] }}
}] }]
} }
}), e.data("chart", a)) }), e.data("chart", a))
...@@ -249,13 +249,6 @@ ...@@ -249,13 +249,6 @@
lineWidth: 1, lineWidth: 1,
color: Charts.colors.gray[900], color: Charts.colors.gray[900],
zeroLineColor: Charts.colors.gray[900] zeroLineColor: Charts.colors.gray[900]
},
ticks:
{
callback: function (e)
{
if (!(e % 10)) return /*"$"*/ + e
}
} }
}] }]
}, },
...@@ -268,18 +261,18 @@ ...@@ -268,18 +261,18 @@
var t = a.datasets[e.datasetIndex].label || "", var t = a.datasets[e.datasetIndex].label || "",
o = e.yLabel, o = e.yLabel,
n = ""; n = "";
return 1 < a.datasets.length && (n += '<span class="popover-body-label mr-auto">' + t + "</span>"), n += '<span class="popover-body-value">$' + o + "k</span>" return 1 < a.datasets.length && (n += '<span class="popover-body-label mr-auto">' + t + "</span>"), n += '<span class="popover-body-value">' + o + "</span>"
} }
} }
} }
}, },
data: data:
{ {
labels: {{ day_chart.keys()|list }}, labels: {{ day_chart[0] }},
datasets: [ datasets: [
{ {
label: "Performance", label: "Performance",
data: {{ day_chart.values()|list }} data: {{ day_chart[1] }}
}] }]
} }
}), e.data("chart", a)) }), e.data("chart", a))
......
...@@ -41,14 +41,17 @@ def index(): ...@@ -41,14 +41,17 @@ def index():
#print('last_activity', last_activity) #print('last_activity', last_activity)
info = [created_apps, active_devices, total_activity, last_activity] info = [created_apps, active_devices, total_activity, last_activity]
r = md.get_user_data_count_per_hour_period(session['name'], 12)[1] day_chart_values = md.get_user_data_count_per_hour_period(session['name'], 11)[1]
r = [x[0] for x in r] day_chart_values = [x[0] for x in day_chart_values]
day_chart_labels = [misc.local_hour(x) for x in range(11,-1,-1)]
day_chart = {} day_chart = [day_chart_labels, day_chart_values]
for i in range(12,-1,-1):
day_chart[misc.utc_hour(i)] = r[i] week_chart_values = md.get_user_data_count_per_day_period(session['name'], 6)[1]
week_chart_values = [x[0] for x in week_chart_values]
week_chart_labels = [misc.local_weekday(x) for x in range(6,-1,-1)]
week_chart = [week_chart_labels, week_chart_values]
return render_template('new/public/dashboard.html', info=info, recent_activity=recent_activity, day_chart=day_chart) return render_template('new/public/dashboard.html', info=info, recent_activity=recent_activity, day_chart=day_chart, week_chart=week_chart)
#apps = ad.get_list(session['name']) #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