Commit d9bcc517 authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

added comments

parent 9c23260a
...@@ -41,6 +41,8 @@ from django.core.files.storage import default_storage ...@@ -41,6 +41,8 @@ from django.core.files.storage import default_storage
startedquiz = dict() startedquiz = dict()
def index(request): def index(request):
""" This function is responsible for for rendering the quiz page to the student for the selected quiz by the student
"""
quiz_id = int(request.GET['q']) quiz_id = int(request.GET['q'])
quizInstance = quiz.objects.get(pk=quiz_id) quizInstance = quiz.objects.get(pk=quiz_id)
obj = Questions.objects.filter(quizId=quizInstance).all().order_by('questionId') obj = Questions.objects.filter(quizId=quizInstance).all().order_by('questionId')
...@@ -51,6 +53,8 @@ def index(request): ...@@ -51,6 +53,8 @@ def index(request):
@login_required @login_required
def result(request): def result(request):
"""This function is called on submission of quiz to calculate the marks og the student the marks are added to total score for
every correct answer and for every wronf answer the negative marks set by instructor are deducted"""
if request.user.is_authenticated and request.method =="POST": if request.user.is_authenticated and request.method =="POST":
quizId=int(request.POST['quizId']) quizId=int(request.POST['quizId'])
quizInstance = quiz.objects.get(pk=quizId) quizInstance = quiz.objects.get(pk=quizId)
...@@ -78,6 +82,10 @@ def result(request): ...@@ -78,6 +82,10 @@ def result(request):
def save_ans(request): def save_ans(request):
"""
this function keeps saving the response of the quiz while the student is attempting in order to ensure if due to network failure
student quiz stops then he can continue later from the point where he was interrupted
"""
ans = request.GET['ans'] ans = request.GET['ans']
quizId=request.GET['quizId'] quizId=request.GET['quizId']
questionId=request.GET['questionId'] questionId=request.GET['questionId']
...@@ -87,6 +95,7 @@ def save_ans(request): ...@@ -87,6 +95,7 @@ def save_ans(request):
return HttpResponse('') return HttpResponse('')
def save_cribs(request): def save_cribs(request):
"""This function saves the cribs that the student has raised"""
crib=request.GET.get('cribs') crib=request.GET.get('cribs')
quizId=int(request.GET.get('quiz')) quizId=int(request.GET.get('quiz'))
quizInstance = quiz.objects.get(pk=quizId) quizInstance = quiz.objects.get(pk=quizId)
...@@ -97,10 +106,12 @@ def save_cribs(request): ...@@ -97,10 +106,12 @@ def save_cribs(request):
return HttpResponse('Suuuuuccess') return HttpResponse('Suuuuuccess')
def upload(request): def upload(request):
"""This function Renders the upload page for instructor to upload quiz through csv"""
return render(request,'upload.html') return render(request,'upload.html')
@login_required @login_required
def student(request): def student(request):
"""This function depending on the role of the logged in user load the professor dasboard or student dashboard"""
role = Permission.objects.all().filter(userId=request.user).values('role') role = Permission.objects.all().filter(userId=request.user).values('role')
if role: if role:
role = role[0]['role'] role = role[0]['role']
...@@ -112,6 +123,7 @@ def student(request): ...@@ -112,6 +123,7 @@ def student(request):
return render(request,'student.html') return render(request,'student.html')
def ongoing_quiz(request): def ongoing_quiz(request):
"""Displays all ongoing quiz to the professor who has hosted the quiz"""
quizzes = quiz.objects.all().values('quizId', 'quizCode') quizzes = quiz.objects.all().values('quizId', 'quizCode')
quizId = list() quizId = list()
quizCode = list() quizCode = list()
...@@ -120,6 +132,7 @@ def ongoing_quiz(request): ...@@ -120,6 +132,7 @@ def ongoing_quiz(request):
return render(request, 'ongoing_quiz.html', {'quizId': quizId}) return render(request, 'ongoing_quiz.html', {'quizId': quizId})
def upload_file(request): def upload_file(request):
""" This function reads the csv file and inserts the questions into the database """
uploaded=False uploaded=False
temp1='test' temp1='test'
random_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 6)) random_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k = 6))
...@@ -137,6 +150,7 @@ def upload_file(request): ...@@ -137,6 +150,7 @@ def upload_file(request):
def instructor(request): def instructor(request):
"""This function is used to display the instructor with graphs(bell curve and histogram) , cribs raised by the students of the quiz selected"""
q_id = request.GET.get('quiz_id') q_id = request.GET.get('quiz_id')
quizId = 0 quizId = 0
allquizs = quiz.objects.all().filter(quizInstructor=request.user).order_by('-date', '-startTime') allquizs = quiz.objects.all().filter(quizInstructor=request.user).order_by('-date', '-startTime')
...@@ -191,10 +205,12 @@ def instructor(request): ...@@ -191,10 +205,12 @@ def instructor(request):
return render(request, 'instructor.html',{"graph": html_graph, "graph1": html_graph, "graph2": html_graph1,'quiz':quizInstance,'cribs':cribs, 'all_quizes': allquizs, 'quizDone':quizDone}) return render(request, 'instructor.html',{"graph": html_graph, "graph1": html_graph, "graph2": html_graph1,'quiz':quizInstance,'cribs':cribs, 'all_quizes': allquizs, 'quizDone':quizDone})
def quizTable(request): def quizTable(request):
"""This function helps in rendering all the quiz hosted by the instructor"""
quizs = quiz.objects.filter(quizInstructor=request.user).all() quizs = quiz.objects.filter(quizInstructor=request.user).all()
return render(request,'quizTable.html',{'quiz':quizs}) return render(request,'quizTable.html',{'quiz':quizs})
def handle_uploaded_file(f,q1): def handle_uploaded_file(f,q1):
"""This function reads the csv file uploaded by the instructor and makes insert into the database"""
with open('name.csv', 'wb+') as destination: with open('name.csv', 'wb+') as destination:
for chunk in f.chunks(): for chunk in f.chunks():
destination.write(chunk) destination.write(chunk)
...@@ -211,6 +227,7 @@ def create_quiz(request): ...@@ -211,6 +227,7 @@ def create_quiz(request):
#login functionality #login functionality
def sign_up(request): def sign_up(request):
"""This function renders the sign up page for the users"""
context = {} context = {}
form = UserCreationForm(request.POST or None) form = UserCreationForm(request.POST or None)
if request.method == "POST": if request.method == "POST":
...@@ -225,6 +242,7 @@ def sign_up(request): ...@@ -225,6 +242,7 @@ def sign_up(request):
@login_required @login_required
def submissions(request): def submissions(request):
""" This function helps in rendering the submission page showing the student all the previous attempted quizzes"""
#prev_subm = submission.objects.all().filter(studentId=request.user) #prev_subm = submission.objects.all().filter(studentId=request.user)
prev_subm = submission.objects.all().filter(studentId=request.user).values('quizId').annotate(dcount=Count('quizId')) prev_subm = submission.objects.all().filter(studentId=request.user).values('quizId').annotate(dcount=Count('quizId'))
return render(request,'submissions.html', { 'submissions' : prev_subm }) return render(request,'submissions.html', { 'submissions' : prev_subm })
...@@ -232,6 +250,8 @@ def submissions(request): ...@@ -232,6 +250,8 @@ def submissions(request):
@login_required @login_required
def view_sub(request): def view_sub(request):
"""This function gives details to the student about the completed quiz consisting of correct answers
and choosen answers also the explainations for the questions provided by the professor"""
if request.method == "GET": if request.method == "GET":
quizId = int(request.GET.get('q')) quizId = int(request.GET.get('q'))
quizInstance = quiz.objects.get(pk=quizId) quizInstance = quiz.objects.get(pk=quizId)
...@@ -249,6 +269,7 @@ def view_sub(request): ...@@ -249,6 +269,7 @@ def view_sub(request):
def add_quiz(request): def add_quiz(request):
"""This function makes insert into database for all the manually entered quiz questions"""
vals=list() vals=list()
for req in request.POST.values(): for req in request.POST.values():
vals.append(req) vals.append(req)
...@@ -276,6 +297,9 @@ def add_quiz(request): ...@@ -276,6 +297,9 @@ def add_quiz(request):
return render(request,'professor.html',{'quiz_upload':True})#(request,'success') return render(request,'professor.html',{'quiz_upload':True})#(request,'success')
def monitor(request): def monitor(request):
"""
Thid function renders the monitor page for the instructor to view ongoing quiz , and monitor the student activity
"""
q_id = request.GET.get('quiz') q_id = request.GET.get('quiz')
allquizs = quiz.objects.all().filter(quizInstructor=request.user).order_by('-date', '-startTime') allquizs = quiz.objects.all().filter(quizInstructor=request.user).order_by('-date', '-startTime')
...@@ -292,17 +316,20 @@ def monitor(request): ...@@ -292,17 +316,20 @@ def monitor(request):
@xframe_options_exempt @xframe_options_exempt
def getbeat(request): def getbeat(request):
"""This function track the student activity for displaying the same on the instructor monitor page"""
quizId = int(request.GET.get('quiz')) quizId = int(request.GET.get('quiz'))
test = startedquiz.get(quizId) test = startedquiz.get(quizId)
return render(request,'student_activity.html', {'activity': test }) return render(request,'student_activity.html', {'activity': test })
def view_logs(request): def view_logs(request):
"""THus function helps in viewing all the quizzes logs"""
quizId = int(request.GET.get('quiz')) quizId = int(request.GET.get('quiz'))
quizInstance = quiz.objects.get(pk=quizId) quizInstance = quiz.objects.get(pk=quizId)
quiz_logs = log.objects.all().filter(quizId=quizInstance) quiz_logs = log.objects.all().filter(quizId=quizInstance)
return render(request,'log.html', {'logs': quiz_logs }) return render(request,'log.html', {'logs': quiz_logs })
def heartbeat(request): def heartbeat(request):
"""This function keeps track of student whether he exited full screen and which question he is currently on"""
quizId = int(request.GET.get('quiz')) quizId = int(request.GET.get('quiz'))
quizInstance = quiz.objects.get(pk=quizId) quizInstance = quiz.objects.get(pk=quizId)
if quizId in startedquiz: if quizId in startedquiz:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment