Beispiel #1
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, app.config.get('GEO'))
         apps_cached.append(id)
Beispiel #2
0
def get_app_stats(id, short_name): # pragma: no cover
    """Get stats for app."""
    import pybossa.cache.apps as cached_apps
    import pybossa.cache.project_stats as stats
    from flask import current_app

    cached_apps.get_app(short_name)
    cached_apps.n_tasks(id)
    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)
    stats.get_stats(id, current_app.config.get('GEO'))
Beispiel #3
0
 def warm_app(id, short_name):
     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:
             print "Getting stats for %s as it has %s" % (id,
                                                          n_task_runs)
             stats.get_stats(id, app.config.get('GEO'))
         apps_cached.append(id)
Beispiel #4
0
def get_app_stats(id, short_name): # pragma: no cover
    """Get stats for app."""
    import pybossa.cache.apps as cached_apps
    import pybossa.cache.project_stats as stats
    from flask import current_app

    cached_apps.get_app(short_name)
    cached_apps.n_tasks(id)
    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)
    stats.get_stats(id, current_app.config.get('GEO'))
Beispiel #5
0
def hidden_apps(user_id):
    sql = text('''
               SELECT app.id, app.name, app.short_name, app.description,
               app.owner_id,
               app.info
               FROM app, task
               WHERE app.id=task.app_id AND app.owner_id=:user_id AND
               app.hidden=1 AND app.info LIKE('%task_presenter%')
               GROUP BY app.id, app.name, app.short_name,
               app.description,
               app.info;''')
    apps_published = []
    results = session.execute(sql, dict(user_id=user_id))
    for row in results:
        app = dict(id=row.id,
                   name=row.name,
                   short_name=row.short_name,
                   owner_id=row.owner_id,
                   description=row.description,
                   overall_progress=overall_progress(row.id),
                   n_tasks=n_tasks(row.id),
                   n_volunteers=n_volunteers(row.id),
                   info=json.loads(row.info))
        apps_published.append(app)
    return apps_published
def app_index(page, lookup, category, fallback, use_count):
    """Show apps of app_type"""

    per_page = 5
    # @FC to come back to project homepage from the application detail
    if 'cat_byapp_' in category:
        category = get_app_category(category.replace("cat_byapp_", ""))

    # @FC
    apps, count = lookup(category, page, per_page)

    data = []
    #for app in apps:
    #    if 'tutorial' in app['short_name']:
    #        data.append(dict(app=app, n_tasks=cached_apps.n_tasks(app['id']),
    #                         overall_progress=cached_apps.overall_progress(app['id']),
    #                         last_activity=cached_apps.last_activity(app['id'])))
    for app in apps:
        if 'tutorial' not in app['short_name']:
            data.append(dict(app=app, n_tasks=cached_apps.n_tasks(app['id']),
                             overall_progress=cached_apps.overall_progress(app['id']),
                             last_activity=cached_apps.last_activity(app['id'])))

    if fallback and not apps:
        return redirect(url_for('.published'))

    pagination = Pagination(page, per_page, count)
    categories = cached_cat.get_all()
    # Check for pre-defined categories featured and draft
    featured_cat = model.Category(name='Featured',
                                  short_name='featured',
                                  description='Featured applications')
    if category == 'featured':
        active_cat = featured_cat
    elif category == 'draft':
        active_cat = model.Category(name='Draft',
                                    short_name='draft',
                                    description='Draft applications')
    else:
        active_cat = db.session.query(model.Category)\
                       .filter_by(short_name=category).first()

    # Check if we have to add the section Featured to local nav
    if cached_apps.n_featured() > 0:
        categories.insert(0, featured_cat)
    template_args = {
        "apps": data,
        "title": gettext("Applications"),
        "pagination": pagination,
        "active_cat": active_cat,
        "n_apps_per_category": None,
        "categories": categories}

    n_apps_per_category = dict()
    for c in categories:
        n_apps_per_category[c.short_name] = cached_apps.n_count(c.short_name)
    template_args['n_apps_per_category'] = n_apps_per_category
    if use_count:
        template_args.update({"count": count})
    return render_template('/applications/index.html', **template_args)
Beispiel #7
0
def hidden_apps(user_id):
    try:
        sql = text('''
                   SELECT app.id, app.name, app.short_name, app.description,
                   app.owner_id,
                   app.info
                   FROM app, task
                   WHERE app.id=task.app_id AND app.owner_id=:user_id AND
                   app.hidden=1 AND app.info LIKE('%task_presenter%')
                   GROUP BY app.id, app.name, app.short_name,
                   app.description,
                   app.info;''')
        apps_published = []
        session = get_session(db, bind='slave')
        results = session.execute(sql, dict(user_id=user_id))
        for row in results:
            app = dict(id=row.id, name=row.name, short_name=row.short_name,
                       owner_id=row.owner_id,
                       description=row.description,
                       overall_progress=overall_progress(row.id),
                       n_tasks=n_tasks(row.id),
                       n_volunteers=n_volunteers(row.id),
                       info=json.loads(row.info))
            apps_published.append(app)
        return apps_published
    except: # pragma: no cover
        session.rollback()
        raise
    finally:
        session.close()
