Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #363 from edx/dan-f/fix-negative-video-bars
Browse files Browse the repository at this point in the history
Fix negative video bars.
  • Loading branch information
dan-f committed Oct 7, 2015
2 parents 473e691 + 363e452 commit 1ff51fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion analytics_dashboard/courses/presenters/engagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def attach_computed_data(self, video):
video['id'] = video.pop('encoded_module_id')

total = max([video['users_at_start'], video['users_at_end']])
start_only_users = video['users_at_start'] - video['users_at_end']
start_only_users = max(video['users_at_start'] - video['users_at_end'], 0)
video.update({
'end_percent': utils.math.calculate_percent(video['users_at_end'], total),
'start_only_users': start_only_users,
Expand Down
16 changes: 16 additions & 0 deletions analytics_dashboard/courses/tests/test_presenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ def test_attach_computed_data(self):
'start_only_percent': start_only_users / max_users,
})

def test_greater_users_at_end(self):
module_data = {
'encoded_module_id': self.VIDEO_ID,
'users_at_start': 0,
'users_at_end': 1
}
self.presenter.attach_computed_data(module_data)
self.assertDictEqual(module_data, {
'id': self.VIDEO_ID,
'users_at_start': 0,
'users_at_end': 1,
'end_percent': 1.0,
'start_only_users': 0,
'start_only_percent': 0.0,
})

def test_attach_aggregated_data_to_parent(self):
parent = {
'num_modules': 2,
Expand Down

0 comments on commit 1ff51fd

Please sign in to comment.