示例#1
0
 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')
示例#2
0
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
示例#3
0
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)
示例#4
0
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)
示例#5
0
 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')
示例#6
0
def index():
    """Return Global Statistics for the site."""
    title = "Statistics"
    description = """Statistical analysis of contributions made via the
                  LibCrowds crowdsourcing platform."""

    # User stats
    n_anon = extra_stats.n_anon_users()
    n_auth = site_stats.n_auth_users()
    top_5_users_1_week = extra_stats.get_top_n_users_k_days(5, 7)
    n_tr_top_10_percent = extra_stats.get_top_n_percent(10)
    users_daily = extra_stats.get_users_daily()
    leaderboard = cached_users.get_leaderboard(10)
    n_avg_days_active = extra_stats.n_avg_days_active()

    # Task stats
    n_tasks = site_stats.n_tasks_site()
    n_task_runs = site_stats.n_task_runs_site()
    n_auth_task_runs = extra_stats.n_auth_task_runs_site()
    n_tasks_completed = extra_stats.n_tasks_completed()
    task_runs_daily = extra_stats.get_task_runs_daily()
    dow = extra_stats.get_dow()
    hourly_activity = extra_stats.site_hourly_activity()

    # Project stats
    n_published_projects = cached_projects.n_published()
    top_5_pr_1_week = extra_stats.get_top_n_projects_k_days(5, 7)

    # Location stats
    locs = extra_stats.get_locations()
    n_continents = extra_stats.n_continents()
    n_cities = extra_stats.n_cities()
    n_countries = extra_stats.n_countries()
    top_countries = extra_stats.get_top_n_countries()

    stats = dict(n_auth=n_auth,
                 n_anon=n_anon,
                 n_published_projects=n_published_projects,
                 n_tasks=n_tasks,
                 n_task_runs=n_task_runs,
                 n_auth_task_runs=n_auth_task_runs,
                 n_tasks_completed=n_tasks_completed,
                 n_countries=n_countries,
                 n_cities=n_cities,
                 n_continents=n_continents,
                 n_avg_days_active=n_avg_days_active,
                 n_tr_top_10_percent=n_tr_top_10_percent)

    return render_template('/stats.html', title=title,
                           description=description,
                           stats=json.dumps(stats),
                           locs=json.dumps(locs),
                           users_daily=json.dumps(users_daily),
                           task_runs_daily=json.dumps(task_runs_daily),
                           top_countries=json.dumps(top_countries),
                           top_5_pr_1_week=json.dumps(top_5_pr_1_week),
                           top_5_users_1_week=json.dumps(top_5_users_1_week),
                           hourly_activity=json.dumps(hourly_activity),
                           dow=json.dumps(dow),
                           leaderboard=json.dumps(leaderboard))
示例#7
0
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
示例#8
0
文件: jobs.py 项目: idahoan/pybossa
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
示例#9
0
文件: stats.py 项目: PyBossa/pybossa
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)
示例#10
0
    def test_n_auth_users_returns_number_of_registered_users(self):
        UserFactory.create_batch(2)
        users = stats.n_auth_users()

        assert users == 2, users
示例#11
0
    def test_n_auth_users_returns_number_of_registered_users(self):
        UserFactory.create_batch(2)
        users = stats.n_auth_users()

        assert users == 2, users
示例#12
0
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)