mirror of
https://github.com/zyeri/quizme.git
synced 2026-02-04 10:47:31 -06:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
275759d12a | ||
|
|
74bbcef9f7 |
@@ -9,5 +9,5 @@ class GenerateQuizForm(FlaskForm):
|
||||
chapters = SelectMultipleField('Select chapters for quiz to cover:', coerce=int, validators=[Required()])
|
||||
questions = IntegerField('Number of questions from each chapter:', validators=[
|
||||
Required(),
|
||||
NumberRange(min=1, message="You must have atleast 1 question!")
|
||||
NumberRange(min=1, message="You must have at least 1 question!")
|
||||
])
|
||||
|
||||
@@ -157,6 +157,13 @@ class Result(db.Model):
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
|
||||
def get_data(self):
|
||||
return self.data
|
||||
|
||||
def get_times_taken(id):
|
||||
result_data = db.session.query(Result) # need to query for data then interate over it to get num of attempts
|
||||
return 1
|
||||
|
||||
@staticmethod
|
||||
def grade(*, params=None):
|
||||
quiz_id = params['id']
|
||||
|
||||
@@ -58,25 +58,25 @@ def take(id):
|
||||
data = quiz.data
|
||||
questions = list()
|
||||
|
||||
#build the quesiton in the quiz
|
||||
# build the quesiton in the quiz
|
||||
for question in data['questions']:
|
||||
q_temp = Question.query.get(question['question_id'])
|
||||
q_blah = dict({'question': q_temp, 'question_num': question['question']}) #it's 4 am ~a
|
||||
q_blah = dict({'question': q_temp, 'question_num': question['question']}) # it's 4 am ~a
|
||||
questions.append(q_blah)
|
||||
|
||||
return render_template('quiz/take.html', questions=questions, id=id)
|
||||
|
||||
|
||||
|
||||
@quiz_blueprint.route('/results', methods=('GET', 'POST'))
|
||||
def results():
|
||||
quiz=Quiz.get_all()
|
||||
if request.method == 'POST':
|
||||
#build the results of the quiz
|
||||
# build the results of the quiz
|
||||
res_data = request.form.to_dict()
|
||||
id = res_data['id']
|
||||
del res_data['id']
|
||||
blah = list() # i'm bad at namin things, but it works
|
||||
check =list() # need this for coloration
|
||||
blah = list() # i'm bad at namin things, but it works
|
||||
check = list() # need this for coloration
|
||||
temp_itter = 1
|
||||
|
||||
for item in res_data:
|
||||
@@ -86,22 +86,22 @@ def results():
|
||||
temp_itter += 1
|
||||
blah.append(temp_dict)
|
||||
|
||||
results=dict({'id': id, 'results': blah})
|
||||
results = dict({'id': id, 'results': blah})
|
||||
|
||||
bleh = Result.grade(params=results)
|
||||
|
||||
#double check is quiz exists, because users are dumb and try to break things
|
||||
# double check is quiz exists, because users are dumb and try to break things
|
||||
quiz = Quiz.query.get(id)
|
||||
if quiz is None:
|
||||
return redirect(url_for("main.error"))
|
||||
data = quiz.data
|
||||
questions = list()
|
||||
|
||||
#build the quesiton in the quiz
|
||||
# build the quesiton in the quiz
|
||||
for question in data['questions']:
|
||||
q_temp = Question.query.get(question['question_id'])
|
||||
q_temp2 = question_schema.dump(q_temp).data
|
||||
q_blah = dict({'question': q_temp2, 'question_num': question['question']}) #it's 4 am ~a
|
||||
q_blah = dict({'question': q_temp2, 'question_num': question['question']}) # it's 4 am ~a
|
||||
questions.append(q_blah)
|
||||
|
||||
# add colors to questions......
|
||||
@@ -112,14 +112,14 @@ def results():
|
||||
q_color = ""
|
||||
correct = answer['correct']
|
||||
temp_id = str(answer['id'])
|
||||
if (correct) :
|
||||
if (correct):
|
||||
q_color = "btn-success"
|
||||
elif (temp_id in check):
|
||||
q_color = "btn-warning"
|
||||
else :
|
||||
else:
|
||||
q_color = "btn-light"
|
||||
answer['color'] = q_color
|
||||
|
||||
return render_template('quiz/results.html', results=bleh, questions=questions)
|
||||
return render_template('quiz/results.html', results=bleh, questions=questions, quiz=quiz)
|
||||
else:
|
||||
return redirect(url_for("main.error"))
|
||||
|
||||
@@ -1,11 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from flask import render_template, Blueprint
|
||||
from flask import render_template, Blueprint, flash, jsonify, url_for, redirect, request
|
||||
|
||||
from ..models import Chapter, Quiz, Question, Answer, Result
|
||||
|
||||
stats_blueprint = Blueprint('stats', __name__)
|
||||
|
||||
|
||||
@stats_blueprint.route('/<int:id>')
|
||||
def index(id):
|
||||
return render_template('stats/index.html')
|
||||
quiz = Quiz.query.get(id)
|
||||
result = Result.query.get(id)
|
||||
avg_result = 0
|
||||
if quiz is None:
|
||||
return redirect(url_for("main.error"))
|
||||
data = quiz.data
|
||||
result_all = result.get_all()
|
||||
times_taken = 0
|
||||
scores = []
|
||||
for each in result_all:
|
||||
if each.quiz_id == id:
|
||||
times_taken += 1
|
||||
percent = Result.get_data(each)['results']['precentage']
|
||||
scores.append(percent)
|
||||
avg_result += int(percent)
|
||||
|
||||
print(Result.get_data(each)['answers'])
|
||||
if times_taken > 0:
|
||||
avg_result /= times_taken
|
||||
else:
|
||||
avg_result = 0
|
||||
questions = list()
|
||||
for question in data['questions']:
|
||||
q_temp = Question.query.get(question['question_id'])
|
||||
q_blah = dict({'question': q_temp, 'question_num': question['question']})
|
||||
questions.append(q_blah)
|
||||
|
||||
return render_template('stats/index.html',
|
||||
questions=questions,
|
||||
id=id,
|
||||
result_all=result_all,
|
||||
num_times_taken=times_taken,
|
||||
avg_results=avg_result,
|
||||
scores=scores,
|
||||
quiz=quiz)
|
||||
|
||||
@@ -44,8 +44,13 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
<div class="d-flex justify-content-end">
|
||||
<a class="btn btn-info align-self-end" href="{{ url_for('quiz.take', id=quiz.id) }}" role="button">Take Quiz</a>
|
||||
<div class="d-flex justify-content-between">
|
||||
<a class="btn btn-info align-self-start" href="{{ url_for('stats.index', id=quiz.id) }}" roll="button">
|
||||
View Stats
|
||||
</a>
|
||||
<a class="btn btn-info align-self-end" href="{{ url_for('quiz.take', id=quiz.id) }}" role="button">
|
||||
Take Quiz
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer text-muted">Created: {{ quiz.created_on.humanize() }}</div>
|
||||
|
||||
@@ -1,19 +1,64 @@
|
||||
|
||||
{% extends "layouts/base.html" %}
|
||||
|
||||
{% block title %}Stats{% endblock %}
|
||||
{% block title %}Quiz {{id}} Statistics{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% include "partials/_nav.html"%}
|
||||
<script src="https://unpkg.com/frappe-charts@0.0.8/dist/frappe-charts.min.iife.js" xmlns:></script>
|
||||
<div class="container">
|
||||
<br><br>
|
||||
<div class="card text-center" >
|
||||
<div class="card text-left" >
|
||||
<div class="card-body">
|
||||
<h4 class="card-title">Quiz Statistics</h4>
|
||||
<h6 class="card-subtitle mb-2 text-muted">Just do it</h6>
|
||||
<p class="card-text">
|
||||
<!-- don't let your function be dreams -->
|
||||
List Quizzes Here!
|
||||
</p>
|
||||
{% if not num_times_taken == 0 %}
|
||||
<h4 class="card-title">Statistics for Quiz #{{id}}</h4>
|
||||
<h6 class="card-subtitle mb-2 text-muted">
|
||||
Number of Questions: {{ questions|length }}<br>
|
||||
Number of Attempts: {{ num_times_taken }}<br>
|
||||
Average Score: {{ avg_results|round(2) }}%
|
||||
</h6>
|
||||
<div class="card-text">
|
||||
<div id="chart">
|
||||
<script type="text/javascript">
|
||||
var t = 1
|
||||
var a = [];
|
||||
while(t <= {{scores|length}}){
|
||||
a.push(t++);
|
||||
}
|
||||
function showStats(){
|
||||
let data = {
|
||||
labels: a,
|
||||
datasets: [
|
||||
{
|
||||
values: {{scores}}
|
||||
}
|
||||
]
|
||||
};
|
||||
let chart = new Chart({
|
||||
parent: "#chart",
|
||||
data: data,
|
||||
type: 'line',
|
||||
height: 350,
|
||||
colors: ['blue'],
|
||||
format_tooltip_x: d => ("Attempt " + d + ''),
|
||||
format_tooltip_y: d => ("Score: " + d + '%')
|
||||
});
|
||||
}
|
||||
showStats()
|
||||
</script>
|
||||
</div>
|
||||
{# <h6 class="text-center">Attempts</h6> #}
|
||||
<div class="d-flex justify-content-end">
|
||||
<a class="btn btn-info align-self-end" href="{{ url_for('quiz.take', id=quiz.id) }}" role="button">
|
||||
Take Quiz {{id}}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="card-text">
|
||||
<h3 class="card-title text-center">There are no statistics for Quiz #{{id}}</h4>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user