Repository navigation
Enable daily metrics models backfill of historical data in platform, but not progress - #452
Conversation
This exists to help identify when we should include a course in performing backfill to `CourseDailyMetrics` for a given date in the past. Getting the `CourseEnrollment.created` value for the first enrollment provides a fast "close enough best guess" when a course was first created, as we cannot rely on CourseOverview timestamps and this avoids diving into MongoDB or the filesystem to dredge up timestamps for the given course
|
Interesting. Apparently the new test, The new code in this PR appears to cause the following to fail in multisite environments. |
This one was mildly interesting: * TestCourseDailyMetricsPipelineFunctions.test_get_num_learners_completed was failing in the multisite environemnts * The expected number of certificates was not being returned * The cert dates are based on the enrollment dates and the enrollments, created vis CourseEnrollmentFactory, were assigning whatever the increment was in the factory * This was fine until the critical extra `CourseEnrollmentFactory` calls were made in the new `test_course.py` `TestCourse.test_first_enrollment_timestamp_with_enrollments` function * Then it pushed the date over the limit So this commit sets explicit `created` values for the the enrollments in the `TestCourseDailyMetricsPipelineFunctions` test class Also, ran flake8 on this test module and removed unused inports
…igures into john/daily-metrics-backfill
This commit has new functions in `figures.pipeline.backfill`. For each function, see the details in each function's docstring Because we don't want to update courses created after the "date_for", we need to identify which courses to update. That's what the bulk of this commit's code does It uses the existing metrics loader classes to do the actual data querying and metrics model saves Add backfill dialy metrics managmenet command * Still working on getting the mgmt test to pass. Having errors in parsing the args call to `call_command`, Will pick up again to get this working tomorrow
34115a3 to
97d5346
Compare
* Removed old test code from tests/test_commands.py * Added new test class module to tests/commands/ * Fixed bug in management command
|
@OmarIthawi @melvinsoft @shadinaif @estherjsuh @bryanlandia This is ready for review |
|
@OmarIthawi @melvinsoft @shadinaif @estherjsuh @bryanlandia Following up, would someone please review? |
bryanlandia
left a comment
There was a problem hiding this comment.
I left a few comments but approving... .not the most thorough review but it all looks like it makes sense and has good test coverage 🎉
| def figures_backfill_log_dir(): | ||
| """Specify where to write Figures backfill log files | ||
| """ | ||
| return settings.ENV_TOKENS['FIGURES'].get('BACKFILL_LOG_DIR', |
There was a problem hiding this comment.
Not sure what the policy is across Figures, whether to just throw an error is there is no ENV_TOKENS['FIGURES'], but if in other places you do a .get() for those you should do so here too.
There was a problem hiding this comment.
@bryanlandia settings.ENV_TOKENS['FIGURES'] should always exist when Figures is instantiated as an Open edX plugin. Please see here: https://github.com/appsembler/figures/blob/main/figures/settings/lms_production.py#L127
What I did was create an issue to note that you raised the issue and as a place to discuss how to improve this architecture: #456
| course_ids = courses_enrolled_on_or_before(site, date_for) | ||
| course_id_count = len(course_ids) | ||
|
|
||
| with open(filepath, 'a', encoding='utf-8') as logfile: |
There was a problem hiding this comment.
why append here and not overwrite if you are starting a new backfill?
There was a problem hiding this comment.
This is a log file that has the site-id and date-for as the unique identifiers. Setting to append is a safe and simple way to make sure that we don't wipe and overwrite an existing log in the event an exception gets raised and we have to manually fix something and restart the backfill for that site and date.
A obvious improvement is to rename an exiting log to say dot some number or dot timestamp. But this is an improvement that is not essential at this time. If we find it a pain point we can improve it
| site=self.site, | ||
| date_for=date_for) | ||
|
|
||
| open_mock.assert_called_with(results['logfile'], 'a', encoding='utf-8') |
There was a problem hiding this comment.
if you did change from append to overwrite then update here too
There was a problem hiding this comment.
Good point if we did. I'll make inline comments that address your comments
|
Thanks for reviewing @bryanlandia! |
https://appsembler.atlassian.net/browse/BLACK-2375
Porting ad-hoc scripts into Figures to fill approximate metrics for historical values
There should be one more commit, modify the existing Django management command,
backfill_figures_daily_metricsand add test coverage for that commandCommit 8aeced4
Add method - figures.course.Course.first_enrollment_timestamp
This exists to help identify when we should include a course in
performing backfill to
CourseDailyMetricsfor a given date in thepast.
Getting the
CourseEnrollment.createdvalue for the first enrollmentprovides a fast "close enough best guess" when a course was first
created, as we cannot rely on CourseOverview timestamps and this avoids
diving into MongoDB or the filesystem to dredge up timestamps for the
given course
Commit 7146aa4
Commit message has the important details, but here's a brief summary:
This one fixes a latent bug in an existing test case that appeared because the test case did not explicitly set course enrollment 'created' dates for the
CourseEnrollmentFactoryinstantiations. After we added new CourseEnrollmentFactory created instances, thecreateddate got bumped past the date check.Commit 8aeced4
New functions to call backfill for a site and date and track the backfill to a log file
Commit 0fa8880
Add new test module, remove test class from old test module