Commit 37d08956723807cf6285c787b741b93670af3ba4
1 parent
8d6ee39a
Exists in
master
Added a new API endpoint to retrieve projects progress.
Showing
2 changed files
with
23 additions
and
2 deletions
Show diff stats
pybossa/api/__init__.py
@@ -200,7 +200,14 @@ def leaderboard(): | @@ -200,7 +200,14 @@ def leaderboard(): | ||
200 | @crossdomain(origin='*', headers=cors_headers) | 200 | @crossdomain(origin='*', headers=cors_headers) |
201 | @ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER')) | 201 | @ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER')) |
202 | def project_last_answers(): | 202 | def project_last_answers(): |
203 | - user_id = None if current_user.is_anonymous() else current_user.id | ||
204 | project_id = request.args.get('project_id') | 203 | project_id = request.args.get('project_id') |
205 | data = cached_projects.project_last_answers(project_id) | 204 | data = cached_projects.project_last_answers(project_id) |
206 | return Response(json.dumps(data), mimetype="application/json") | 205 | return Response(json.dumps(data), mimetype="application/json") |
206 | + | ||
207 | +@jsonpify | ||
208 | +@blueprint.route('/projects_progress') | ||
209 | +@crossdomain(origin='*', headers=cors_headers) | ||
210 | +@ratelimit(limit=ratelimits.get('LIMIT'), per=ratelimits.get('PER')) | ||
211 | +def projects_progress(): | ||
212 | + data = cached_projects.projects_progress() | ||
213 | + return Response(json.dumps(data), mimetype="application/json") |
pybossa/cache/projects.py
@@ -234,7 +234,21 @@ def project_last_answers(project_id): | @@ -234,7 +234,21 @@ def project_last_answers(project_id): | ||
234 | last_answers = dict() | 234 | last_answers = dict() |
235 | last_answers['project_name'] = project.short_name | 235 | last_answers['project_name'] = project.short_name |
236 | last_answers['last_answers'] = project_last_answers_data(project.id) | 236 | last_answers['last_answers'] = project_last_answers_data(project.id) |
237 | - result.append(last_answers) | 237 | + results.append(last_answers) |
238 | + return results | ||
239 | + | ||
240 | +@memoize(timeout=timeouts.get('APP_TIMEOUT')) | ||
241 | +def projects_progress(): | ||
242 | + projects = session.query(Project).all() | ||
243 | + results = [] | ||
244 | + for project in projects: | ||
245 | + progress = dict() | ||
246 | + progress['short_name'] = project.short_name | ||
247 | + progress['n_tasks'] = n_tasks(project.id) | ||
248 | + progress['n_task_runs'] = n_task_runs(project.id) | ||
249 | + progress['n_completed_tasks'] = n_completed_tasks(project.id) | ||
250 | + progress['last_activity'] = last_activity(project.id) | ||
251 | + results.append(progress) | ||
238 | return results | 252 | return results |
239 | 253 | ||
240 | @memoize(timeout=timeouts.get('APP_TIMEOUT')) | 254 | @memoize(timeout=timeouts.get('APP_TIMEOUT')) |