Skip to content

Commit

Permalink
Added "hack" functionality to seed LearnerCourseGradeMetrics (LCGM)
Browse files Browse the repository at this point in the history
Quick hack to populate LCGM model for local development
  • Loading branch information
johnbaldwin committed Jul 6, 2020
1 parent a32602e commit 21eec6b
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion devsite/devsite/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from student.models import CourseAccessRole, CourseEnrollment, UserProfile

from figures.compat import RELEASE_LINE, GeneratedCertificate
from figures.models import CourseDailyMetrics, SiteDailyMetrics
from figures.models import (
CourseDailyMetrics,
LearnerCourseGradeMetrics,
SiteDailyMetrics,
)
from figures.helpers import as_course_key, as_datetime, days_from, prev_day
from figures.pipeline import course_daily_metrics as pipeline_cdm
from figures.pipeline import site_daily_metrics as pipeline_sdm
Expand All @@ -44,6 +48,10 @@ def get_site():
return Site.objects.first()


def today():
return datetime.datetime.utcnow().date()


def days_back_list(days_back):
end_date = prev_day(datetime.datetime.now())
start_date = days_from(end_date, abs(days_back) * -1)
Expand Down Expand Up @@ -85,6 +93,8 @@ def seed_course_overviews(data=None):
display_org_with_default=rec['org'],
number=rec['number'],
created=as_datetime(rec['created']).replace(tzinfo=utc),
start=as_datetime(rec['enrollment_start']).replace(tzinfo=utc),
end=as_datetime(rec['enrollment_end']).replace(tzinfo=utc),
enrollment_start=as_datetime(rec['enrollment_start']).replace(tzinfo=utc),
enrollment_end=as_datetime(rec['enrollment_end']).replace(tzinfo=utc),
)
Expand Down Expand Up @@ -265,13 +275,56 @@ def seed_site_daily_metrics(data=None):
date_for=dt, force_update=True)


def seed_lcgm_for_course(**_kwargs):
"""Quick hack to create a number of LCGM records
Improvement is to add a devsite model for "synthetic course policy". This
model specifies course info: points possible, sections possible, number of
learners or learer range, learner completion/progress curve
"""
date_for = _kwargs.get('date_for', datetime.datetime.utcnow().date() )
site = _kwargs.get('site', get_site())
course_id = _kwargs.get('course_id')
points_possible = _kwargs.get('points_possible', 20)
points_earned = _kwargs.get('points_earned', 10)
sections_possible = _kwargs.get('sections_possible', 10)
sections_worked = _kwargs.get('sections_worked', 5)
for ce in CourseEnrollment.objects.filter(course_id=as_course_key(course_id)):
LearnerCourseGradeMetrics.objects.update_or_create(
site=site,
user=ce.user,
course_id=str(course_id),
date_for=date_for,
defaults=dict(
points_possible=points_possible,
points_earned=points_earned,
sections_possible=sections_possible,
sections_worked=sections_worked
)
)

def seed_lcgm_all():
for co in CourseOverview.objects.all():
print('Seeding LCGM for course {}'.format(str(co.id)))
for i, date_for in enumerate(days_back_list(10)):
seed_args = dict(
date_for=date_for,
course_id=str(co.id),
points_possible=100,
points_earned=i*5,
sections_possible=20,
sections_worked=i*2,
)
seed_lcgm_for_course(**seed_args)


def wipe():
clear_non_admin_users()
CourseEnrollment.objects.all().delete()
StudentModule.objects.all().delete()
CourseOverview.objects.all().delete()
CourseDailyMetrics.objects.all().delete()
SiteDailyMetrics.objects.all().delete()
LearnerCourseGradeMetrics.all().delete()


def seed_all():
Expand Down

0 comments on commit 21eec6b

Please sign in to comment.