def _compute_group_stats(): """ Computes group statistics for the WMT16 evaluation campaign. """ group_stats = [] wmt16_group = Group.objects.filter(name='WMT16') wmt16_users = _get_active_users_for_group(wmt16_group) # Aggregate information about participating groups. groups = set() for user in wmt16_users: for group in _identify_groups_for_user(user): groups.add(group) # TODO: move this to property of evaluation group or add dedicated data model. # GOAL: should be configurable from within the Django admin backend. # # MINIMAL: move to local_settings.py? # # The following dictionary defines the number of HITs each group should # have completed during the WMT16 evaluation campaign. for group in groups: _name = group.name _group_stats = HIT.compute_status_for_group(group) _total = _group_stats[0] if _total > 0 and not _name in GROUP_HIT_REQUIREMENTS.keys(): _required = 0 elif _name in GROUP_HIT_REQUIREMENTS.keys(): _required = GROUP_HIT_REQUIREMENTS[_name] _delta = _total - _required _data = (_total, _required, _delta) if _data[0] > 0: group_stats.append((_name, _data)) # Sort by number of remaining HITs. group_stats.sort(key=lambda x: x[1][2]) # Add totals at the bottom. global_total = sum([x[1][0] for x in group_stats]) global_required = sum([x[1][1] for x in group_stats]) global_delta = global_total - global_required global_data = (global_total, global_required, global_delta) group_stats.append(("Totals", global_data)) return group_stats
def overview(request): """ Renders the evaluation tasks overview. """ LOGGER.info('Rendering WMT16 HIT overview for user "{0}".'.format( request.user.username or "Anonymous")) # Re-initialise random number generator. seed(None) # Collect available language pairs for the current user. language_codes = set([x[0] for x in LANGUAGE_PAIR_CHOICES]) language_pairs = request.user.groups.filter(name__in=language_codes) # Collect available annotation projects for the current user. annotation_projects = request.user.project_set.all() hit_data = [] total = [0, 0, 0] for language_pair in language_pairs: for annotation_project in annotation_projects: hit = _compute_next_task_for_user(request.user, annotation_project, language_pair) user_status = HIT.compute_status_for_user(request.user, annotation_project, language_pair) for i in range(3): total[i] = total[i] + user_status[i] if hit: # Convert status seconds back into datetime.time instances. for i in range(2): user_status[i+1] = seconds_to_timedelta(int(user_status[i+1])) hit_data.append( (hit.get_language_pair_display(), hit.get_absolute_url(), hit.hit_id, user_status, annotation_project) ) # Convert total seconds back into datetime.timedelta instances. total[1] = seconds_to_timedelta(int(total[2]) / float(int(total[0]) or 1)) # Remove microseconds to get a nicer timedelta rendering in templates. total[1] = total[1] - timedelta(microseconds=total[1].microseconds) total[2] = seconds_to_timedelta(int(total[2])) groups = _identify_groups_for_user(request.user) group = None if len(groups) > 1: LOGGER.debug(u'User "{0}" assigned to multiple annotation groups: {1}'.format( request.user.username or u'Anonymous', u', '.join([x.name for x in groups])) ) group = groups[0] if group is not None: group_name = group.name group_status = HIT.compute_status_for_group(group) for i in range(2): group_status[i+1] = seconds_to_timedelta(int(group_status[i+1])) else: group_status = None group_name = None LOGGER.debug(u'\n\nHIT data for user "{0}":\n\n{1}\n'.format( request.user.username or "Anonymous", u'\n'.join([u'{0}\t{1}\t{2}\t{3}'.format(*x) for x in hit_data]))) # Compute admin URL for super users. admin_url = None if request.user.is_superuser: admin_url = reverse('admin:index') dictionary = { 'active_page': "OVERVIEW", 'hit_data': hit_data, 'total': total, 'group_name': group_name, 'group_status': group_status, 'admin_url': admin_url, 'title': 'WMT16 Dashboard', 'annotation_groups': [x.name for x in groups], } dictionary.update(BASE_CONTEXT) LOGGER.info(dictionary.values()) return render(request, 'wmt16/overview.html', dictionary)
def overview(request): """ Renders the evaluation tasks overview. """ LOGGER.info('Rendering WMT16 HIT overview for user "{0}".'.format( request.user.username or "Anonymous")) # Re-initialise random number generator. seed(None) # Collect available language pairs for the current user. language_codes = set([x[0] for x in LANGUAGE_PAIR_CHOICES]) language_pairs = request.user.groups.filter(name__in=language_codes) # Collect available annotation projects for the current user. annotation_projects = request.user.project_set.all() hit_data = [] total = [0, 0, 0] for language_pair in language_pairs: for annotation_project in annotation_projects: hit = _compute_next_task_for_user(request.user, annotation_project, language_pair) user_status = HIT.compute_status_for_user(request.user, annotation_project, language_pair) for i in range(3): total[i] = total[i] + user_status[i] if hit: # Convert status seconds back into datetime.time instances. for i in range(2): user_status[i + 1] = seconds_to_timedelta( int(user_status[i + 1])) hit_data.append( (hit.get_language_pair_display(), hit.get_absolute_url(), hit.hit_id, user_status, annotation_project)) # Convert total seconds back into datetime.timedelta instances. total[1] = seconds_to_timedelta(int(total[2]) / float(int(total[0]) or 1)) # Remove microseconds to get a nicer timedelta rendering in templates. total[1] = total[1] - timedelta(microseconds=total[1].microseconds) total[2] = seconds_to_timedelta(int(total[2])) groups = _identify_groups_for_user(request.user) group = None if len(groups) > 1: LOGGER.debug( u'User "{0}" assigned to multiple annotation groups: {1}'.format( request.user.username or u'Anonymous', u', '.join([x.name for x in groups]))) group = groups[0] if group is not None: group_name = group.name group_status = HIT.compute_status_for_group(group) for i in range(2): group_status[i + 1] = seconds_to_timedelta(int(group_status[i + 1])) else: group_status = None group_name = None LOGGER.debug(u'\n\nHIT data for user "{0}":\n\n{1}\n'.format( request.user.username or "Anonymous", u'\n'.join([u'{0}\t{1}\t{2}\t{3}'.format(*x) for x in hit_data]))) # Compute admin URL for super users. admin_url = None if request.user.is_superuser: admin_url = reverse('admin:index') dictionary = { 'active_page': "OVERVIEW", 'hit_data': hit_data, 'total': total, 'group_name': group_name, 'group_status': group_status, 'admin_url': admin_url, 'title': 'WMT16 Dashboard', 'annotation_groups': [x.name for x in groups], } dictionary.update(BASE_CONTEXT) LOGGER.info(dictionary.values()) return render(request, 'wmt16/overview.html', dictionary)
def _compute_group_stats(): """ Computes group statistics for the wmt16 evaluation campaign. """ group_stats = [] wmt16_group = Group.objects.filter(name='wmt16') wmt16_users = [] if wmt16_group.exists(): wmt16_users = wmt16_group[0].user_set.all() # Aggregate information about participating groups. groups = set() for user in wmt16_users: for group in user.groups.all(): if group.name == 'wmt16' or group.name.startswith('eng2') \ or group.name.endswith('2eng'): continue groups.add(group) # TODO: move this to property of evaluation group or add dedicated data model. # GOAL: should be configurable from within the Django admin backend. # # MINIMAL: move to local_settings.py? # # The following dictionary defines the number of HITs each group should # have completed during the wmt16 evaluation campaign. group_hit_requirements = { # volunteers 'MSR': 0, 'MTMA': 0, # participants, confirmed 'Aalto': 100, 'Abu-Matran': 300, 'AFRL-MITLL': 400, 'AMU-UEDIN': 200, 'CMU': 100, 'CUNI': 500, 'JHU': 1600, 'KIT': 300, 'KIT-LIMSI': 100, 'LIMSI': 300, 'LMU-CUNI': 100, 'METAMIND': 100, 'TBTK': 200, 'Cambridge': 100, 'NRC': 100, 'NYU-Umontreal': 400, 'PJATK': 200, 'PROMT': 500, 'QT21': 100, 'RWTH': 100, 'UEdin': 1900, 'UH': 400, 'USFD': 100, 'UUT': 100, 'YSDA': 200, } for group in groups: _name = group.name if not _name in group_hit_requirements.keys(): continue _group_stats = HIT.compute_status_for_group(group) _total = _group_stats[0] _required = group_hit_requirements[_name] _delta = _total - _required _data = (_total, _required, _delta) if _data[0] > 0: group_stats.append((_name, _data)) # Sort by number of remaining HITs. group_stats.sort(key=lambda x: x[1][2]) # Add totals at the bottom. global_total = sum([x[1][0] for x in group_stats]) global_required = sum([x[1][1] for x in group_stats]) global_delta = global_total - global_required global_data = (global_total, global_required, global_delta) group_stats.append(("Totals", global_data)) return group_stats