def get_questions(self):
return self.question_set.all().select_subclasses()
+ @property
def get_max_score(self):
return self.get_questions().count()
def get_current_score(self):
return self.current_score
+ @property
def get_percent_correct(self):
dividend = float(self.current_score)
divisor = self.quiz.question_set.all().select_subclasses().count()
<div class="container">
-{% if new_user %}
-
- <div class="alert alert-block">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <ul class="unstyled">
- <li>
- <h4>Thank you for joining this website. Welcome to your progress page.</h4>
- </li>
- </ul>
- </div>
-
-{% endif %}
-
-
-{% if cat_scores %}
-
-<h1>Question Category Scores</h1>
-<p class="lead">
- Below are the categories of questions that you have attempted. Blue is the percentage that are correct.
-</p>
-
-<script type="text/javascript" src="http://www.google.com/jsapi"></script>
-<script type="text/javascript">
- google.load('visualization', '1', {packages: ['corechart']});
-</script>
-
- {% for cat, value in cat_scores.items %}
-
- {% ifnotequal cat "empty" %}
-
- {% if forloop.first %}
- <div class="row">
- <ul class="thumbnails">
- {% endif %}
-
- {% ifequal forloop.counter 5 %}
- </ul>
- </div>
- <div class="row">
- <ul class="thumbnails">
- {% endifequal %}
-
- {% ifequal forloop.counter 9 %}
- </ul>
- </div>
- <div class="row">
- <ul class="thumbnails">
- {% endifequal %}
-
- {% ifequal forloop.counter 13 %}
- </ul>
- </div>
- <div class="row">
- <ul class="thumbnails">
- {% endifequal %}
-
- {% ifequal forloop.counter 17 %}
- </ul>
- </div>
- <div class="row">
- <ul class="thumbnails">
- {% endifequal %}
-
- <li class="span3">
- <div class="thumbnail">
- <script type="text/javascript">
- function drawVisualization() {
- // Create and populate the data table.
- var difference = {{ value.1 }} - {{ value.0 }};
- var correct = {{ value.0 }};
- var data = google.visualization.arrayToDataTable([
- ["",""],
- ['Correct', correct],
- ['Incorrect', difference]
- ]);
-
- var options = {
- legend:{position:'none'},
- title:"{{ cat }}",
- fontSize: 16
- };
-
- // Create and draw the visualization.
- new google.visualization.PieChart(document.getElementById('visualization{{ cat }}')).
- draw(data, options);
- }
-
-
- google.setOnLoadCallback(drawVisualization);
- </script>
-
- <div id="visualization{{ cat }}" ></div>
- </div>
- </li>
-
- {% endifnotequal %}
-
-
- {% endfor %}
- </ul>
- </div>
-
-{% endif %}
-
-{% if exams %}
-
-<hr>
+ {% if cat_scores %}
-<h1>Previous exam papers</h1>
-<p class="lead">
+ <h1>Question Category Scores</h1>
+
+ <table class="table table-bordered table-striped">
+
+ <thead>
+ <tr>
+ <th>Category</th>
+ <th>Correctly answererd</th>
+ <th>Incorrect</th>
+ <th>%</th>
+ </tr>
+ </thead>
+
+ <tbody>
+
+
+ {% for cat, value in cat_scores.items %}
+ <tr>
+ <td>{{ cat }}</td>
+ <td>{{ value.0 }}</td>
+ <td>{{ value.1 }}</td>
+ <td>{{ value.2 }}</td>
+ </tr>
+
+ {% endfor %}
+
+ </tbody>
+
+ </table>
+
+
+ {% endif %}
+
+ {% if exams %}
+
+ <hr>
+
+ <h1>Previous exam papers</h1>
+ <p class="lead">
Below are the results of exams that you have sat.
-</p>
+ </p>
-<table class="table table-bordered table-striped">
+ <table class="table table-bordered table-striped">
<thead>
- <tr>
- <th>Quiz Title</th>
- <th>Score</th>
- <th>Possible Score</th>
- <th>%</th>
- </tr>
- </thead>
+ <tr>
+ <th>Quiz Title</th>
+ <th>Score</th>
+ <th>Possible Score</th>
+ <th>%</th>
+ </tr>
+ </thead>
- <tbody>
+ <tbody>
- {% for exam in exams %}
+ {% for exam in exams %}
- <tr>
- {% user_previous_exam exam %}
- </tr>
+ <tr>
+ <td>{{ exam.quiz.title }}</td>
+ <td>{{ exam.current_score }}</td>
+ <td>{{ exam.quiz.get_max_score }}</td>
+ <td>{{ exam.get_percent_correct }}</td>
+ </tr>
- {% endfor %}
+ {% endfor %}
- </tbody>
+ </tbody>
-</table>
+ </table>
-{% endif %}
+ {% endif %}
</div>
+++ /dev/null
-<td>{{ title }}</td>
-<td>{{ score }}</td>
-<td>{{ possible }}</td>
-<td>{{ percent }}</td>
return {'previous': previous,
'user_was_incorrect': user_was_incorrect}
-
-
-@register.inclusion_tag('user_previous_exam.html', takes_context=True)
-def user_previous_exam(context, exam):
- """
- Provides details of finished exams
- """
- final_score = exam.current_score
- possible_score = exam.quiz.get_max_score()
- percent = int(round((float(final_score) / float(possible_score)) * 100))
- return {'title': exam.quiz.title,
- 'score': final_score,
- 'possible': possible_score,
- 'percent': percent}
self.assertEqual(self.quiz1.exam_paper, True)
def test_get_max_score(self):
- self.assertEqual(self.quiz1.get_max_score(), 1)
+ self.assertEqual(self.quiz1.get_max_score, 1)
def test_get_questions(self):
self.assertIn(self.question1, self.quiz1.get_questions())
self.sitting.add_to_score(1)
self.assertEqual(self.sitting.get_current_score(), 1)
- self.assertEqual(self.sitting.get_percent_correct(), 50)
+ self.assertEqual(self.sitting.get_percent_correct, 50)
self.sitting.add_to_score(1)
self.assertEqual(self.sitting.get_current_score(), 2)
- self.assertEqual(self.sitting.get_percent_correct(), 100)
+ self.assertEqual(self.sitting.get_percent_correct, 100)
self.sitting.add_to_score(1)
self.assertEqual(self.sitting.get_current_score(), 3)
- self.assertEqual(self.sitting.get_percent_correct(), 100)
+ self.assertEqual(self.sitting.get_percent_correct, 100)
def test_incorrect_and_complete(self):
self.assertEqual(self.sitting.get_incorrect_questions(), [])
self.assertIn('straw.berries', response.context['cat_scores'])
self.assertEqual([1, 2, 50],
response.context['cat_scores']['elderberries'])
- self.assertContains(response, 'var difference = 2 - 1;')
- self.assertContains(response, 'var correct = 1;')
def test_quiz_start_page(self):
response = self.client.get('/q/tq1/')
self.assertTemplateUsed('correct_answer.html')
self.assertIn('bing', template.render(context))
self.assertIn('incorrectly', template.render(context))
-
- def test_previous_exam(self):
- template = Template('{% load quiz_tags %}' +
- '{% user_previous_exam exam %}')
-
- context = Context({'exam': self.sitting})
-
- self.assertTemplateUsed('user_previous_exam.html')
- self.assertIn('test quiz 1', template.render(context))
- self.assertIn('<td>1</td>', template.render(context))
- self.assertIn('<td>2</td>', template.render(context))
- self.assertIn('<td>50</td>', template.render(context))
from django.views.generic import DetailView, ListView, TemplateView
from .models import Quiz, Category, Progress, Sitting, Question
-from multichoice.models import MCQuestion
class QuizListView(ListView):
def final_result_user(request, sitting, quiz, previous):
score = sitting.get_current_score()
incorrect = sitting.get_incorrect_questions()
- max_score = quiz.get_max_score()
- percent = sitting.get_percent_correct()
+ max_score = quiz.get_max_score
+ percent = sitting.get_percent_correct
sitting.mark_quiz_complete()
def final_result_anon(request, quiz, previous):
score = request.session[quiz.anon_score_id()]
- max_score = quiz.get_max_score()
+ max_score = quiz.get_max_score
percent = int(round((float(score) / max_score) * 100))
if score is 0:
score = "0"