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 get(self, oid=None): """Return global stats.""" n_pending_tasks = stats.n_total_tasks_site() - stats.n_task_runs_site() n_users = stats.n_auth_users() + stats.n_anon_users() n_projects = cached_projects.n_published() + cached_projects.n_count('draft') data = dict(n_projects=n_projects, n_users=n_users, n_task_runs=stats.n_task_runs_site(), n_pending_tasks=n_pending_tasks, categories=[]) # Add Categories categories = cached_categories.get_used() for c in categories: datum = dict() datum[c['short_name']] = cached_projects.n_count(c['short_name']) data['categories'].append(datum) # Add Featured datum = dict() datum['featured'] = cached_projects.n_count('featured') data['categories'].append(datum) # Add Draft datum = dict() datum['draft'] = cached_projects.n_count('draft') data['categories'].append(datum) return Response(json.dumps(data), 200, mimetype='application/json')
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 get(self, oid=None): """Return global stats.""" n_pending_tasks = stats.n_total_tasks_site() - stats.n_task_runs_site() n_users = stats.n_auth_users() + stats.n_anon_users() n_projects = cached_projects.n_published() + cached_projects.n_count('draft') data = dict(n_projects=n_projects, n_users=n_users, n_tasks=stats.n_total_tasks_site(), n_task_runs=stats.n_task_runs_site(), n_pending_tasks=n_pending_tasks, n_results=stats.n_results_site(), categories=[]) # Add Categories categories = cached_categories.get_used() for c in categories: datum = dict() datum[c['short_name']] = cached_projects.n_count(c['short_name']) data['categories'].append(datum) # Add Featured datum = dict() datum['featured'] = cached_projects.n_count('featured') data['categories'].append(datum) # Add Draft datum = dict() datum['draft'] = cached_projects.n_count('draft') data['categories'].append(datum) return Response(json.dumps(data), 200, mimetype='application/json')
def test_n_anon_users_returns_number_of_distinct_anonymous_contributors(self): AnonymousTaskRunFactory.create(user_ip="1.1.1.1") AnonymousTaskRunFactory.create(user_ip="1.1.1.1") AnonymousTaskRunFactory.create(user_ip="2.2.2.2") anonymous_users = stats.n_anon_users() assert anonymous_users == 2, anonymous_users
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 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)