Skip to content

Commit

Permalink
Fix "Project Statistics page missing data for Batches with 0 complete…
Browse files Browse the repository at this point in the history
…d Task Assignments" (#145)
  • Loading branch information
charman committed Apr 29, 2021
1 parent 03db0c6 commit 1919a9e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Project Statistics page now includes data about all Batches for
the Project, not just Batches with at least one completed Task
Assignment

## [2.4.0] - 2021-04-20
### Added
Expand Down
2 changes: 1 addition & 1 deletion turkle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
default_app_config = 'turkle.apps.TurkleAppConfig'
__version__ = '2.5.0-dev'
__version__ = '2.4.1-dev'
13 changes: 8 additions & 5 deletions turkle/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,22 +1024,25 @@ def project_stats(self, request, project_id):
uncompleted_tas_active_batches = 0
uncompleted_tas_inactive_batches = 0

batch_ids = task_duration_by_batch.keys()
stats_batches = []
for batch in Batch.objects.filter(id__in=batch_ids).order_by('name'):
for batch in project.batch_set.order_by('name'):
has_completed_assignments = batch.id in task_duration_by_batch
if has_completed_assignments:
assignments_completed = len(task_duration_by_batch[batch.id])
last_finished_time = task_updated_at_by_batch[batch.id][-1]
mean_work_time = int(statistics.mean(task_duration_by_batch[batch.id]))
median_work_time = int(statistics.median(task_duration_by_batch[batch.id]))
else:
assignments_completed = 0
last_finished_time = 'N/A'
mean_work_time = 'N/A'
median_work_time = 'N/A'
assignments_completed = len(task_duration_by_batch[batch.id])
total_task_assignments = batch.total_task_assignments()
assignments_completed_percentage = '%.1f' % \
(100.0 * assignments_completed / total_task_assignments)
if total_task_assignments != 0:
assignments_completed_percentage = '%.1f' % \
(100.0 * assignments_completed / total_task_assignments)
else:
assignments_completed_percentage = 'N/A'
stats_batches.append({
'batch_id': batch.id,
'name': batch.name,
Expand Down
17 changes: 17 additions & 0 deletions turkle/tests/test_admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,23 @@ def test_post_change_project_remove_and_add_user(self):
self.assertTrue(user_to_add.has_perm('can_work_on', project))
self.assertFalse(user_to_remove.has_perm('can_work_on', project))

def test_project_stats_view(self):
project = Project.objects.create(
name='foo', html_template='<p>${foo}: ${bar}</p><textarea>')
batch_no_tasks = Batch.objects.create(
project=project, name='No associated tasks', published=True)
batch_no_completed_tasks = Batch.objects.create(
project=project, name='No completed tasks', published=True)
Task.objects.create(batch=batch_no_completed_tasks)

client = django.test.Client()
client.login(username='admin', password='secret')
response = client.get(reverse('turkle_admin:project_stats',
kwargs={'project_id': project.id}))
self.assertEqual(response.status_code, 200)
self.assertTrue(batch_no_tasks.name in str(response.content))
self.assertTrue(batch_no_completed_tasks.name in str(response.content))


class TestReviewBatch(django.test.TestCase):
def test_batch_review_bad_batch_id(self):
Expand Down

0 comments on commit 1919a9e

Please sign in to comment.