IsaacKerson commited on
Commit
787493e
1 Parent(s): 149f5b0

add get ignore and updated quiz page

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. app.py +0 -1
  3. pages/quiz_new.py → old/quiz_old.py +36 -45
  4. pages/quiz.py +45 -36
.gitignore ADDED
@@ -0,0 +1 @@
 
1
+ old/
app.py CHANGED
@@ -14,7 +14,6 @@ app = MultiPage()
14
  st.markdown("# Quiz Maker")
15
 
16
  # Add all your application here
17
- app.add_page("New Quiz", quiz_new.app)
18
  app.add_page("Quiz", quiz.app)
19
  app.add_page("Upload", upload.app)
20
  app.add_page("View", view.app)
14
  st.markdown("# Quiz Maker")
15
 
16
  # Add all your application here
 
17
  app.add_page("Quiz", quiz.app)
18
  app.add_page("Upload", upload.app)
19
  app.add_page("View", view.app)
pages/quiz_new.py → old/quiz_old.py RENAMED
@@ -5,13 +5,11 @@ import random
5
  import datetime
6
 
7
  # Custom imports
8
- from pages.utils import *
9
 
10
  def app():
11
-
12
- DATABASE_NAME = 'quiz_maker.db'
13
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
14
- DATABASE = os.path.join(BASE_DIR, DATABASE_NAME)
15
 
16
  def form_callback(questions):
17
  st.session_state.form_submit = True
@@ -43,52 +41,45 @@ def app():
43
  score_val = 100 * num_correct / len(questions)
44
  st.metric(label="Final Score", value=f"{score_val}%")
45
 
46
- if "form_submit" not in st.session_state:
47
-
48
  c, conn = db_connect(DATABASE)
49
 
50
- st.markdown("# Sentence Completion")
51
- st.text_input('Comma seperated tags. (Maximum 3)', key='tags')
 
 
 
 
52
  st.selectbox('How many question do you want?', [5,10,15,20], key='num_q')
53
-
54
- tag_string = st.session_state.tags
55
  num_q = st.session_state.num_q
56
-
57
- clean_tags = clean_string(tag_string)
58
- terms = split_string(clean_tags)
59
- subquery = make_subquery(terms)
60
- query = make_query(subquery, limit = num_q)
61
 
62
- if tag_string:
63
 
64
- questions = []
65
- word_bank = []
66
 
67
- for idx, item in enumerate(c.execute(query)):
68
- word = item[0]
69
- word_bank.append(word)
70
- sentence = item[2]
71
- questions.append((idx, word, sentence, add_blanks(word, sentence)))
72
-
73
- conn.close()
74
-
75
- if len(questions) == 0:
76
- st.warning("There are no tags that matched that query.")
77
- elif len(questions) < num_q:
78
- st.warning(f"There are only {len(questions)} with that tag.")
79
- else:
80
- st.markdown(f"## QUIZ: {' '.join(terms)}")
81
- st.markdown("### Word Bank")
82
- random.shuffle(word_bank)
83
- st.table(chunker(word_bank, 5))
84
- st.markdown("### Questions")
85
- st.write("Complete the sentences with the words from the word bank.")
86
 
87
- with st.form("sentence_completion"):
88
- for q in questions:
89
- st.text_input(f'{q[0] + 1}. {q[3]}', key=q[0], placeholder="Type answer here")
90
- submitted = st.form_submit_button(label="Submit", on_click=form_callback, args=(questions,))
91
- if submitted:
92
- st.write("Submitted")
93
- del st.session_state.tags
94
- del st.session_state.num_q
 
 
 
 
5
  import datetime
6
 
7
  # Custom imports
8
+ from pages.utils import add_blanks, chunker, random_session_id, check_answer, db_connect
9
 
10
  def app():
 
 
11
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
12
+ DATABASE = os.path.join(BASE_DIR, 'vocabulary_current.db')
13
 
14
  def form_callback(questions):
15
  st.session_state.form_submit = True
41
  score_val = 100 * num_correct / len(questions)
42
  st.metric(label="Final Score", value=f"{score_val}%")
43
 
44
+ if "form_submit" not in st.session_state:
 
45
  c, conn = db_connect(DATABASE)
46
 
47
+ units_list = []
48
+ for item in c.execute("SELECT DISTINCT unit FROM vocab"):
49
+ units_list.append(item[0])
50
+
51
+ st.title("Sentence Completion")
52
+ st.selectbox('Select a unit.', units_list, key='unit')
53
  st.selectbox('How many question do you want?', [5,10,15,20], key='num_q')
54
+
55
+ unit = st.session_state.unit
56
  num_q = st.session_state.num_q
57
+ input_tup = (unit, num_q)
 
 
 
 
58
 
59
+ st.header(unit)
60
 
61
+ st.write("Complete the sentences with the words from the word bank.")
 
62
 
63
+ questions = []
64
+ word_bank = []
65
+
66
+ query = "SELECT * FROM vocab WHERE unit = ? ORDER BY RANDOM() LIMIT ?"
67
+
68
+ for idx, item in enumerate(c.execute(query, input_tup)):
69
+ word = item[2]
70
+ word_bank.append(word)
71
+ sentence = item[4]
72
+ questions.append((idx, word, sentence, add_blanks(word, sentence)))
 
 
 
 
 
 
 
 
 
73
 
