def warm_up_stats(): # pragma: no cover """Background job for warming stats.""" from pybossa.cache.site_stats import (n_auth_users, n_anon_users, n_tasks_site, n_total_tasks_site, n_task_runs_site, get_top5_projects_24_hours, get_top5_users_24_hours) n_auth_users() n_anon_users() n_tasks_site() n_total_tasks_site() n_task_runs_site() get_top5_projects_24_hours() get_top5_users_24_hours() return True
def index(): """Return Global Statistics for the site.""" title = "Global Statistics" n_auth = site_stats.n_auth_users() n_anon = site_stats.n_anon_users() n_total_users = n_anon + n_auth n_published_projects = cached_projects.n_published() n_draft_projects = cached_projects.n_count('draft') n_total_projects = n_published_projects + n_draft_projects n_tasks = site_stats.n_tasks_site() n_task_runs = site_stats.n_task_runs_site() top5_projects_24_hours = site_stats.get_top5_projects_24_hours() top5_users_24_hours = site_stats.get_top5_users_24_hours() stats = dict(n_total_users=n_total_users, n_auth=n_auth, n_anon=n_anon, n_published_projects=n_published_projects, n_draft_projects=n_draft_projects, n_total_projects=n_total_projects, n_tasks=n_tasks, n_task_runs=n_task_runs) users = dict(label="User Statistics", values=[ dict(label='Anonymous', value=[0, n_anon]), dict(label='Authenticated', value=[0, n_auth]) ]) projects = dict(label="Projects Statistics", values=[ dict(label='Published', value=[0, n_published_projects]), dict(label='Draft', value=[0, n_draft_projects]) ]) tasks = dict(label="Task and Task Run Statistics", values=[ dict(label='Tasks', value=[0, n_tasks]), dict(label='Answers', value=[1, n_task_runs]) ]) response = dict(template='/stats/global.html', title=title, users=json.dumps(users), projects=json.dumps(projects), tasks=json.dumps(tasks), show_locs=False, top5_users_24_hours=top5_users_24_hours, top5_projects_24_hours=top5_projects_24_hours, stats=stats) return handle_content_type(response)
def index(): """Return Global Statistics for the site""" title = "Global Statistics" n_auth = site_stats.n_auth_users() n_anon = site_stats.n_anon_users() n_total_users = n_anon + n_auth n_published_apps = cached_apps.n_published() n_draft_apps = cached_apps.n_count('draft') n_total_apps = n_published_apps + n_draft_apps n_tasks = site_stats.n_tasks_site() n_task_runs = site_stats.n_task_runs_site() top5_apps_24_hours = site_stats.get_top5_apps_24_hours() top5_users_24_hours = site_stats.get_top5_users_24_hours() locs = site_stats.get_locs() show_locs = False if len(locs) > 0: show_locs = True stats = dict(n_total_users=n_total_users, n_auth=n_auth, n_anon=n_anon, n_published_apps=n_published_apps, n_draft_apps=n_draft_apps, n_total_apps=n_total_apps, n_tasks=n_tasks, n_task_runs=n_task_runs) users = dict(label="User Statistics", values=[ dict(label='Anonymous', value=[0, n_anon]), dict(label='Authenticated', value=[0, n_auth])]) apps = dict(label="Apps Statistics", values=[ dict(label='Published', value=[0, n_published_apps]), dict(label='Draft', value=[0, n_draft_apps])]) tasks = dict(label="Task and Task Run Statistics", values=[ dict(label='Tasks', value=[0, n_tasks]), dict(label='Answers', value=[1, n_task_runs])]) return render_template('/stats/global.html', title=title, users=json.dumps(users), apps=json.dumps(apps), tasks=json.dumps(tasks), locs=json.dumps(locs), show_locs=show_locs, top5_users_24_hours=top5_users_24_hours, top5_apps_24_hours=top5_apps_24_hours, stats=stats)
def warm_up_stats(): # pragma: no cover """Background job for warming stats.""" print "Running on the background warm_up_stats" from pybossa.cache.site_stats import (n_auth_users, n_anon_users, n_tasks_site, n_total_tasks_site, n_task_runs_site, get_top5_projects_24_hours, get_top5_users_24_hours) n_auth_users() n_anon_users() n_tasks_site() n_total_tasks_site() n_task_runs_site() get_top5_projects_24_hours() get_top5_users_24_hours() return True
def warm_up_stats(): # pragma: no cover """Background job for warming stats.""" print "Running on the background warm_up_stats" from pybossa.cache.site_stats import (n_auth_users, n_anon_users, n_tasks_site, n_total_tasks_site, n_task_runs_site, get_top5_apps_24_hours, get_top5_users_24_hours, get_locs) n_auth_users() n_anon_users() n_tasks_site() n_total_tasks_site() n_task_runs_site() get_top5_apps_24_hours() get_top5_users_24_hours() get_locs() return True
def index(): """Return Global Statistics for the site.""" title = "Global Statistics" n_auth = site_stats.n_auth_users() n_anon = site_stats.n_anon_users() n_total_users = n_anon + n_auth n_published_projects = cached_projects.n_published() n_draft_projects = cached_projects.n_count('draft') n_total_projects = n_published_projects + n_draft_projects n_tasks = site_stats.n_tasks_site() n_task_runs = site_stats.n_task_runs_site() top5_projects_24_hours = site_stats.get_top5_projects_24_hours() top5_users_24_hours = site_stats.get_top5_users_24_hours() stats = dict(n_total_users=n_total_users, n_auth=n_auth, n_anon=n_anon, n_published_projects=n_published_projects, n_draft_projects=n_draft_projects, n_total_projects=n_total_projects, n_tasks=n_tasks, n_task_runs=n_task_runs) users = dict(label="User Statistics", values=[ dict(label='Anonymous', value=[0, n_anon]), dict(label='Authenticated', value=[0, n_auth])]) projects = dict(label="Projects Statistics", values=[ dict(label='Published', value=[0, n_published_projects]), dict(label='Draft', value=[0, n_draft_projects])]) tasks = dict(label="Task and Task Run Statistics", values=[ dict(label='Tasks', value=[0, n_tasks]), dict(label='Answers', value=[1, n_task_runs])]) response = dict(template='/stats/global.html', title=title, users=json.dumps(users), projects=json.dumps(projects), tasks=json.dumps(tasks), show_locs=False, top5_users_24_hours=top5_users_24_hours, top5_projects_24_hours=top5_projects_24_hours, stats=stats) return handle_content_type(response)
def test_get_top5_users_24_hours_considers_last_24_hours_contributions_only(self): recently_contributing_user = UserFactory.create() long_ago_contributing_user = UserFactory.create() two_days_ago = (datetime.datetime.utcnow() - datetime.timedelta(2)).isoformat() TaskRunFactory.create(user=recently_contributing_user) TaskRunFactory.create(user=long_ago_contributing_user, finish_time=two_days_ago) top5 = stats.get_top5_users_24_hours() top5_ids = [top['id'] for top in top5] assert recently_contributing_user.id in top5_ids assert long_ago_contributing_user.id not in top5_ids
def test_get_top5_users_24_hours_returns_best_5_users_only(self): users = UserFactory.create_batch(5) i = 5 for user in users: TaskRunFactory.create_batch(i, user=user) i -= 1 worst_user = UserFactory.create() top5 = stats.get_top5_users_24_hours() top5_ids = [top['id'] for top in top5] assert len(top5) == 5 assert worst_user.id not in top5_ids for i in range(len(top5)): assert users[i].id == top5_ids[i]
def test_get_top5_users_24_hours_returns_best_5_users_only(self): users = UserFactory.create_batch(4) restricted = UserFactory.create(restrict=True) users.append(restricted) i = 5 for user in users: TaskRunFactory.create_batch(i, user=user) i -= 1 worst_user = UserFactory.create() top5 = stats.get_top5_users_24_hours() top5_ids = [top['id'] for top in top5] assert len(top5) == 4, len(top5) assert worst_user.id not in top5_ids for i in range(len(top5)): assert users[i].id == top5_ids[i] assert users[i].restrict is False assert users[i].id != restricted.id
def index(): """Return Global Statistics for the site""" title = "Global Statistics" n_auth = site_stats.n_auth_users() n_anon = site_stats.n_anon_users() n_total_users = n_anon + n_auth n_published_apps = cached_apps.n_published() n_draft_apps = cached_apps.n_count('draft') n_total_apps = n_published_apps + n_draft_apps n_tasks = site_stats.n_tasks_site() n_task_runs = site_stats.n_task_runs_site() top5_apps_24_hours = site_stats.get_top5_apps_24_hours() top5_users_24_hours = site_stats.get_top5_users_24_hours() locs = site_stats.get_locs() show_locs = False if len(locs) > 0: show_locs = True stats = dict(n_total_users=n_total_users, n_auth=n_auth, n_anon=n_anon, n_published_apps=n_published_apps, n_draft_apps=n_draft_apps, n_total_apps=n_total_apps, n_tasks=n_tasks, n_task_runs=n_task_runs) users = dict(label="User Statistics", values=[ dict(label='Anonymous', value=[0, n_anon]), dict(label='Authenticated', value=[0, n_auth]) ]) apps = dict(label="Apps Statistics", values=[ dict(label='Published', value=[0, n_published_apps]), dict(label='Draft', value=[0, n_draft_apps]) ]) tasks = dict(label="Task and Task Run Statistics", values=[ dict(label='Tasks', value=[0, n_tasks]), dict(label='Answers', value=[1, n_task_runs]) ]) return render_template('/stats/global.html', title=title, users=json.dumps(users), apps=json.dumps(apps), tasks=json.dumps(tasks), locs=json.dumps(locs), show_locs=show_locs, top5_users_24_hours=top5_users_24_hours, top5_apps_24_hours=top5_apps_24_hours, stats=stats)