From 41a9d28234f5d561b62f44b5d32d868c510c251c Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 31 Oct 2017 16:18:51 +0500 Subject: [PATCH] Added Google Report --- AutoGrade/admin.py | 8 +- AutoGrade/reports.py | 36 +++++++ AutoGrade/reportviews.py | 17 +++- .../templates/reports/course_report.html | 93 +++++++++++++++++++ AutoGrade/templates/reports/test2.html | 69 ++++++++++++++ AutoGrade/urls.py | 1 + 6 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 AutoGrade/templates/reports/course_report.html create mode 100644 AutoGrade/templates/reports/test2.html diff --git a/AutoGrade/admin.py b/AutoGrade/admin.py index 5c04b07..1b3be6c 100644 --- a/AutoGrade/admin.py +++ b/AutoGrade/admin.py @@ -59,6 +59,12 @@ def student_stats(self, obj): student_stats.short_description = 'Student Stats' student_stats.allow_tags = True + def course_report(self, obj): + return 'Course Report' + + course_report.short_description = 'Course Report' + course_report.allow_tags = True + # This will hide object name from tabular inline. class Media: css = { "all" : ("css/hide_admin_original.css",) } @@ -69,7 +75,7 @@ def get_queryset(self, request): return qs return qs.filter(instructor__user=request.user) - list_display = ('name', 'enroll_key', 'instructor', 'student_stats') + list_display = ('name', 'enroll_key', 'instructor', 'student_stats', 'course_report') exclude = ('courses', ) @admin.register(Student) diff --git a/AutoGrade/reports.py b/AutoGrade/reports.py index 5b61e87..7703a0a 100644 --- a/AutoGrade/reports.py +++ b/AutoGrade/reports.py @@ -38,3 +38,39 @@ def get_course_student_stat(course): course_student_data.append([student, completed_assignments, late_days_remaining, average_marks, average_submissions, average_time_taken]) return course_student_data + +class CourseReport: + + def get_data_for_column_chart(self, course): + assignments = Assignment.objects.filter(course=course) + rows = [] + for assignment in assignments: + submission_count = Submission.objects.filter(assignment=assignment).count() + date = assignment.due_date.strftime('%Y-%m-%d') + rows.append([date, submission_count]) + return rows + + def get_data_for_stack_column_chart(self,course): + assignments = Assignment.objects.filter(course=course) + + rows = [] + + for assignment in assignments: + latest_submissions = assignment.get_student_and_latest_submissions() + list_of_student_score = [] + for submission, student, student_submission_count in latest_submissions: + if submission is not None: + list_of_student_score.append(submission.get_score()) + + as_str = "Assignment-" + str(assignment.id) + date = assignment.due_date.strftime('%Y-%m-%d') + minim = 0 + maxim = 0 + mean = 0 + if len(list_of_student_score) != 0: + minim = min(list_of_student_score) + maxim = max(list_of_student_score) + mean = statistics.mean(list_of_student_score) + rows.append([date, {'v':minim, 'f':str(minim)}, {'v':mean-minim, 'f':str(format(mean, '.2f'))}, {'v':maxim-mean, 'f':str(maxim)}]) + + return rows \ No newline at end of file diff --git a/AutoGrade/reportviews.py b/AutoGrade/reportviews.py index 16b3df4..a90081d 100644 --- a/AutoGrade/reportviews.py +++ b/AutoGrade/reportviews.py @@ -1,9 +1,11 @@ from django.shortcuts import render from django.contrib.admin.views.decorators import staff_member_required +from django.http import JsonResponse from django.utils import timezone +from django.core import serializers from .models import Course -from .reports import get_course_student_stat +from .reports import get_course_student_stat,CourseReport @staff_member_required def course_students_stat(request, course_id): @@ -16,3 +18,16 @@ def course_students_stat(request, course_id): 'generated_on': timezone.now() }) +@staff_member_required +def course_report(request, course_id): + course = Course.objects.get(id = course_id) + report = CourseReport() + column_chart_data = report.get_data_for_column_chart(course) + stack_column_chart_data = report.get_data_for_stack_column_chart(course) + + return render(request, 'reports/course_report.html', { + 'column_chart_data': column_chart_data, + 'stack_column_chart_data': stack_column_chart_data, + 'course': course + }) + diff --git a/AutoGrade/templates/reports/course_report.html b/AutoGrade/templates/reports/course_report.html new file mode 100644 index 0000000..201639f --- /dev/null +++ b/AutoGrade/templates/reports/course_report.html @@ -0,0 +1,93 @@ + + + + Course Report-{{course}} + + + + + + + + + + +
+
+

Course :{{ course.name }}

+
+
+
+
+
+
+
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/AutoGrade/templates/reports/test2.html b/AutoGrade/templates/reports/test2.html new file mode 100644 index 0000000..8f26041 --- /dev/null +++ b/AutoGrade/templates/reports/test2.html @@ -0,0 +1,69 @@ + + + + + + + + + + + + + +
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/AutoGrade/urls.py b/AutoGrade/urls.py index 5644396..fe50cf0 100644 --- a/AutoGrade/urls.py +++ b/AutoGrade/urls.py @@ -37,4 +37,5 @@ url(r'^loginas/(?P[0-9a-zA-Z_]+)$$', views.loginas, name='loginas'), url(r'^request_extension/$', views.request_extension), url(r'^course_students_stat/(?P[0-9a-zA-Z_]+)$', reportviews.course_students_stat, name = 'course_students_stat'), + url(r'^course_report/(?P[0-9a-zA-Z_]+)$', reportviews.course_report, name = 'course_report'), ]