74
+ st.subheader("Word Bank")
75
+ random.shuffle(word_bank)
76
+ st.table(chunker(word_bank, 5))
77
+
78
+ with st.form("sentence_completion"):
79
+ for q in questions:
80
+ st.text_input(f'{q[0] + 1}. {q[3]}', key=q[0], placeholder="Type answer here")
81
+ submitted = st.form_submit_button(label="Submit", on_click=form_callback, args=(questions,))
82
+ if submitted:
83
+ st.write("Submitted")
84
+ conn.close()
85
+
pages/quiz.py CHANGED
@@ -5,11 +5,13 @@ import random
5
  import datetime
6
 
7
  # Custom imports
8
- from pages.utils import add_blanks, chunker, random_session_id, check_answer, db_connect
9
 
10
  def app():
 
 
11
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
12
- DATABASE = os.path.join(BASE_DIR, 'vocabulary_current.db')
13
 
14
  def form_callback(questions):
15
  st.session_state.form_submit = True
@@ -41,45 +43,52 @@ def app():
41
  score_val = 100 * num_correct / len(questions)
42
  st.metric(label="Final Score", value=f"{score_val}%")
43
 
44
- if "form_submit" not in st.session_state:
45
- c, conn = db_connect(DATABASE)
46
 
47
- units_list = []
48
- for item in c.execute("SELECT DISTINCT unit FROM vocab"):
49
- units_list.append(item[0])
50
 
51
- st.title("Sentence Completion")
52
- st.selectbox('Select a unit.', units_list, key='unit')
53
  st.selectbox('How many question do you want?', [5,10,15,20], key='num_q')
54
-
55
- unit = st.session_state.unit
56
  num_q = st.session_state.num_q
57
- input_tup = (unit, num_q)
58
-
59
- st.header(unit)
60
-
61
- st.write("Complete the sentences with the words from the word bank.")
62
-
63
- questions = []
64
- word_bank = []
65
 
66
- query = "SELECT * FROM vocab WHERE unit = ? ORDER BY RANDOM() LIMIT ?"
67
 
68
- for idx, item in enumerate(c.execute(query, input_tup)):
69
- word = item[2]
70
- word_bank.append(word)
71
- sentence = item[4]
72
- questions.append((idx, word, sentence, add_blanks(word, sentence)))
73
 
74
- st.subheader("Word Bank")
75
- random.shuffle(word_bank)
76
- st.table(chunker(word_bank, 5))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- with st.form("sentence_completion"):
79
- for q in questions:
80
- st.text_input(f'{q[0] + 1}. {q[3]}', key=q[0], placeholder="Type answer here")
81
- submitted = st.form_submit_button(label="Submit", on_click=form_callback, args=(questions,))
82
- if submitted:
83
- st.write("Submitted")
84
- conn.close()
85
-
5
  import datetime
6
 
7
  # Custom imports
8
+ from pages.utils import *
9
 
10
  def app():
11
+
12
+ DATABASE_NAME = 'quiz_maker.db'
13
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
14
+ DATABASE = os.path.join(BASE_DIR, DATABASE_NAME)
15
 
16
  def form_callback(questions):
17
  st.session_state.form_submit = True
43
  score_val = 100 * num_correct / len(questions)
44
  st.metric(label="Final Score", value=f"{score_val}%")
45
 
46
+ if "form_submit" not in st.session_state:
 
47
 
48
+ c, conn = db_connect(DATABASE)
 
 
49
 
50
+ st.markdown("# Sentence Completion")
51
+ st.text_input('Comma seperated tags. (Maximum 3)', key='tags')
52
  st.selectbox('How many question do you want?', [5,10,15,20], key='num_q')
53
+
54
+ tag_string = st.session_state.tags
55
  num_q = st.session_state.num_q
56
+
57
+ clean_tags = clean_string(tag_string)
58
+ terms = split_string(clean_tags)
59
+ subquery = make_subquery(terms)
60
+ query = make_query(subquery, limit = num_q)
 
 
 
61
 
62
+ if tag_string:
63
 
64
+ questions = []
65
+ word_bank = []
 
 
 
66
 
67
+ for idx, item in enumerate(c.execute(query)):
68
+ word = item[0]
69
+ word_bank.append(word)
70
+ sentence = item[2]
71
+ questions.append((idx, word, sentence, add_blanks(word, sentence)))
72
+
73
+ conn.close()
74
+
75
+ if len(questions) == 0:
76
+ st.warning("There are no tags that matched that query.")
77
+ elif len(questions) < num_q:
78
+ st.warning(f"There are only {len(questions)} with that tag.")
79
+ else:
80
+ st.markdown(f"## QUIZ: {' '.join(terms)}")
81
+ st.markdown("### Word Bank")
82
+ random.shuffle(word_bank)
83
+ st.table(chunker(word_bank, 5))
84
+ st.markdown("### Questions")
85
+ st.write("Complete the sentences with the words from the word bank.")
86
 
87
+ with st.form("sentence_completion"):
88
+ for q in questions:
89
+ st.text_input(f'{q[0] + 1}. {q[3]}', key=q[0], placeholder="Type answer here")
90
+ submitted = st.form_submit_button(label="Submit", on_click=form_callback, args=(questions,))
91
+ if submitted:
92
+ st.write("Submitted")
93
+ del st.session_state.tags
94
+ del st.session_state.num_q