diff options
author | Leif Johansson <leifj@sunet.se> | 2012-02-09 00:16:16 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2012-02-09 00:16:16 +0100 |
commit | ad21e8e4e5ac8f9eb38830f3024e19fd9329e288 (patch) | |
tree | 4aa7d7c3a6cd66cae59708e5bba274ce1cdb1eba /src/meetingtools/apps/stats | |
parent | 635d92fc5ded0faec71849554224608f0424fae2 (diff) |
* refactor api
* now depends on with statement
* object-pool using queues
Diffstat (limited to 'src/meetingtools/apps/stats')
-rw-r--r-- | src/meetingtools/apps/stats/views.py | 380 |
1 files changed, 190 insertions, 190 deletions
diff --git a/src/meetingtools/apps/stats/views.py b/src/meetingtools/apps/stats/views.py index 1342c2e..b028d18 100644 --- a/src/meetingtools/apps/stats/views.py +++ b/src/meetingtools/apps/stats/views.py @@ -59,148 +59,148 @@ def user_minutes_api(request,username=None): if username == None: username = request.user.username - api = ac_api_client(request) - p = {'sort1-type': 'asc','sort2-type': 'asc','sort1': 'date-created','sort2': 'date-closed','filter-type': 'meeting','filter-login':username} - - 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 - rc = {} - for row in r.et.xpath("//row"): - rc[row.get('sco-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) + with ac_api_client(request) as api: + p = {'sort1-type': 'asc','sort2-type': 'asc','sort1': 'date-created','sort2': 'date-closed','filter-type': 'meeting','filter-login':username} - d1 = _iso2datesimple(date_created_str) - if d_created == None: - d_created = d1 - - d2 = _iso2datesimple(date_closed_str) - if d_closed == None: - d_closed = d2 - - #duration = _iso2dt(date_closed_str) - _iso2dt(date_created_str) - #sdiff = duration.total_seconds() - - if curdate == None: - curdate = d1 + 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 + rc = {} + for row in r.et.xpath("//row"): + rc[row.get('sco-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) - if curdate != d1: - #logging.debug(" %s: %s - %s = %d %d" % (row.findtext("name"),date_created_str,date_closed_str,ms,sdiff*1000)) + d1 = _iso2datesimple(date_created_str) + if d_created == None: + d_created = d1 + + d2 = _iso2datesimple(date_closed_str) + if d_closed == None: + d_closed = d2 + + #duration = _iso2dt(date_closed_str) - _iso2dt(date_created_str) + #sdiff = duration.total_seconds() + + if curdate == None: + curdate = d1 + + if curdate != d1: + #logging.debug(" %s: %s - %s = %d %d" % (row.findtext("name"),date_created_str,date_closed_str,ms,sdiff*1000)) + series.append([_date_ts(curdate),int(ms/60000)]) + ms = 0 + curdate = d1 + + if d1 == d2: #same date + diff = (ts_closed - ts_created) + #logging.debug("ms:: %d + %d" % (ms,diff)) + ms = ms + diff + t_ms = t_ms + diff + else: # meeting spanned midnight + ts_date_ts = _date_ts(d2) + #logging.debug("ms: %d + %d" % (ms,(ts_date_ts - ts_created))) + ms = ms + (ts_date_ts - ts_created) + series.append([_date_ts(d1),int(ms/60000)]) + #logging.debug("* %s: %s - %s = %d %d" % (row.findtext("name"),date_created_str,date_closed_str,ms,sdiff*1000)) + t_ms = t_ms + ms + curdate = d2 + #logging.debug("midnight: %d (%d)" % (ts_date_ts,ts_closed)) + ms = (ts_closed - ts_date_ts) + #logging.debug("nms: %d" % ms) + + if curdate != None and ms > 0: series.append([_date_ts(curdate),int(ms/60000)]) - ms = 0 - curdate = d1 - - if d1 == d2: #same date - diff = (ts_closed - ts_created) - #logging.debug("ms:: %d + %d" % (ms,diff)) - ms = ms + diff - t_ms = t_ms + diff - else: # meeting spanned midnight - ts_date_ts = _date_ts(d2) - #logging.debug("ms: %d + %d" % (ms,(ts_date_ts - ts_created))) - ms = ms + (ts_date_ts - ts_created) - series.append([_date_ts(d1),int(ms/60000)]) - #logging.debug("* %s: %s - %s = %d %d" % (row.findtext("name"),date_created_str,date_closed_str,ms,sdiff*1000)) - t_ms = t_ms + ms - curdate = d2 - #logging.debug("midnight: %d (%d)" % (ts_date_ts,ts_closed)) - ms = (ts_closed - ts_date_ts) - #logging.debug("nms: %d" % ms) - - 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) + + return json_response({'data': sorted(series,key=lambda x: x[0]), 'rooms': len(rc.keys()), 'minutes': int(t_ms/60000)},request) @login_required def domain_minutes_api(request,domain): - api = ac_api_client(request) - p = {'sort': 'asc','sort1': 'date-created','filter-type': 'meeting'} - - 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 - rc = {} - uc = {} - for row in r.et.xpath("//row"): - login = row.findtext("login") - if not login.endswith("@%s" % domain): - continue + with ac_api_client(request) as api: + p = {'sort': 'asc','sort1': 'date-created','filter-type': 'meeting'} - 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) + form = StatCaledarForm(request.GET) + if not form.is_valid(): + return HttpResponseBadRequest() - d1 = _iso2datesimple(date_created_str) - if d_created == None: - d_created = d1 - - d2 = _iso2datesimple(date_closed_str) - if d_closed == None: - d_closed = d2 + 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 + rc = {} + uc = {} + for row in r.et.xpath("//row"): + login = row.findtext("login") + if not login.endswith("@%s" % domain): + continue - if curdate == None: - curdate = d1 + 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) - if curdate != d1: + 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)]) - 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) + + 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 @@ -209,65 +209,65 @@ def room_minutes_api(request,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") - ts_closed = _iso2ts(date_closed_str) + with ac_api_client(request) as api: + p = {'sort': 'asc','sort1': 'date-created','filter-type': 'meeting','filter-sco-id': room.sco_id} - 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 + 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") + ts_closed = _iso2ts(date_closed_str) - if curdate != d1: + 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)]) - 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]), 'users': len(uc.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 |