def report_upload(request): try: decompressed = zlib.decompress(request.body) post = QueryDict(decompressed) except zlib.error: # If zlib can't decode it, assume it's an uncompressed POST post = request.POST try: post_time = convert_to_int(post['time']) post_version = convert_to_int(post['version']) if post_time is None or post_version is None: return HttpResponseBadRequest('The "time" or "version" fields are not integers\n', content_type='text/plain') user_id = post['user_id'] generation_date = datetime.datetime.utcfromtimestamp(post_time) data_type = post['type'] data_version = post_version data = post['data'] except KeyError: return HttpResponseBadRequest('Missing required fields.\n', content_type='text/plain') uploader = request.META['REMOTE_ADDR'] # Fix the IP address if running via proxy on localhost if uploader == '127.0.0.1': try: uploader = request.META['HTTP_X_FORWARDED_FOR'].split(',')[0].strip() except KeyError: pass user_id_hash = hashlib.sha1(user_id.encode('utf-8')).hexdigest() report = UserReport( uploader=uploader, user_id_hash=user_id_hash, generation_date=generation_date, data_type=data_type, data_version=data_version, data=data ) report.save() return HttpResponse('OK', content_type='text/plain')
def render_reports(request, reports, template, args): paginator = Paginator(reports, args.get('pagesize', 100)) page = convert_to_int(request.GET.get('page', '1'), 1) try: report_page = paginator.page(page) except (EmptyPage, InvalidPage): report_page = paginator.page(paginator.num_pages) args['report_page'] = report_page return render_to_response(template, args)
def report_opengl_feature(request, feature): usercounts = {} values = {} cursor = connection.cursor() is_extension = False if re.search(r'[a-z]', feature): is_extension = True if is_extension: cursor.execute(''' SELECT vendor, renderer, os, driver, device_name, SUM(usercount), (SELECT 1 FROM userreport_graphicsextension e WHERE e.name = %s AND e.device_id = d.id) AS val FROM userreport_graphicsdevice d GROUP BY vendor, renderer, os, driver, device_name, val ''', [feature]) for vendor, renderer, os, driver, device_name, usercount, val in cursor: val = 'true' if val else 'false' usercounts[val] = usercounts.get(val, 0) + usercount v = values.setdefault(val, {}).setdefault(HashableDict({ 'vendor': vendor, 'renderer': renderer, 'os': os, 'device': device_name }), {'usercount': 0, 'drivers': set()}) v['usercount'] += usercount v['drivers'].add(driver) else: cursor.execute(''' SELECT value, vendor, renderer, os, driver, device_name, usercount FROM userreport_graphicslimit l JOIN userreport_graphicsdevice d ON l.device_id = d.id WHERE name = %s ''', [feature]) for val, vendor, renderer, os, driver, device_name, usercount in cursor: # Convert to int/float if possible, for better sorting new_value = convert_to_int(val) if new_value is None: new_value = convert_to_float(val) val = new_value usercounts[val] = usercounts.get(val, 0) + usercount v = values.setdefault(val, {}).setdefault(HashableDict({ 'vendor': vendor, 'renderer': renderer, 'os': os, 'device': device_name }), {'usercount': 0, 'drivers': set()}) v['usercount'] += usercount v['drivers'].add(driver) if not values or values.keys() == ['false']: return HttpResponseNotFound() num_users = sum(usercounts.values()) return render_to_response('reports/opengl_feature.html', { 'feature': feature, 'values': values, 'is_extension': is_extension, 'usercounts': usercounts, 'num_users': num_users, })