Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDISCROWD-7968 add n_gold_tasks to projectprogress API #1045

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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