Esempio n. 1
0
def update_stats(project_id, period='2 week'):
    """Update the stats of a given project."""
    hours, hours_anon, hours_auth, max_hours, \
        max_hours_anon, max_hours_auth = stats_hours(project_id, period)
    users, anon_users, auth_users = stats_users(project_id, period)
    dates, dates_anon, dates_auth = stats_dates(project_id, period)


    sum(dates.values())

    sorted(iter(dates.items()), key=operator.itemgetter(0))

    dates_stats = stats_format_dates(project_id, dates,
                                     dates_anon, dates_auth)

    hours_stats = stats_format_hours(project_id, hours, hours_anon, hours_auth,
                                     max_hours, max_hours_anon, max_hours_auth)

    users_stats = stats_format_users(project_id, users, anon_users, auth_users)

    data = dict(dates_stats=dates_stats,
                hours_stats=hours_stats,
                users_stats=users_stats)
    ps = session.query(ProjectStats).filter_by(project_id=project_id).first()

    n_tasks = cached_projects.n_tasks(project_id)
    n_task_runs = cached_projects.n_task_runs(project_id)
    n_results = cached_projects.n_results(project_id)
    overall_progress = cached_projects.overall_progress(project_id)
    last_activity = cached_projects.last_activity(project_id)
    n_volunteers = cached_projects.n_volunteers(project_id)
    n_completed_tasks = cached_projects.n_completed_tasks(project_id)
    average_time = cached_projects.average_contribution_time(project_id)
    n_blogposts = cached_projects.n_blogposts(project_id)

    if ps is None:
        ps = ProjectStats(project_id=project_id, info=data,
                          n_tasks=n_tasks,
                          n_task_runs=n_task_runs,
                          n_results=n_results,
                          n_volunteers=n_volunteers,
                          n_completed_tasks=n_completed_tasks,
                          average_time=average_time,
                          overall_progress=overall_progress,
                          n_blogposts=n_blogposts,
                          last_activity=last_activity)
        db.session.add(ps)
    else:
        ps.info = data
        ps.n_tasks = n_tasks
        ps.n_task_runs = n_task_runs
        ps.overall_progress = overall_progress
        ps.last_activity = last_activity
        ps.n_results = n_results
        ps.n_completed_tasks = n_completed_tasks
        ps.n_volunteers = n_volunteers
        ps.average_time = average_time
        ps.n_blogposts = n_blogposts
    db.session.commit()
    return dates_stats, hours_stats, users_stats
def update_stats(project_id, period='2 week'):
    """Update the stats of a given project."""
    hours, hours_anon, hours_auth, max_hours, \
        max_hours_anon, max_hours_auth = stats_hours(project_id, period)
    users, anon_users, auth_users = stats_users(project_id, period)
    dates, dates_anon, dates_auth = stats_dates(project_id, period)


    sum(dates.values())

    sorted(dates.iteritems(), key=operator.itemgetter(0))

    dates_stats = stats_format_dates(project_id, dates,
                                     dates_anon, dates_auth)

    hours_stats = stats_format_hours(project_id, hours, hours_anon, hours_auth,
                                     max_hours, max_hours_anon, max_hours_auth)

    users_stats = stats_format_users(project_id, users, anon_users, auth_users)

    data = dict(dates_stats=dates_stats,
                hours_stats=hours_stats,
                users_stats=users_stats)
    ps = session.query(ProjectStats).filter_by(project_id=project_id).first()

    n_tasks = cached_projects.n_tasks(project_id)
    n_task_runs = cached_projects.n_task_runs(project_id)
    n_results = cached_projects.n_results(project_id)
    overall_progress = cached_projects.overall_progress(project_id)
    last_activity = cached_projects.last_activity(project_id)
    n_volunteers = cached_projects.n_volunteers(project_id)
    n_completed_tasks = cached_projects.n_completed_tasks(project_id)
    average_time = cached_projects.average_contribution_time(project_id)
    n_blogposts = cached_projects.n_blogposts(project_id)

    if ps is None:
        ps = ProjectStats(project_id=project_id, info=data,
                          n_tasks=n_tasks,
                          n_task_runs=n_task_runs,
                          n_results=n_results,
                          n_volunteers=n_volunteers,
                          n_completed_tasks=n_completed_tasks,
                          average_time=average_time,
                          overall_progress=overall_progress,
                          n_blogposts=n_blogposts,
                          last_activity=last_activity)
        db.session.add(ps)
    else:
        ps.info = data
        ps.n_tasks = n_tasks
        ps.n_task_runs = n_task_runs
        ps.overall_progress = overall_progress
        ps.last_activity = last_activity
        ps.n_results = n_results
        ps.n_completed_tasks = n_completed_tasks
        ps.n_volunteers = n_volunteers
        ps.average_time = average_time
        ps.n_blogposts = n_blogposts
    db.session.commit()
    return dates_stats, hours_stats, users_stats
Esempio n. 3
0
    def notest_n_results_returns_number_of_total_results(self):
        project = ProjectFactory.create()
        task = TaskFactory.create(n_answers=1, project=project)
        TaskRunFactory.create(task=task, project=project)

        results = cached_projects.n_results(project.id)

        assert results == 0, results

        result = result_repo.get_by(project_id=project.id)

        result.info = dict(foo='bar')

        result_repo.update(result)

        results = cached_projects.n_results(project.id)

        assert results == 1, results
Esempio n. 4
0
    def test_n_results_returns_number_of_total_results(self):
        project = ProjectFactory.create()
        task = TaskFactory.create(n_answers=1, project=project)
        TaskRunFactory.create(task=task, project=project)

        results = cached_projects.n_results(project.id)

        assert results == 0, results

        result = result_repo.get_by(project_id=project.id)

        result.info = dict(foo='bar')

        result_repo.update(result)

        results = cached_projects.n_results(project.id)

        assert results == 1, results
Esempio n. 5
0
def index():
    """Return the Data page."""
    categories = cached_cat.get_all()
    projects = {}
    for c in categories:
        n_projects = cached_projects.n_count(category=c.short_name)
        projects[c.short_name] = cached_projects.get(category=c.short_name,
                                                     page=1,
                                                     per_page=n_projects)
        for p in projects[c.short_name]:
            p['n_task_runs'] = cached_projects.n_task_runs(p['id'])
            p['n_results'] = cached_projects.n_results(p['id'])

    return render_template('/index.html', projects=projects,
                           categories=categories, title="Data")
Esempio n. 6
0
def add_custom_contrib_button_to(project, user_id_or_ip):
    """Add a customized contrib button for a project."""
    if type(project) != dict:
        project = project.dictize()
    project['contrib_button'] = check_contributing_state(
        project, **user_id_or_ip)
    query = text('''
                 SELECT COUNT(id) as ct from blogpost
                 WHERE project_id=:project_id;
                 ''')
    results = session.execute(query, dict(project_id=project['id']))
    for row in results:
        project['n_blogposts'] = row.ct

    project['n_results'] = n_results(project['id'])

    return project
Esempio n. 7
0
def add_custom_contrib_button_to(project, user_id_or_ip):
    """Add a customized contrib button for a project."""
    if type(project) != dict:
        project = project.dictize()
    project['contrib_button'] = check_contributing_state(project,
                                                         **user_id_or_ip)
    query = text('''
                 SELECT COUNT(id) as ct from blogpost
                 WHERE project_id=:project_id;
                 ''')
    results = session.execute(query, dict(project_id=project['id']))
    for row in results:
        project['n_blogposts'] = row.ct

    project['n_results'] = n_results(project['id'])

    return project