def _compute_user_stats(): """ Computes user statistics for the WMT14 evaluation campaign. """ user_stats = [] wmt14 = Group.objects.get(name='WMT14') users = wmt14.user_set.all() for user in users: _user_stats = HIT.compute_status_for_user(user) _name = user.username _avg_time = seconds_to_timedelta(_user_stats[1]) _total_time = seconds_to_timedelta(_user_stats[2]) _data = (_name, _user_stats[0], _avg_time, _total_time) if _data[0] > 0: user_stats.append(_data) # Sort by total number of completed HITs. user_stats.sort(key=lambda x: x[1]) user_stats.reverse() return user_stats
def _compute_user_stats(): """ Computes user statistics for the WMT14 evaluation campaign. """ user_stats = [] wmt14 = Group.objects.get(name='WMT14') users = wmt14.user_set.all() for user in users: _user_stats = HIT.compute_status_for_user(user) _name = user.username _avg_time = seconds_to_timedelta(_user_stats[1]) _total_time = seconds_to_timedelta(_user_stats[2]) _data = (_name, _user_stats[0], _avg_time, _total_time) if _data[0] > 0: user_stats.append(_data) # Sort by total number of completed HITs. user_stats.sort(key=lambda x: x[1]) user_stats.reverse() return user_stats
# Properly set DJANGO_SETTINGS_MODULE environment variable. os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' PROJECT_HOME = os.path.normpath(os.getcwd() + "/..") sys.path.append(PROJECT_HOME) # We have just added appraise to the system path list, hence this works. from django.contrib.auth.models import User, Group from appraise.wmt14.models import HIT # Compute user statistics for all users. user_stats = [] wmt14 = Group.objects.get(name='WMT14') users = wmt14.user_set.all() for user in users: _user_stats = HIT.compute_status_for_user(user) _name = user.username _email = user.email _group = "UNDEFINED" for _g in user.groups.all(): if _g.name.startswith("eng2") \ or _g.name.endswith("2eng") \ or _g.name == "WMT14": continue _group = _g.name break _data = (_name, _email, _group, _user_stats[0], _user_stats[2]) user_stats.append(_data)
def overview(request): """ Renders the evaluation tasks overview. """ LOGGER.info('Rendering WMT14 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) hit_data = [] total = [0, 0, 0] for language_pair in language_pairs: hit = _compute_next_task_for_user(request.user, language_pair) user_status = HIT.compute_status_for_user(request.user, 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)) # 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])) group = None for _group in request.user.groups.all(): if _group.name == 'WMT14' \ or _group.name.startswith('eng2') \ or _group.name.endswith('2eng'): continue group = _group break 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", 'commit_tag': COMMIT_TAG, 'hit_data': hit_data, 'total': total, 'group_name': group_name, 'group_status': group_status, 'admin_url': admin_url, 'title': 'WMT14 Dashboard', } return render(request, 'wmt14/overview.html', dictionary)
def overview(request): """ Renders the evaluation tasks overview. """ LOGGER.info('Rendering WMT14 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) hit_data = [] total = [0, 0, 0] for language_pair in language_pairs: hit = _compute_next_task_for_user(request.user, language_pair) user_status = HIT.compute_status_for_user(request.user, 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) ) # 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])) group = None for _group in request.user.groups.all(): if _group.name == 'WMT14' \ or _group.name.startswith('eng2') \ or _group.name.endswith('2eng'): continue group = _group break 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", 'commit_tag': COMMIT_TAG, 'hit_data': hit_data, 'total': total, 'group_name': group_name, 'group_status': group_status, 'admin_url': admin_url, 'title': 'WMT14 Dashboard', } return render(request, 'wmt14/overview.html', dictionary)
# Properly set DJANGO_SETTINGS_MODULE environment variable. os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' PROJECT_HOME = os.path.normpath(os.getcwd() + "/..") sys.path.append(PROJECT_HOME) # We have just added appraise to the system path list, hence this works. from django.contrib.auth.models import User, Group from appraise.wmt14.models import HIT # Compute user statistics for all users. user_stats = [] wmt14 = Group.objects.get(name='WMT14') users = wmt14.user_set.all() for user in users: _user_stats = HIT.compute_status_for_user(user) _name = user.username _email = user.email _group = "UNDEFINED" for _g in user.groups.all(): if _g.name.startswith("eng2") \ or _g.name.endswith("2eng") \ or _g.name == "WMT14": continue _group = _g.name break _data = (_name, _email, _group, _user_stats[0], _user_stats[2]) user_stats.append(_data)