From b8541db176a5f3423e96fef512522f16d8809aff Mon Sep 17 00:00:00 2001 From: Han Su Kim Date: Mon, 5 May 2014 11:16:20 -0400 Subject: [PATCH 1/4] Renaming enrolled to active --- .../certificates/management/commands/gen_cert_report.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/certificates/management/commands/gen_cert_report.py b/lms/djangoapps/certificates/management/commands/gen_cert_report.py index 505552de29..fdf7c974c2 100644 --- a/lms/djangoapps/certificates/management/commands/gen_cert_report.py +++ b/lms/djangoapps/certificates/management/commands/gen_cert_report.py @@ -58,12 +58,13 @@ class Command(BaseCommand): for course_id in ended_courses: - # find students who are enrolled + # find students who are active + # enrolled students are always downloable + notpassing print "Looking up certificate states for {0}".format(course_id) - enrolled_students = User.objects.filter( + active_students = User.objects.filter( courseenrollment__course_id=course_id, courseenrollment__is_active=True) - cert_data[course_id] = {'enrolled': enrolled_students.count()} + cert_data[course_id] = {'active': active_students.count()} tallies = GeneratedCertificate.objects.filter( course_id__exact=course_id).values('status').annotate( From 36865b8447d3ec4b6b18963174c2a2d1cd84dd01 Mon Sep 17 00:00:00 2001 From: Han Su Kim Date: Mon, 5 May 2014 11:31:39 -0400 Subject: [PATCH 2/4] flake8 cleanup --- .../management/commands/gen_cert_report.py | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lms/djangoapps/certificates/management/commands/gen_cert_report.py b/lms/djangoapps/certificates/management/commands/gen_cert_report.py index fdf7c974c2..4cba4767ac 100644 --- a/lms/djangoapps/certificates/management/commands/gen_cert_report.py +++ b/lms/djangoapps/certificates/management/commands/gen_cert_report.py @@ -30,20 +30,20 @@ class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('-c', '--course', - metavar='COURSE_ID', - dest='course', - default=None, - help='Only generate for COURSE_ID'), + metavar='COURSE_ID', + dest='course', + default=None, + help='Only generate for COURSE_ID'), ) def _ended_courses(self): for course_id in [course # all courses in COURSE_LISTINGS - for sub in settings.COURSE_LISTINGS - for course in settings.COURSE_LISTINGS[sub]]: - course_loc = CourseDescriptor.id_to_location(course_id) - course = modulestore().get_instance(course_id, course_loc) - if course.has_ended(): - yield course_id + for sub in settings.COURSE_LISTINGS + for course in settings.COURSE_LISTINGS[sub]]: + course_loc = CourseDescriptor.id_to_location(course_id) + course = modulestore().get_instance(course_id, course_loc) + if course.has_ended(): + yield course_id def handle(self, *args, **options): @@ -62,26 +62,26 @@ class Command(BaseCommand): # enrolled students are always downloable + notpassing print "Looking up certificate states for {0}".format(course_id) active_students = User.objects.filter( - courseenrollment__course_id=course_id, - courseenrollment__is_active=True) + courseenrollment__course_id=course_id, + courseenrollment__is_active=True) cert_data[course_id] = {'active': active_students.count()} tallies = GeneratedCertificate.objects.filter( - course_id__exact=course_id).values('status').annotate( - dcount=Count('status')) + course_id__exact=course_id).values('status').annotate( + dcount=Count('status')) cert_data[course_id].update( - {status['status']: status['dcount'] - for status in tallies}) + {status['status']: status['dcount'] + for status in tallies}) # all states we have seen far all courses status_headings = set( - [status for course in cert_data - for status in cert_data[course]]) + [status for course in cert_data + for status in cert_data[course]]) # print the heading for the report print "{:>20}".format("course ID"), print ' '.join(["{:>12}".format(heading) - for heading in status_headings]) + for heading in status_headings]) # print the report for course_id in cert_data: From 4b49159205e64e1a6e0fab0852851177021fbce8 Mon Sep 17 00:00:00 2001 From: Han Su Kim Date: Mon, 5 May 2014 13:20:36 -0400 Subject: [PATCH 3/4] Adding additional fields for certificate mode --- .../management/commands/gen_cert_report.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/certificates/management/commands/gen_cert_report.py b/lms/djangoapps/certificates/management/commands/gen_cert_report.py index 4cba4767ac..b12da62831 100644 --- a/lms/djangoapps/certificates/management/commands/gen_cert_report.py +++ b/lms/djangoapps/certificates/management/commands/gen_cert_report.py @@ -64,14 +64,22 @@ class Command(BaseCommand): active_students = User.objects.filter( courseenrollment__course_id=course_id, courseenrollment__is_active=True) + cert_data[course_id] = {'active': active_students.count()} - tallies = GeneratedCertificate.objects.filter( + status_tally = GeneratedCertificate.objects.filter( course_id__exact=course_id).values('status').annotate( dcount=Count('status')) cert_data[course_id].update( {status['status']: status['dcount'] - for status in tallies}) + for status in status_tally}) + + mode_tally = GeneratedCertificate.objects.filter( + course_id__exact=course_id).values('mode').annotate( + dcount=Count('downloadable')) + cert_data[course_id].update( + {mode['mode']: mode['dcount'] + for mode in mode_tally}) # all states we have seen far all courses status_headings = set( From 8bcb70b8bf3a84d6053db59d634a8ca85eba0e2b Mon Sep 17 00:00:00 2001 From: Han Su Kim Date: Mon, 5 May 2014 13:45:07 -0400 Subject: [PATCH 4/4] Filter just downloadable certs for report --- .../certificates/management/commands/gen_cert_report.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/certificates/management/commands/gen_cert_report.py b/lms/djangoapps/certificates/management/commands/gen_cert_report.py index b12da62831..54b30ca275 100644 --- a/lms/djangoapps/certificates/management/commands/gen_cert_report.py +++ b/lms/djangoapps/certificates/management/commands/gen_cert_report.py @@ -75,8 +75,9 @@ class Command(BaseCommand): for status in status_tally}) mode_tally = GeneratedCertificate.objects.filter( - course_id__exact=course_id).values('mode').annotate( - dcount=Count('downloadable')) + course_id__exact=course_id, + status__exact='downloadable').values('mode').annotate( + dcount=Count('mode')) cert_data[course_id].update( {mode['mode']: mode['dcount'] for mode in mode_tally})