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

feat: add learning hours count to the stats api #169

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

tehreem-sadat
Copy link
Collaborator

@tehreem-sadat tehreem-sadat commented Dec 20, 2024

Related issue: #67

Add learning hours stats count to the Stats API.

@tehreem-sadat tehreem-sadat force-pushed the tehreem/feat_add_learning_hours_stats_to_stats_api branch from 038f0ce to 6d56c74 Compare December 20, 2024 09:17
Copy link
Collaborator

@shadinaif shadinaif left a 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'
Copy link
Collaborator

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

Suggested change
'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'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two more tests, please

Suggested change
('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'),

Copy link
Collaborator Author

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.

Comment on lines 75 to 77
return round(total_hours, 1)
except (ValueError, IndexError):
return settings.FX_DEFAULT_COURSE_EFFORT
Copy link
Collaborator

@shadinaif shadinaif Dec 20, 2024

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

Suggested change
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
Copy link
Collaborator

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(
Copy link
Collaborator

@shadinaif shadinaif Dec 20, 2024

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)
Copy link
Collaborator

@shadinaif shadinaif Dec 20, 2024

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

Suggested change
effort = models.CharField(max_length=255)
effort = models.TextField(null=True)

Copy link
Collaborator

@shadinaif shadinaif left a 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!

@shadinaif shadinaif merged commit 1362a0b into main Dec 20, 2024
4 checks passed
@shadinaif shadinaif deleted the tehreem/feat_add_learning_hours_stats_to_stats_api branch December 20, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants