-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add learning hours count to the stats api #169
feat: add learning hours count to the stats api #169
Conversation
038f0ce
to
6d56c74
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you @tehreem-sadat . I left a few comments for you
STAT_LEARNING_HOURS = 'learning_hours' | ||
|
||
valid_stats = [ | ||
STAT_CERTIFICATES, STAT_COURSES, STAT_ENROLLMENTS, STAT_HIDDEN_COURSES, STAT_LEARNERS, STAT_LEARNING_HOURS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STAT_CERTIFICATES, STAT_COURSES, STAT_ENROLLMENTS, STAT_HIDDEN_COURSES, STAT_LEARNERS, STAT_LEARNING_HOURS | |
STAT_CERTIFICATES, STAT_COURSES, STAT_ENROLLMENTS, STAT_HIDDEN_COURSES, STAT_LEARNERS, STAT_LEARNING_HOURS, |
settings.FX_DEFAULT_COURSE_EFFORT = getattr( | ||
settings, | ||
'FX_DEFAULT_COURSE_EFFORT', | ||
'50' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value was communicated with Nelc team
'50' | |
'12', |
('30', 30 * 2, 'Valid, only hours provided (no minutes)'), | ||
('5:120', 10 * 2, 'Invalid, minutes exceed 60, use default value'), | ||
('invalid', 10 * 2, 'Invalid, non-numeric value for hours, use default value'), | ||
('20:invalid', 10 * 2, 'Invalid, non-numeric value for minutes, use default value'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two more tests, please
('20:invalid', 10 * 2, 'Invalid, non-numeric value for minutes, use default value'), | |
('20:invalid', 10 * 2, 'Invalid, non-numeric value for minutes, use default value'), | |
('0:25', 10 * 2, 'Invalid, less than 30 minutes'), | |
('0:-55', 10 * 2, 'Invalid, less than 30 minutes'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good catch there.
return round(total_hours, 1) | ||
except (ValueError, IndexError): | ||
return settings.FX_DEFAULT_COURSE_EFFORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to make it silent for the user, but noisy for us in the logs
return round(total_hours, 1) | |
except (ValueError, IndexError): | |
return settings.FX_DEFAULT_COURSE_EFFORT | |
if total_hours < 0.5: | |
raise ValueError('course effort value is too small') | |
return round(total_hours, 1) | |
except (ValueError, IndexError) as exc: | |
log.exception('Invalid course-effort for course %s. Assuming default value (%s hours). Error: %s', course_id, settings.FX_DEFAULT_COURSE_EFFORT, str(exc)) | |
return settings.FX_DEFAULT_COURSE_EFFORT |
|
||
|
||
def get_learning_hours_count( | ||
fx_permission_info: dict, visible_courses_filter: bool | None = True, active_courses_filter: bool | None = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ same default values for argument as in get_certificates_count
. Thank you!
).values('course_effort', 'certificates_count') | ||
) | ||
|
||
return sum( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ this is great, let's see the performance on production. We can cache it if we find it slowing down the dashboard
@@ -32,6 +32,7 @@ class CourseOverview(models.Model): | |||
self_paced = models.BooleanField(default=False) | |||
course_image_url = models.TextField() | |||
visible_to_staff_only = models.BooleanField(default=False) | |||
effort = models.CharField(max_length=255) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always remember, please: mocks are our hidden enemies in tests. We need to make them similar to the original as much as we can
effort = models.CharField(max_length=255) | |
effort = models.TextField(null=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thank you!
Related issue: #67
Add learning hours stats count to the Stats API.