示例#1
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)
示例#2
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)
示例#3
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)
示例#4
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'))
示例#5
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)
示例#6
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'))
示例#7
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
    def test_last_activity_returns_date_of_latest_contribution(self):
        project = ProjectFactory.create()
        first_task_run = TaskRunFactory.create(project=project)
        last_task_run = TaskRunFactory.create(project=project)

        activity = cached_projects.last_activity(project.id)

        assert activity == last_task_run.finish_time, last_task_run
示例#10
0
    def test_last_activity_returns_date_of_latest_contribution(self):
        project = ProjectFactory.create()
        first_task_run = TaskRunFactory.create(project=project)
        last_task_run = TaskRunFactory.create(project=project)

        activity = cached_projects.last_activity(project.id)

        assert activity == last_task_run.finish_time, last_task_run
    def test_last_activity_returns_None_if_no_contributions(self):
        project = ProjectFactory.create()

        activity = cached_projects.last_activity(project.id)

        assert activity is None, activity
示例#12
0
    def test_last_activity_returns_None_if_no_contributions(self):
        project = ProjectFactory.create()

        activity = cached_projects.last_activity(project.id)

        assert activity is None, activity