diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/meetingtools/apps/stats/views.py | 86 | ||||
-rw-r--r-- | src/meetingtools/urls.py | 6 | ||||
-rw-r--r-- | src/templates/apps/room/list.html | 2 | ||||
-rw-r--r-- | src/templates/apps/stats/domain.html | 4 | ||||
-rw-r--r-- | src/templates/apps/stats/room.html | 32 | ||||
-rw-r--r-- | src/templates/apps/stats/user.html | 2 |
6 files changed, 125 insertions, 7 deletions
diff --git a/src/meetingtools/apps/stats/views.py b/src/meetingtools/apps/stats/views.py index 5090c1f..8cdee25 100644 --- a/src/meetingtools/apps/stats/views.py +++ b/src/meetingtools/apps/stats/views.py @@ -10,6 +10,8 @@ from iso8601 import iso8601 from time import mktime from meetingtools.multiresponse import json_response, respond_to from meetingtools.apps.stats.forms import StatCaledarForm +from django.shortcuts import get_object_or_404 +from meetingtools.apps.room.models import Room def _iso2datesimple(iso): (date,rest) = iso.split("T") @@ -31,11 +33,19 @@ def user(request): def domain(request,domain): (l,d) = request.user.username.split('@') if d != domain: - return HttpResponseForbidden("You can only look at stats for your own domain!") + return HttpResponseForbidden("You can only look at statistics for your own domain!") return respond_to(request,{'text/html': 'apps/stats/domain.html'},{'domain': domain}) @login_required +def room(request,rid): + room = get_object_or_404(Room,pk=rid) + if not room.creator == request.user: + return HttpResponseForbidden("You can only look at statistics for your own rooms!") + + return respond_to(request,{'text/html': 'apps/stats/room.html'},{'room': room}) + +@login_required def user_minutes_api(request,username=None): if username and username != request.user.username: return HttpResponseForbidden("You can't spy on others!") @@ -131,12 +141,84 @@ def domain_minutes_api(request,domain): curdate = None t_ms = 0 rc = {} + uc = {} for row in r.et.xpath("//row"): login = row.findtext("login") if not login.endswith("@%s" % domain): continue rc[row.get('sco-id')] = True + uc[row.get('principal-id')] = True + date_created_str = row.findtext("date-created") + ts_created = _iso2ts(date_created_str) + date_closed_str = row.findtext("date-closed") + ts_closed = _iso2ts(date_closed_str) + + d1 = _iso2datesimple(date_created_str) + if d_created == None: + d_created = d1 + + d2 = _iso2datesimple(date_closed_str) + if d_closed == None: + d_closed = d2 + + if curdate == None: + curdate = d1 + + if curdate != d1: + series.append([_date_ts(curdate),int(ms/60000)]) + ms = 0 + curdate = d1 + + if d1 == d2: #same date + diff = (ts_closed - ts_created) + ms = ms + diff + t_ms = t_ms + diff + else: # meeting spanned midnight + ts_date_ts = _date_ts(d2) + ms = ms + (ts_date_ts - ts_created) + series.append([_date_ts(d1),int(ms/60000)]) + t_ms = t_ms + ms + curdate = d2 + ms = (ts_closed - ts_date_ts) + + if curdate != None and ms > 0: + series.append([_date_ts(curdate),int(ms/60000)]) + + return json_response({'data': sorted(series,key=lambda x: x[0]), 'rooms': len(rc.keys()), 'users': len(uc.keys()), 'minutes': int(t_ms/60000)},request) + + +@login_required +def room_minutes_api(request,rid): + room = get_object_or_404(Room,pk=rid) + if not room.creator == request.user: + return HttpResponseForbidden("You can only look at statistics for your own rooms!") + + api = ac_api_client(request) + p = {'sort': 'asc','sort1': 'date-created','filter-type': 'meeting','filter-sco-id': room.sco_id} + + form = StatCaledarForm(request.GET) + if not form.is_valid(): + return HttpResponseBadRequest() + + begin = form.cleaned_data['begin'] + end = form.cleaned_data['end'] + + if begin != None: + p['filter-gte-date-created'] = begin + if end != None: + p['filter-lt-date-created'] = end + r = api.request('report-bulk-consolidated-transactions',p) + + series = [] + d_created = None + d_closed = None + ms = 0 + curdate = None + t_ms = 0 + uc = {} + for row in r.et.xpath("//row"): + uc[row.get('principal-id')] = True date_created_str = row.findtext("date-created") ts_created = _iso2ts(date_created_str) date_closed_str = row.findtext("date-closed") @@ -173,4 +255,4 @@ def domain_minutes_api(request,domain): if curdate != None and ms > 0: series.append([_date_ts(curdate),int(ms/60000)]) - return json_response({'data': sorted(series,key=lambda x: x[0]), 'rooms': len(rc.keys()), 'minutes': int(t_ms/60000)},request)
\ No newline at end of file + return json_response({'data': sorted(series,key=lambda x: x[0]), 'users': len(uc.keys()), 'minutes': int(t_ms/60000)},request)
\ No newline at end of file diff --git a/src/meetingtools/urls.py b/src/meetingtools/urls.py index 13382d8..d1a6ef2 100644 --- a/src/meetingtools/urls.py +++ b/src/meetingtools/urls.py @@ -42,9 +42,11 @@ urlpatterns = patterns('', # Uncomment the admin/doc line below to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^api/stats/user/(.*)$','meetingtools.apps.stats.views.user_minutes_api'), - (r'^api/stats/domain/(.*)$','meetingtools.apps.stats.views.domain_minutes_api'), + (r'^api/stats/domain/(.+)$','meetingtools.apps.stats.views.domain_minutes_api'), + (r'^api/stats/room/(\d+)$','meetingtools.apps.stats.views.room_minutes_api'), (r'^stats$','meetingtools.apps.stats.views.user'), - (r'^stats/(.+)$','meetingtools.apps.stats.views.domain'), + (r'^stats/domain/(.+)$','meetingtools.apps.stats.views.domain'), + (r'^stats/room/(\d+)$','meetingtools.apps.stats.views.room'), # Uncomment the next line to enable the admin: (r'^admin/', include(admin.site.urls)) ) diff --git a/src/templates/apps/room/list.html b/src/templates/apps/room/list.html index c314f4b..5de2221 100644 --- a/src/templates/apps/room/list.html +++ b/src/templates/apps/room/list.html @@ -39,7 +39,7 @@ {% if r.self_cleaning %}<li>» Room will be reset when empty.</li>{%else%}<li>» Room state is preserved between sessions.</li>{% endif %} {% if r.allow_host %}<li>» First participant can elect to become host.</li>{% endif %} {% if r.lastvisited %}<li>» Last visited {{r.lastvisited|datehumanize}}</li>{%endif%} - <li>» Hosted on {{r.acc.name}}</li> + <li>» Hosted on {{r.acc.name}} <a href="{% prefix %}/stats/room/{{r.id}}">(usage statistics)</a></li> </ul> <br/> <ul class="ilist"> diff --git a/src/templates/apps/stats/domain.html b/src/templates/apps/stats/domain.html index 8f86976..93fb1a9 100644 --- a/src/templates/apps/stats/domain.html +++ b/src/templates/apps/stats/domain.html @@ -15,6 +15,7 @@ $.ajax({ }); $('#minutes').append(resp['minutes']); $('#rooms').append(resp['rooms']); + $('#users').append(resp['users']); } }); {% endblock %} @@ -26,7 +27,8 @@ $.ajax({ <table> <tr><td><b>Total minutes:</b></td><td id="minutes"></td></tr> <tr><td><b>Total rooms:</b></td><td id="rooms"></td></tr> + <tr><td><b>Total unique users:</b></td><td id="users"></td></tr> + <tr><td colspan="2" style="padding-top: 10px;"><a href="{% prefix %}/stats">Look at your own statistics</a></td></tr> </table> -<a href="{% prefix %}/stats">Look at your own statistics</a> </div> {% endblock %}
\ No newline at end of file diff --git a/src/templates/apps/stats/room.html b/src/templates/apps/stats/room.html new file mode 100644 index 0000000..7a2a25f --- /dev/null +++ b/src/templates/apps/stats/room.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} +{% load datehumanize %} +{% load prefix %} +{% block widgets %} +$.ajax({ + url: '{% prefix %}/api/stats/room/{{room.id}}', + method: 'GET', + success: function (resp) { + var graph = $('#graph'); + series = [{label: 'Meeting minutes for {{room.name}}',data: resp['data']}]; + $.plot(graph,series,{ + lines: { show: true }, + points: { show: true }, + xaxis: { mode: "time" } + }); + $('#minutes').append(resp['minutes']); + $('#users').append(resp['users']); + } +}); +{% endblock %} +{% block content %} +<h1>Meeting statistics for {{room.name}}</h1> +<div id="graph" style="width:600px;height:300px; display: block; float: left; margin-right: 30px;"></div> +<div> +<h2>Summary</h2> +<table> + <tr><td><b>Total minutes:</b></td><td id="minutes"></td></tr> + <tr><td><b>Total unique users:</b></td><td id="users"></td></tr> + <tr><td colspan="2" style="padding-top: 10px;"><a href="{% prefix %}/stats">Look at your own statistics</a></td></tr> +</table> +</div> +{% endblock %}
\ No newline at end of file diff --git a/src/templates/apps/stats/user.html b/src/templates/apps/stats/user.html index 73c4fb9..486c9be 100644 --- a/src/templates/apps/stats/user.html +++ b/src/templates/apps/stats/user.html @@ -26,7 +26,7 @@ $.ajax({ <table> <tr><td><b>Total minutes:</b></td><td id="minutes"></td></tr> <tr><td><b>Total rooms:</b></td><td id="rooms"></td></tr> + <tr><td colspan="2" style="padding-top: 10px;"><a href="{% prefix %}/stats/domain/{{domain}}">Look at statistics for {{domain}}</a></td></tr> </table> -<a href="{% prefix %}/stats/{{domain}}">Look at statistics for {{domain}}</a> </div> {% endblock %}
\ No newline at end of file |