Beispiel #8
0
def apps_contributed(user_id):
    try:
        sql = text('''
                   WITH apps_contributed as 
                        (SELECT DISTINCT(app_id) FROM task_run 
                         WHERE user_id=:user_id)
                   SELECT app.id, app.name, app.short_name, app.owner_id,
                   app.description, app.info FROM app, apps_contributed
                   WHERE app.id=apps_contributed.app_id ORDER BY app.name DESC;
                   ''')
        session = get_session(db, bind='slave')
        results = session.execute(sql, dict(user_id=user_id))
        apps_contributed = []
        for row in results:
            app = dict(id=row.id, name=row.name, short_name=row.short_name,
                       owner_id=row.owner_id,
                       description=row.description,
                       overall_progress=overall_progress(row.id),
                       n_tasks=n_tasks(row.id),
                       n_volunteers=n_volunteers(row.id),
                       info=json.loads(row.info))
            apps_contributed.append(app)
        return apps_contributed
    except: # pragma: no cover
        session.rollback()
    finally:
        session.close()
Beispiel #9
0
def check_contributing_state(app_id, user_id=None, user_ip=None):
    """Returns the state of a given app for a given user, depending on whether
    the app is completed or not and the user can contribute more to it or not"""

    states = ('completed', 'can_contribute', 'cannot_contribute')
    if overall_progress(app_id) >= 100:
        return states[0]
    if n_available_tasks(app_id, user_id=user_id, user_ip=user_ip) > 0:
        return states[1]
    return states[2]
Beispiel #10
0
def check_contributing_state(app_id, user_id=None, user_ip=None):
    """Returns the state of a given app for a given user, depending on whether
    the app is completed or not and the user can contribute more to it or not"""

    states = ('completed', 'can_contribute', 'cannot_contribute')
    if overall_progress(app_id) >= 100:
        return states[0]
    if n_available_tasks(app_id, user_id=user_id, user_ip=user_ip) > 0:
        return states[1]
    return states[2]
Beispiel #11
0
def app_by_shortname(short_name):
    app = cached_apps.get_app(short_name)
    if app.id:
        # Populate CACHE with the data of the app
        return (app, cached_apps.n_tasks(app.id),
                cached_apps.n_task_runs(app.id),
                cached_apps.overall_progress(app.id),
                cached_apps.last_activity(app.id))

    else:
        return abort(404)
Beispiel #12
0
def app_by_shortname(short_name):
    app = cached_apps.get_app(short_name)
    if app.id:
        # Populate CACHE with the data of the app
        return (app,
                cached_apps.n_tasks(app.id),
                cached_apps.n_task_runs(app.id),
                cached_apps.overall_progress(app.id),
                cached_apps.last_activity(app.id))

    else:
        return abort(404)
Beispiel #13
0
def check_contributing_state(app, user_id=None, user_ip=None):
    """Returns the state of a given app for a given user, depending on whether
    the app is completed or not and the user can contribute more to it or not"""

    app_id = app['id'] if type(app) == dict else app.id
    states = ('completed', 'draft', 'can_contribute', 'cannot_contribute')
    if overall_progress(app_id) >= 100:
        return states[0]
    if _has_no_presenter(app) or _has_no_tasks(app_id):
        return states[1]
    if n_available_tasks(app_id, user_id=user_id, user_ip=user_ip) > 0:
        return states[2]
    return states[3]
Beispiel #14
0
def check_contributing_state(app, user_id=None, user_ip=None):
    """Returns the state of a given app for a given user, depending on whether
    the app is completed or not and the user can contribute more to it or not"""

    app_id = app['id'] if type(app) == dict else app.id
    states = ('completed', 'draft', 'can_contribute', 'cannot_contribute')
    if overall_progress(app_id) >= 100:
        return states[0]
    if _has_no_presenter(app) or _has_no_tasks(app_id):
        return states[1]
    if n_available_tasks(app_id, user_id=user_id, user_ip=user_ip) > 0:
        return states[2]
    return states[3]
