예제 #1
0
    def test_unpublish_project(self):
        project = ProjectFactory.create(
            info=dict(published=True, task_presenter='task presenter'))
        make_subadmin(project.owner)
        task = TaskFactory.create(project=project, n_answers=1)
        TaskRunFactory.create(task=task)
        orig_taskruns = cached_projects.n_task_runs(project.id)

        #unpublish project
        url = '/project/%s/1/publish?api_key=%s' % (project.short_name,
                                                    project.owner.api_key)
        res = self.app.get(url)
        assert res.status_code == 200, res.status_code
        assert 'Are you sure you want to publish this project?' in res.data, \
            'Confirmation message to publish project should be provided'
        assert 'Force remove taskruns and results' in res.data, \
            'Option to remove taskruns and results should be provided'

        resp = self.app.post('/project/%s/0/publish' % project.short_name,
                             follow_redirects=True)
        assert res.status_code == 200, 'Failed to unpublish project'
        project = project_repo.get(project.id)
        assert not project.published, 'Project should not be published'

        #publish an unpublished project
        resp = self.app.post('/project/%s/1/publish' % project.short_name,
                             follow_redirects=True,
                             data={'force_reset': 'off'})
        assert res.status_code == 200, 'Failed to publish project'
        project = project_repo.get(project.id)
        assert project.published, 'Project should be published'
        taskruns_when_published = cached_projects.n_task_runs(project.id)
        assert taskruns_when_published == orig_taskruns, 'Publish project should not have deleted taskruns'
예제 #2
0
파일: jobs.py 프로젝트: codeaudit/pybossa
def get_project_stats(_id, short_name):  # pragma: no cover
    """Get stats for project."""
    import pybossa.cache.projects as cached_projects
    import pybossa.cache.project_stats as stats
    from flask import current_app

    cached_projects.get_project(short_name)
    cached_projects.n_tasks(_id)
    cached_projects.n_task_runs(_id)
    cached_projects.overall_progress(_id)
    cached_projects.last_activity(_id)
    cached_projects.n_completed_tasks(_id)
    cached_projects.n_volunteers(_id)
    stats.get_stats(_id, current_app.config.get('GEO'))
예제 #3
0
파일: jobs.py 프로젝트: ianthe/pybossa
def get_project_stats(_id, short_name):  # pragma: no cover
    """Get stats for project."""
    import pybossa.cache.projects as cached_projects
    import pybossa.cache.project_stats as stats
    from flask import current_app

    cached_projects.get_project(short_name)
    cached_projects.n_tasks(_id)
    cached_projects.n_task_runs(_id)
    cached_projects.overall_progress(_id)
    cached_projects.last_activity(_id)
    cached_projects.n_completed_tasks(_id)
    cached_projects.n_volunteers(_id)
    stats.get_stats(_id, current_app.config.get('GEO'))
예제 #4
0
    def test_n_task_runs_returns_number_of_total_taskruns(self):
        project = self.create_project_with_contributors(anonymous=1,
                                                        registered=1)

        taskruns = cached_projects.n_task_runs(project.id)

        assert taskruns == 2, taskruns
예제 #5
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
예제 #6
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(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
예제 #7
0
파일: warm.py 프로젝트: Skytim/pybossa
 def warm_app(id, short_name, featured=False):
     if id not in apps_cached:
         cached_apps.get_app(short_name)
         cached_apps.n_tasks(id)
         n_task_runs = cached_apps.n_task_runs(id)
         cached_apps.overall_progress(id)
         cached_apps.last_activity(id)
         cached_apps.n_completed_tasks(id)
         cached_apps.n_volunteers(id)
         if n_task_runs >= 1000 or featured:
             print "Getting stats for %s as it has %s task runs" % (short_name, n_task_runs)
             stats.get_stats(id, app.config.get('GEO'))
         apps_cached.append(id)
예제 #8
0
 def warm_app(id, short_name, featured=False):
     if id not in apps_cached:
         cached_apps.get_app(short_name)
         cached_apps.n_tasks(id)
         n_task_runs = cached_apps.n_task_runs(id)
         cached_apps.overall_progress(id)
         cached_apps.last_activity(id)
         cached_apps.n_completed_tasks(id)
         cached_apps.n_volunteers(id)
         if n_task_runs >= 1000 or featured:
             print("Getting stats for %s as it has %s task runs" % (short_name, n_task_runs))
             stats.get_stats(id)
         apps_cached.append(id)
예제 #9
0
파일: jobs.py 프로젝트: codeaudit/pybossa
 def warm_project(_id, short_name, featured=False):
     if _id not in projects_cached:
         cached_projects.get_project(short_name)
         cached_projects.n_tasks(_id)
         n_task_runs = cached_projects.n_task_runs(_id)
         cached_projects.overall_progress(_id)
         cached_projects.last_activity(_id)
         cached_projects.n_completed_tasks(_id)
         cached_projects.n_volunteers(_id)
         if n_task_runs >= 1000 or featured:
             # print ("Getting stats for %s as it has %s task runs" %
             #        (short_name, n_task_runs))
             stats.get_stats(_id, app.config.get('GEO'))
         projects_cached.append(_id)
예제 #10
0
파일: jobs.py 프로젝트: ianthe/pybossa
 def warm_project(_id, short_name, featured=False):
     if _id not in projects_cached:
         cached_projects.get_project(short_name)
         cached_projects.n_tasks(_id)
         n_task_runs = cached_projects.n_task_runs(_id)
         cached_projects.overall_progress(_id)
         cached_projects.last_activity(_id)
         cached_projects.n_completed_tasks(_id)
         cached_projects.n_volunteers(_id)
         if n_task_runs >= 1000 or featured:
             # print ("Getting stats for %s as it has %s task runs" %
             #        (short_name, n_task_runs))
             stats.get_stats(_id, app.config.get('GEO'))
         projects_cached.append(_id)
예제 #11
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")
예제 #12
0
    def test_n_task_runs_returns_number_of_total_taskruns(self):
        project = self.create_project_with_contributors(anonymous=1, registered=1)

        taskruns = cached_projects.n_task_runs(project.id)

        assert taskruns == 2, taskruns