Skip to content

Commit

Permalink
Merge pull request #1045 from bloomberg/RDISCROWD-7968
Browse files Browse the repository at this point in the history
RDISCROWD-7968 add n_gold_tasks to projectprogress API
  • Loading branch information
n00rsy authored Feb 20, 2025
2 parents ba4d9dc + f49f7e7 commit e75f190
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 7 additions & 6 deletions pybossa/repositories/project_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,14 @@ def get_total_and_completed_task_count(self, project_id):
sql = text(
'''
SELECT
(SELECT COUNT(*) FROM task
WHERE task.project_id=:project_id AND task.state='completed') as n_completed,
(SELECT COUNT(task.id) AS n_tasks FROM task
WHERE task.project_id=:project_id AND calibration != 1) as n_tasks;
SUM(CASE WHEN task.state = 'completed' THEN 1 ELSE 0 END) AS n_completed,
SUM(CASE WHEN calibration != 1 THEN 1 ELSE 0 END) AS n_tasks,
SUM(CASE WHEN calibration = 1 THEN 1 ELSE 0 END) AS n_gold_tasks
FROM task
WHERE task.project_id = :project_id;
'''
)
response = self.db.session.execute(sql, dict(project_id=project_id)).fetchall()
n_completed, n_tasks = response[0]
result = dict(n_completed_tasks=n_completed, n_tasks=n_tasks)
n_completed, n_tasks, n_gold_tasks = response[0]
result = dict(n_completed_tasks=n_completed, n_tasks=n_tasks, n_gold_tasks=n_gold_tasks)
return result
13 changes: 8 additions & 5 deletions test/test_api/test_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2513,7 +2513,7 @@ def test_project_progress(self):
# query for the count of all tasks in the propject
res = self.app.get('/api/project/1/projectprogress', follow_redirects=True, headers=headers)
assert res.status_code == 200
assert res.json == dict(n_completed_tasks=0, n_tasks=3)
assert res.json == dict(n_completed_tasks=0, n_tasks=3, n_gold_tasks=0)

# mark 2 out of total 3 tasks as complete
for i in range(n_answers):
Expand All @@ -2523,15 +2523,15 @@ def test_project_progress(self):
# query for the count of all tasks in the propject
res = self.app.get('/api/project/1/projectprogress', follow_redirects=True, headers=headers)
assert res.status_code == 200
assert res.json == dict(n_completed_tasks=2, n_tasks=3)
assert res.json == dict(n_completed_tasks=2, n_tasks=3, n_gold_tasks=0)

# mark third task also complete
for i in range(n_answers):
TaskRunFactory.create(task=tasks[2], project=project)
# query for the count of all tasks in the propject
res = self.app.get('/api/project/1/projectprogress', follow_redirects=True, headers=headers)
assert res.status_code == 200
assert res.json == dict(n_completed_tasks=3, n_tasks=3)
assert res.json == dict(n_completed_tasks=3, n_tasks=3, n_gold_tasks=0), res.json

# accessing api with subadmin user who's not owner fails
headers = [('Authorization', subadmin.api_key)]
Expand All @@ -2554,12 +2554,15 @@ def test_project_progress(self):
# query for the count of total tasks and completed tasks in the propject
res = self.app.get('/api/project/1/projectprogress', follow_redirects=True, headers=headers)
assert res.status_code == 200
assert res.json == dict(n_completed_tasks=3, n_tasks=3)
assert res.json == dict(n_completed_tasks=3, n_tasks=3, n_gold_tasks=0)

# create gold tasks
tasks = TaskFactory.create_batch(2, project=project, calibration = 1)

# accessing api using project short_name pass
res = self.app.get('/api/project/testproject/projectprogress', follow_redirects=True, headers=headers)
assert res.status_code == 200
assert res.json == dict(n_completed_tasks=3, n_tasks=3)
assert res.json == dict(n_completed_tasks=3, n_tasks=3, n_gold_tasks=2)


def _setup_project(self, short_name, owner):
Expand Down

0 comments on commit e75f190

Please sign in to comment.