def test_n_unexpired_gold_tasks_expired_tasks(self): project = ProjectFactory.create() task = TaskFactory.create(project=project, calibration=1, expiration='2012-01-01T00:00:00') n_gold_tasks = helpers.n_unexpired_gold_tasks(project.id) assert n_gold_tasks == 0, n_available_tasks
def user_progress(project_id=None, short_name=None): """API endpoint for user progress. Return a JSON object with four fields regarding the tasks for the user: { 'done': 10, 'total: 100, 'remaining': 90, 'remaining_for_user': 45 } This will mean that the user has done 10% of the available tasks for the project, 90 tasks are yet to be submitted and the user can access 45 of them based on user preferences. """ if current_user.is_anonymous: return abort(401) if project_id or short_name: if short_name: project = project_repo.get_by_shortname(short_name) elif project_id: project = project_repo.get(project_id) if project: # For now, keep this version, but wait until redis cache is # used here for task_runs too query_attrs = dict(project_id=project.id, user_id=current_user.id) guidelines_updated = _guidelines_updated(project.id, current_user.id) taskrun_count = task_repo.count_task_runs_with(**query_attrs) num_available_tasks = n_available_tasks(project.id, include_gold_task=True) num_available_tasks_for_user = n_available_tasks_for_user( project, current_user.id) response = dict(done=taskrun_count, total=n_tasks(project.id), completed=n_completed_tasks(project.id), remaining=num_available_tasks, locked=len({ task["task_id"] for task in get_locked_tasks(project) }), remaining_for_user=num_available_tasks_for_user, quiz=current_user.get_quiz_for_project(project), guidelines_updated=guidelines_updated) if current_user.admin or (current_user.subadmin and current_user.id in project.owners_ids): num_gold_tasks = n_unexpired_gold_tasks(project.id) response['available_gold_tasks'] = num_gold_tasks return Response(json.dumps(response), mimetype="application/json") else: return abort(404) else: # pragma: no cover return abort(404)
def test_n_unexpired_gold_tasks_has_tasks(self): project = ProjectFactory.create() task = TaskFactory.create_batch(3, project=project, calibration=1) n_gold_tasks = helpers.n_unexpired_gold_tasks(project.id) assert n_gold_tasks == 3, n_available_tasks
def test_n_unexpired_gold_tasks_no_tasks(self): project = ProjectFactory.create() task = TaskFactory.create(project=project) n_gold_tasks = helpers.n_unexpired_gold_tasks(project.id) assert n_gold_tasks == 0, n_available_tasks