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

Added Google Report #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion AutoGrade/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<a target="_blank" href="' + reverse("home") + 'course_report/' + str(obj.id) + '">Course Report</a>'

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",) }
Expand All @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions AutoGrade/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion AutoGrade/reportviews.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
})

93 changes: 93 additions & 0 deletions AutoGrade/templates/reports/course_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<html>
<head>
<!--Load the AJAX API-->
<title>Course Report-{{course}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">

// Load the Visualization API and the corechart package.
google.charts.load('visualization', '1', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Assignment Due Date');
data.addColumn('number', 'Submissions');

data.addRows({{ column_chart_data|safe }});

// Set chart options
var lagend = {position: 'top', textStyle: {color: 'blue', fontSize: 16}}
var options = {'title':'Total Submissions of Assignment',
'width':400,
'height':300,
'bar':{groupWidth: "30%"},
'backgroundColor':'white',
'colors':['silver'],
'hAxis':{title: 'Assignment Due Date',titleTextStyle: {color: 'black'}},
'vAxis':{title: 'Number of Submissions', titleTextStyle: {color: 'black'}}
};

// Create the data table.
var data1 = new google.visualization.DataTable();
data1.addColumn('string', 'Due Date');
data1.addColumn('number', 'Min');
data1.addColumn('number', 'Average');
data1.addColumn('number', 'Max');

data1.addRows({{ stack_column_chart_data|safe }});

var options1 = {'title':'Min, Max and Average Marks of Each Assignment',
'width':400,
'height':300,
'bar':{groupWidth: "30%"},
'backgroundColor':'white',
'hAxis':{title: 'Assignment Due Date',titleTextStyle: {color: 'black'}},
'vAxis':{title: 'Marks', titleTextStyle: {color: 'black'}},
'isStacked': true,
'series': [{color:'transparent'},{color:'silver'},{color:'silver'}],
'focusTarget': 'category',
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);

var chart1 = new google.visualization.ColumnChart(document.getElementById('chart_div1'));

chart1.draw(data1, options1);
}
</script>
</head>

<body>
<!--Div that will hold the pie chart-->
<div class="container">
<div class="row">
<h2>Course :{{ course.name }} </h2>
<hr />
</div>
<br />
<div class="row text-center">
<div class="col col-sm-6">
<div id="chart_div" style="display: inline-block; margin: 0 auto;"></div>
</div>

<div class="col col-sm-6">
<div id="chart_div1" style="display: inline-block; margin: 0 auto;"></div>
</div>
</div>
</div>
</body>
</html>
69 changes: 69 additions & 0 deletions AutoGrade/templates/reports/test2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<html>
<head>
<!--Load the AJAX API-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">

// Load the Visualization API and the corechart package.
google.charts.load('current', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Assignment Due Date');
data.addColumn('number', 'min');
data.addColumn('number', 'avg');
data.addColumn('number', 'max');

data.addRows([
['A', 3, 2, 2],
['B', 2, 4, 1],
['C', 4, 1, 3],
['D', 5, 1, 1],
['E', 1, 4, 4],
]);

// Set chart options
var lagend = {position: 'top', textStyle: {color: 'blue', fontSize: 16}}
var options = {'title':'Total Submissions for Each Assignment',
'width':400,
'height':300,
'bar':{groupWidth: "30%"},
'backgroundColor':'white',
'colors':['pink'],
'hAxis':{title: 'Assignment Due Date',titleTextStyle: {color: 'black'}},
'vAxis':{title: 'Number of Submissions', titleTextStyle: {color: 'black'}},
'isStacked': true,
'series': [{color:'transparent'},{color:'silver'},{color:'silver'}],
'focusTarget': 'category',
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>

<body>
<!--Div that will hold the pie chart-->
<div class="container">
<div class="row text-center">
<div class="col col-sm-6">
<div id="chart_div" style="display: inline-block; margin: 0 auto;"></div>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions AutoGrade/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
url(r'^loginas/(?P<student_id>[0-9a-zA-Z_]+)$$', views.loginas, name='loginas'),
url(r'^request_extension/$', views.request_extension),
url(r'^course_students_stat/(?P<course_id>[0-9a-zA-Z_]+)$', reportviews.course_students_stat, name = 'course_students_stat'),
url(r'^course_report/(?P<course_id>[0-9a-zA-Z_]+)$', reportviews.course_report, name = 'course_report'),
]