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)
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'))
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)
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()
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()
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 test_n_volunteers(self): """Test CACHE PROJECTS n_volunteers returns the sum of the anonymous plus registered volunteers that contributed to a project""" app = self.create_app_with_contributors(anonymous=2, registered=3, two_tasks=True) total_volunteers = cached_apps.n_volunteers(app.id) err_msg = "Volunteers is %s, it should be 5" % total_volunteers assert total_volunteers == 5, err_msg
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
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