Exemplo n.º 1
0
def update_counters():
    """Populates the counters table."""
    from pybossa.core import db
    from pybossa.core import project_repo, task_repo, result_repo
    from pybossa.model.task import Task
    from pybossa.model.task_run import TaskRun
    from pybossa.model.counter import Counter

    projects = project_repo.get_all()

    print len(projects)

    db.session.query(Counter).delete()
    db.session.commit()


    for project in projects:
        print "Working on project: %s" % project.id
        sql = text('''select task.project_id as project_id, task.id as task_id, count(task_run.task_id) as n_task_runs from task left outer join task_run on (task_run.task_id=task.id) where task.project_id=:project_id group by task.project_id, task.id, task_run.task_id''')
        results = db.engine.execute(sql, project_id=project.id)
        for result in results:
            db.session.add(Counter(project_id=result.project_id,
                                   task_id=result.task_id,
                                   n_task_runs=result.n_task_runs))
        db.session.commit()
Exemplo n.º 2
0
def home():
    """Render home page with the cached projects and users."""
    page = 1
    per_page = current_app.config.get('APPS_PER_PAGE', 5)

    # Add featured
    tmp_projects = cached_projects.get_featured('featured', page, per_page)
    if len(tmp_projects) > 0:
        data = dict(featured=rank(tmp_projects))
    else:
        data = dict(featured=[])
    # Add historical contributions
    historical_projects = []
    projects = project_repo.get_all()
    data['projects'] = []
    for project in projects:
        if project.published == True:
            data['projects'].append(project)
    if current_user.is_authenticated():
        user_id = current_user.id
        historical_projects = cached_users.projects_contributed(
            user_id, order_by='last_contribution')[:3]
        data['historical_contributions'] = historical_projects
    response = dict(template='/home/index.html', **data)
    return handle_content_type(response)
Exemplo n.º 3
0
def update_counters():
    """Populates the counters table."""
    from pybossa.core import db
    from pybossa.core import project_repo, task_repo, result_repo
    from pybossa.model.task import Task
    from pybossa.model.task_run import TaskRun
    from pybossa.model.counter import Counter

    projects = project_repo.get_all()

    print len(projects)

    db.session.query(Counter).delete()
    db.session.commit()

    for project in projects:
        print "Working on project: %s" % project.id
        sql = text(
            '''select task.project_id as project_id, task.id as task_id, count(task_run.task_id) as n_task_runs from task left outer join task_run on (task_run.task_id=task.id) where task.project_id=:project_id group by task.project_id, task.id, task_run.task_id'''
        )
        results = db.engine.execute(sql, project_id=project.id)
        for result in results:
            db.session.add(
                Counter(project_id=result.project_id,
                        task_id=result.task_id,
                        n_task_runs=result.n_task_runs))
        db.session.commit()
Exemplo n.º 4
0
def get_autoimport_jobs(queue='high'):
    current_app.logger.error("This isn't really an error, autoimport was triggered!")
    """Get autoimport jobs."""
    from pybossa.core import project_repo
    #current_app.logger.error("v1a")
    import pybossa.cache.projects as cached_projects
    #current_app.logger.error("v1b")
    from pybossa.pro_features import ProFeatureHandler
    #current_app.logger.error("v1c")
    feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))

    timeout = current_app.config.get('TIMEOUT')
    #current_app.logger.error("v2")
    #if feature_handler.only_for_pro('autoimporter'):
    #    current_app.logger.error("v3a")
    #    projects = cached_projects.get_from_pro_user()
    #else:
    #current_app.logger.error("v3b")
    projects = (p.dictize() for p in project_repo.get_all())
    #current_app.logger.error("v4")
    for project_dict in projects:
        #current_app.logger.error("v5")
        project = project_repo.get(project_dict['id'])
        #current_app.logger.error(str(project))
        if project.has_autoimporter():
            #current_app.logger.error(str(project))
            #current_app.logger.error("v6")
            job = dict(name=import_tasks,
                       args=[project.id, True],
                       kwargs=project.get_autoimporter(),
                       timeout=timeout,
                       queue=queue)
            #current_app.logger.error(str(job))
            #current_app.logger.error("v7")
            yield job
Exemplo n.º 5
0
def get_export_task_jobs(queue):
    """Export tasks to zip."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    from pybossa.pro_features import ProFeatureHandler

    feature_handler = ProFeatureHandler(current_app.config.get("PRO_FEATURES"))
    if feature_handler.only_for_pro("updated_exports"):
        if queue == "high":
            projects = cached_projects.get_from_pro_user()
        else:
            projects = (p.dictize() for p in project_repo.get_all() if p.owner.pro is False)
    else:
        projects = (p.dictize() for p in project_repo.get_all())
    for project in projects:
        project_id = project.get("id")
        job = dict(name=project_export, args=[project_id], kwargs={}, timeout=(10 * MINUTE), queue=queue)
        yield job
Exemplo n.º 6
0
def get_export_task_jobs(queue):
    """Export tasks to zip."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    from pybossa.pro_features import ProFeatureHandler
    feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))
    if feature_handler.only_for_pro('updated_exports'):
        if queue == 'high':
            projects = cached_projects.get_from_pro_user()
        else:
            projects = (p.dictize() for p in project_repo.get_all()
                        if p.owner.pro is False)
    else:
        projects = (p.dictize() for p in project_repo.get_all())
    for project in projects:
        project_id = project.get('id')
        job = dict(name=project_export,
                   args=[project_id], kwargs={},
                   timeout=(10 * MINUTE),
                   queue=queue)
        yield job