Beispiel #15
0
def app_index(page, lookup, category, fallback, use_count):
    """Show apps of app_type"""

    per_page = 5

    apps, count = lookup(category, page, per_page)

    data = []
    for app in apps:
        data.append(
            dict(app=app,
                 n_tasks=cached_apps.n_tasks(app['id']),
                 overall_progress=cached_apps.overall_progress(app['id']),
                 last_activity=app['last_activity'],
                 last_activity_raw=app['last_activity_raw']))

    if fallback and not apps:  # pragma: no cover
        return redirect(url_for('.index'))

    pagination = Pagination(page, per_page, count)
    categories = cached_cat.get_all()
    # Check for pre-defined categories featured and draft
    featured_cat = model.Category(name='Featured',
                                  short_name='featured',
                                  description='Featured applications')
    if category == 'featured':
        active_cat = featured_cat
    elif category == 'draft':
        active_cat = model.Category(name='Draft',
                                    short_name='draft',
                                    description='Draft applications')
    else:
        active_cat = db.session.query(model.Category)\
                       .filter_by(short_name=category).first()

    # Check if we have to add the section Featured to local nav
    if cached_apps.n_featured() > 0:
        categories.insert(0, featured_cat)
    template_args = {
        "apps": data,
        "title": gettext("Applications"),
        "pagination": pagination,
        "active_cat": active_cat,
        "categories": categories
    }

    if use_count:
        template_args.update({"count": count})
    return render_template('/applications/index.html', **template_args)
Beispiel #16
0
def app_index(page, lookup, category, fallback, use_count):
    """Show apps of app_type"""

    per_page = 5

    apps, count = lookup(category, page, per_page)

    data = []
    for app in apps:
        data.append(dict(app=app, n_tasks=cached_apps.n_tasks(app['id']),
                         overall_progress=cached_apps.overall_progress(app['id']),
                         last_activity=app['last_activity'],
                         last_activity_raw=app['last_activity_raw']))


    if fallback and not apps:  # pragma: no cover
        return redirect(url_for('.index'))

    pagination = Pagination(page, per_page, count)
    categories = cached_cat.get_all()
    # Check for pre-defined categories featured and draft
    featured_cat = model.Category(name='Featured',
                                  short_name='featured',
                                  description='Featured applications')
    if category == 'featured':
        active_cat = featured_cat
    elif category == 'draft':
        active_cat = model.Category(name='Draft',
                                    short_name='draft',
                                    description='Draft applications')
    else:
        active_cat = db.session.query(model.Category)\
                       .filter_by(short_name=category).first()

    # Check if we have to add the section Featured to local nav
    if cached_apps.n_featured() > 0:
        categories.insert(0, featured_cat)
    template_args = {
        "apps": data,
        "title": gettext("Applications"),
        "pagination": pagination,
        "active_cat": active_cat,
        "categories": categories}

    if use_count:
        template_args.update({"count": count})
    return render_template('/applications/index.html', **template_args)
Beispiel #17
0
def apps_contributed(user_id):
    sql = text('''
               WITH apps_contributed as
                    (SELECT DISTINCT(app_id) FROM task_run
                     WHERE user_id=:user_id)
               SELECT app.id, app.name, app.short_name, app.owner_id,
               app.description, app.info FROM app, apps_contributed
               WHERE app.id=apps_contributed.app_id ORDER BY app.name DESC;
               ''')
    results = db.slave_session.execute(sql, dict(user_id=user_id))
    apps_contributed = []
    for row in results:
        app = dict(id=row.id, name=row.name, short_name=row.short_name,
                   owner_id=row.owner_id,
                   description=row.description,
                   overall_progress=overall_progress(row.id),
                   n_tasks=n_tasks(row.id),
                   n_volunteers=n_volunteers(row.id),
                   info=json.loads(row.info))
        apps_contributed.append(app)
    return apps_contributed
Beispiel #18
0
def hidden_apps(user_id):
    sql = text('''
               SELECT app.id, app.name, app.short_name, app.description,
               app.owner_id,
               app.info
               FROM app, task
               WHERE app.id=task.app_id AND app.owner_id=:user_id AND
               app.hidden=1 AND app.info LIKE('%task_presenter%')
               GROUP BY app.id, app.name, app.short_name,
               app.description,
               app.info;''')
    apps_published = []
    results = session.execute(sql, dict(user_id=user_id))
    for row in results:
        app = dict(id=row.id, name=row.name, short_name=row.short_name,
                   owner_id=row.owner_id,
                   description=row.description,
                   overall_progress=overall_progress(row.id),
                   n_tasks=n_tasks(row.id),
                   n_volunteers=n_volunteers(row.id),
                   info=json.loads(row.info))
        apps_published.append(app)
    return apps_published
Beispiel #19
0
def draft_apps(user_id):
    sql = text('''
               SELECT app.id, app.name, app.short_name, app.description,
               owner_id,
               app.info
               FROM app
               WHERE app.owner_id=:user_id
               AND app.info NOT LIKE('%task_presenter%')
               GROUP BY app.id, app.name, app.short_name,
               app.description,
               app.info;''')
    apps_draft = []
    results = db.slave_session.execute(sql, dict(user_id=user_id))
    for row in results:
        app = dict(id=row.id, name=row.name, short_name=row.short_name,
                   owner_id=row.owner_id,
                   description=row.description,
                   overall_progress=overall_progress(row.id),
                   n_tasks=n_tasks(row.id),
                   n_volunteers=n_volunteers(row.id),
                   info=json.loads(row.info))
        apps_draft.append(app)
    return apps_draft