Fausto Busuito commited on
Commit
de7c6d8
1 Parent(s): 83297c3

Application changes

Browse files
Files changed (3) hide show
  1. app.py +10 -8
  2. templates/quiz.html +4 -24
  3. templates/results.html +1 -1
app.py CHANGED
@@ -3,7 +3,7 @@ from flask_session import Session
3
  import json
4
  import random
5
  import os
6
- import datetime
7
 
8
  app = Flask(__name__)
9
  app.secret_key = 'supersecretkey'
@@ -25,7 +25,7 @@ def start():
25
  session['answers'] = []
26
  session['score'] = 0
27
  session['current_question'] = 0
28
- session['start_time'] = datetime.datetime.now()
29
 
30
  selected_file = request.form['file']
31
  session['selected_file'] = os.path.splitext(selected_file)[0] # Remove file extension
@@ -61,16 +61,17 @@ def quiz():
61
  return redirect(url_for('results'))
62
 
63
  question = session['questions'][session['current_question']]
64
- question_text = question['question']
65
- select_multiple = 'SELECT TWO' in question_text or 'SELECT THREE' in question_text
 
66
 
67
  return render_template('quiz.html', question=question,
68
  question_number=session['current_question'] + 1,
69
  total_questions=len(session['questions']),
70
  selected_file=session['selected_file'],
71
  show_previous=session['current_question'] > 0,
72
- select_multiple=select_multiple,
73
- start_time=session['start_time'])
74
 
75
  @app.route('/results')
76
  def results():
@@ -79,11 +80,12 @@ def results():
79
 
80
  total_questions = len(session['questions'])
81
  score_percentage = (session['score'] / total_questions) * 100
82
- elapsed_time = datetime.datetime.now() - session['start_time']
 
83
 
84
  return render_template('results.html', score=session['score'],
85
  total_questions=total_questions, score_percentage=score_percentage,
86
- elapsed_time=str(elapsed_time))
87
 
88
  if __name__ == '__main__':
89
  app.run(host='0.0.0.0', port=7860)
 
3
  import json
4
  import random
5
  import os
6
+ import time
7
 
8
  app = Flask(__name__)
9
  app.secret_key = 'supersecretkey'
 
25
  session['answers'] = []
26
  session['score'] = 0
27
  session['current_question'] = 0
28
+ session['start_time'] = time.time()
29
 
30
  selected_file = request.form['file']
31
  session['selected_file'] = os.path.splitext(selected_file)[0] # Remove file extension
 
61
  return redirect(url_for('results'))
62
 
63
  question = session['questions'][session['current_question']]
64
+ multiple_selection = 'SELECT TWO' in question['question'] or 'SELECT THREE' in question['question']
65
+ elapsed_time = time.time() - session['start_time']
66
+ elapsed_time_str = time.strftime('%H:%M:%S', time.gmtime(elapsed_time))
67
 
68
  return render_template('quiz.html', question=question,
69
  question_number=session['current_question'] + 1,
70
  total_questions=len(session['questions']),
71
  selected_file=session['selected_file'],
72
  show_previous=session['current_question'] > 0,
73
+ multiple_selection=multiple_selection,
74
+ elapsed_time=elapsed_time_str)
75
 
76
  @app.route('/results')
77
  def results():
 
80
 
81
  total_questions = len(session['questions'])
82
  score_percentage = (session['score'] / total_questions) * 100
83
+ elapsed_time = time.time() - session['start_time']
84
+ elapsed_time_str = time.strftime('%H:%M:%S', time.gmtime(elapsed_time))
85
 
86
  return render_template('results.html', score=session['score'],
87
  total_questions=total_questions, score_percentage=score_percentage,
88
+ elapsed_time=elapsed_time_str)
89
 
90
  if __name__ == '__main__':
91
  app.run(host='0.0.0.0', port=7860)
templates/quiz.html CHANGED
@@ -7,11 +7,14 @@
7
  <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
8
  </head>
9
  <body>
 
 
 
10
  <h1>Question {{ question_number }} of {{ total_questions }} - {{ selected_file }}</h1>
11
  <p>{{ question.question }}</p>
12
  <form action="{{ url_for('quiz') }}" method="post">
13
  {% for option in question.options %}
14
- <input type="checkbox" id="{{ loop.index }}" name="answer" value="{{ loop.index }}" {% if not select_multiple %}required{% endif %}>
15
  <label for="{{ loop.index }}">{{ option }}</label><br>
16
  {% endfor %}
17
  <br>
@@ -21,28 +24,5 @@
21
  <button type="submit" name="action" value="next">Next</button>
22
  <button type="submit" name="action" value="end">End Session</button>
23
  </form>
24
- <div>
25
- <p>Timer: <span id="timer">00:00:00</span></p>
26
- <p>System Time: <span id="system-time">{{ start_time.strftime('%H:%M:%S') }}</span></p>
27
- </div>
28
- <script>
29
- function updateTimer() {
30
- const startTime = new Date("{{ start_time.isoformat() }}");
31
- const now = new Date();
32
- const diff = now - startTime;
33
- const hours = Math.floor(diff / 3600000);
34
- const minutes = Math.floor((diff % 3600000) / 60000);
35
- const seconds = Math.floor((diff % 60000) / 1000);
36
- document.getElementById('timer').innerText = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
37
- }
38
-
39
- function updateSystemTime() {
40
- const now = new Date();
41
- document.getElementById('system-time').innerText = now.toLocaleTimeString();
42
- }
43
-
44
- setInterval(updateTimer, 1000);
45
- setInterval(updateSystemTime, 1000);
46
- </script>
47
  </body>
48
  </html>
 
7
  <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
8
  </head>
9
  <body>
10
+ <div style="text-align: right;">
11
+ <span>Time Elapsed: {{ elapsed_time }}</span>
12
+ </div>
13
  <h1>Question {{ question_number }} of {{ total_questions }} - {{ selected_file }}</h1>
14
  <p>{{ question.question }}</p>
15
  <form action="{{ url_for('quiz') }}" method="post">
16
  {% for option in question.options %}
17
+ <input type="checkbox" id="{{ loop.index }}" name="answer" value="{{ loop.index }}" {% if not multiple_selection %}required{% endif %}>
18
  <label for="{{ loop.index }}">{{ option }}</label><br>
19
  {% endfor %}
20
  <br>
 
24
  <button type="submit" name="action" value="next">Next</button>
25
  <button type="submit" name="action" value="end">End Session</button>
26
  </form>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  </body>
28
  </html>
templates/results.html CHANGED
@@ -10,7 +10,7 @@
10
  <h1>Results</h1>
11
  <p>Your score is {{ score }} out of {{ total_questions }}.</p>
12
  <p>That's {{ score_percentage }}%.</p>
13
- <p>Time taken: {{ elapsed_time }}</p>
14
  <a href="{{ url_for('index') }}">Take another quiz</a>
15
  </body>
16
  </html>
 
10
  <h1>Results</h1>
11
  <p>Your score is {{ score }} out of {{ total_questions }}.</p>
12
  <p>That's {{ score_percentage }}%.</p>
13
+ <p>Time Elapsed: {{ elapsed_time }}</p>
14
  <a href="{{ url_for('index') }}">Take another quiz</a>
15
  </body>
16
  </html>