Exemplo n.º 7
0
def get_export_task_jobs(queue):
    """Export tasks to zip."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    if queue == 'high':
        projects = cached_projects.get_from_pro_user()
    else:
        projects = (p.dictize() for p in project_repo.get_all()
                    if p.owner.pro is False)
    for project in projects:
        project_id = project.get('id')
        job = dict(name=project_export,
                   args=[project_id], kwargs={},
                   timeout=(10 * MINUTE),
                   queue=queue)
        yield job
Exemplo n.º 8
0
def get_export_task_jobs(queue):
    """Export tasks to zip."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    if queue == 'high':
        projects = cached_projects.get_from_pro_user()
    else:
        projects = (p.dictize() for p in project_repo.get_all()
                    if p.owner.pro is False)
    for project in projects:
        project_id = project.get('id')
        job = dict(name=project_export,
                   args=[project_id], kwargs={},
                   timeout=(10 * MINUTE),
                   queue=queue)
        yield job
Exemplo n.º 9
0
def get_project_jobs(queue):
    """Return a list of jobs based on user type."""
    from pybossa.core import project_repo
    from pybossa.cache import projects as cached_projects
    timeout = current_app.config.get('TIMEOUT')
    if queue == 'super':
        projects = cached_projects.get_from_pro_user()
    elif queue == 'high':
        projects = (p.dictize() for p in project_repo.get_all())
    else:
        projects = []
    for project in projects:
        project_id = project.get('id')
        project_short_name = project.get('short_name')
        job = dict(name=get_project_stats,
                   args=[project_id, project_short_name], kwargs={},
                   timeout=timeout,
                   queue=queue)
        yield job
Exemplo n.º 10
0
def update_project_stats():
    """Update project stats for draft projects."""
    from pybossa.core import db
    from pybossa.core import project_repo, task_repo, result_repo
    from pybossa.model.task import Task
    from pybossa.model.task_run import TaskRun
    from pybossa.model.counter import Counter
    import pybossa.cache.project_stats as stats

    projects = project_repo.get_all()

    for project in projects:
        print "Working on project: %s" % project.short_name
        sql_query = """INSERT INTO project_stats 
                       (project_id, n_tasks, n_task_runs, n_results, n_volunteers,
                       n_completed_tasks, overall_progress, average_time,
                       n_blogposts, last_activity, info)
                       VALUES (%s, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{}');""" % (project.id)
        db.engine.execute(sql_query)
Exemplo n.º 11
0
def update_project_stats():
    """Update project stats for draft projects."""
    from pybossa.core import db
    from pybossa.core import project_repo, task_repo, result_repo
    from pybossa.model.task import Task
    from pybossa.model.task_run import TaskRun
    from pybossa.model.counter import Counter
    import pybossa.cache.project_stats as stats

    projects = project_repo.get_all()

    for project in projects:
        print "Working on project: %s" % project.short_name
        sql_query = """INSERT INTO project_stats 
                       (project_id, n_tasks, n_task_runs, n_results, n_volunteers,
                       n_completed_tasks, overall_progress, average_time,
                       n_blogposts, last_activity, info)
                       VALUES (%s, 0, 0, 0, 0, 0, 0, 0, 0, 0, '{}');""" % (project.id)
        db.engine.execute(sql_query)
Exemplo n.º 12
0
def get_autoimport_jobs(queue='low'):
    """Get autoimport jobs."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    from pybossa.pro_features import ProFeatureHandler
    feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))
    if feature_handler.only_for_pro('autoimporter'):
        projects = cached_projects.get_from_pro_user()
    else:
        projects = (p.dictize() for p in project_repo.get_all())
    for project_dict in projects:
        project = project_repo.get(project_dict['id'])
        if project.has_autoimporter():
            job = dict(name=import_tasks,
                       args=[project.id],
                       kwargs=project.get_autoimporter(),
                       timeout=IMPORT_TASKS_TIMEOUT,
                       queue=queue)
            yield job
Exemplo n.º 13
0
def get_autoimport_jobs(queue='low'):
    """Get autoimport jobs."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    from pybossa.pro_features import ProFeatureHandler
    feature_handler = ProFeatureHandler(current_app.config.get('PRO_FEATURES'))

    timeout = current_app.config.get('TIMEOUT')

    if feature_handler.only_for_pro('autoimporter'):
        projects = cached_projects.get_from_pro_user()
    else:
        projects = (p.dictize() for p in project_repo.get_all())
    for project_dict in projects:
        project = project_repo.get(project_dict['id'])
        if project.has_autoimporter():
            job = dict(name=import_tasks,
                       args=[project.id, True],
                       kwargs=project.get_autoimporter(),
                       timeout=timeout,
                       queue=queue)
            yield job
Exemplo n.º 14
0
def get_autoimport_jobs(queue="low"):
    """Get autoimport jobs."""
    from pybossa.core import project_repo
    import pybossa.cache.projects as cached_projects
    from pybossa.pro_features import ProFeatureHandler

    feature_handler = ProFeatureHandler(current_app.config.get("PRO_FEATURES"))
    if feature_handler.only_for_pro("autoimporter"):
        projects = cached_projects.get_from_pro_user()
    else:
        projects = (p.dictize() for p in project_repo.get_all())
    for project_dict in projects:
        project = project_repo.get(project_dict["id"])
        if project.has_autoimporter():
            job = dict(
                name=import_tasks,
                args=[project.id],
                kwargs=project.get_autoimporter(),
                timeout=IMPORT_TASKS_TIMEOUT,
                queue=queue,
            )
            yield job
Exemplo n.º 15
0
def map_result():
    """Map result page ."""
    all_projects = project_repo.get_all()
    return render_template('/admin/map_result.html', all_projects=all_projects)
Exemplo n.º 16
0
def map_result():
    """Map result page ."""
    all_projects = project_repo.get_all()
    return render_template('/admin/map_result.html', all_projects=all_projects)