Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,13 +6,16 @@ from get_next_question import next_question_level
|
|
| 6 |
lvl = {"easy" : 0, "medium" : 1, "hard" : 2}
|
| 7 |
idx = ["easy", "medium", "hard"]
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
# Update Ability Score
|
| 10 |
def ability(H,L,R,W):
|
| 11 |
if R == 0:
|
| 12 |
-
R
|
| 13 |
W -= 0.5
|
| 14 |
elif W == 0:
|
| 15 |
-
W
|
| 16 |
R -= 0.5
|
| 17 |
|
| 18 |
score = (H/L) + np.log(R/W)
|
|
@@ -98,10 +101,10 @@ def start_test(fileName):
|
|
| 98 |
question["Option3"], question["Option4"]])
|
| 99 |
|
| 100 |
# Submit Button
|
| 101 |
-
submit_button = st.form_submit_button("Next Question")
|
| 102 |
|
| 103 |
# End Button
|
| 104 |
-
end_test = st.form_submit_button("End Test")
|
| 105 |
|
| 106 |
if submit_button:
|
| 107 |
correct = (options == question["Correct Answer"])
|
|
@@ -113,6 +116,15 @@ def start_test(fileName):
|
|
| 113 |
# Update Score
|
| 114 |
st.session_state.score += int(response["correct"])
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
# Update Next State
|
| 117 |
st.session_state.visited_question.append(response["id"])
|
| 118 |
st.session_state.level = next_level(idx[st.session_state.level], response)
|
|
@@ -121,29 +133,58 @@ def start_test(fileName):
|
|
| 121 |
st.session_state.question = fetch_question(fileName, st.session_state.level, st.session_state.visited_question)
|
| 122 |
question = st.session_state.question
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
# Update L, H, R, W
|
| 125 |
st.session_state.L = st.session_state.question_no
|
| 126 |
st.session_state.H = st.session_state.level + 1
|
| 127 |
st.session_state.R += int(response["correct"])
|
| 128 |
st.session_state.W += int(not response["correct"])
|
| 129 |
|
| 130 |
-
#
|
| 131 |
-
st.session_state.question_no
|
| 132 |
-
|
| 133 |
-
# Re-Render the Page
|
| 134 |
-
st.experimental_rerun()
|
| 135 |
-
|
| 136 |
-
if end_test:
|
| 137 |
-
st.write("No of Questions : ", st.session_state.question_no - 1)
|
| 138 |
st.write("Ability Score : ", ability(st.session_state.H, st.session_state.L, st.session_state.R, st.session_state.W))
|
| 139 |
st.write("Correct Answers : ", st.session_state.R)
|
| 140 |
st.write("Wrong Answers : ", st.session_state.W)
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# Probability and Chart
|
| 143 |
probabilty = st.session_state.next_class.get_probabilty()
|
| 144 |
-
|
| 145 |
|
| 146 |
-
data = {"Difficulty Level" : ["Easy", "Medium", "Hard"], "Probabilty" : probabilty.values()}
|
| 147 |
chart_data = pd.DataFrame(data)
|
| 148 |
st.bar_chart(chart_data, x = "Difficulty Level", y = "Probabilty")
|
| 149 |
|
|
|
|
| 6 |
lvl = {"easy" : 0, "medium" : 1, "hard" : 2}
|
| 7 |
idx = ["easy", "medium", "hard"]
|
| 8 |
|
| 9 |
+
# Limit
|
| 10 |
+
limit = 15
|
| 11 |
+
|
| 12 |
# Update Ability Score
|
| 13 |
def ability(H,L,R,W):
|
| 14 |
if R == 0:
|
| 15 |
+
R = 0.5
|
| 16 |
W -= 0.5
|
| 17 |
elif W == 0:
|
| 18 |
+
W = 0.5
|
| 19 |
R -= 0.5
|
| 20 |
|
| 21 |
score = (H/L) + np.log(R/W)
|
|
|
|
| 101 |
question["Option3"], question["Option4"]])
|
| 102 |
|
| 103 |
# Submit Button
|
| 104 |
+
submit_button = st.form_submit_button("Next Question", disabled=(st.session_state.question_no >= limit))
|
| 105 |
|
| 106 |
# End Button
|
| 107 |
+
end_test = st.form_submit_button("End Test", disabled=(st.session_state.question_no < limit))
|
| 108 |
|
| 109 |
if submit_button:
|
| 110 |
correct = (options == question["Correct Answer"])
|
|
|
|
| 116 |
# Update Score
|
| 117 |
st.session_state.score += int(response["correct"])
|
| 118 |
|
| 119 |
+
# Update L, H, R, W
|
| 120 |
+
st.session_state.L = st.session_state.question_no
|
| 121 |
+
st.session_state.H = st.session_state.level + 1
|
| 122 |
+
st.session_state.R += int(response["correct"])
|
| 123 |
+
st.session_state.W += int(not response["correct"])
|
| 124 |
+
|
| 125 |
+
# Update Question No
|
| 126 |
+
st.session_state.question_no += 1
|
| 127 |
+
|
| 128 |
# Update Next State
|
| 129 |
st.session_state.visited_question.append(response["id"])
|
| 130 |
st.session_state.level = next_level(idx[st.session_state.level], response)
|
|
|
|
| 133 |
st.session_state.question = fetch_question(fileName, st.session_state.level, st.session_state.visited_question)
|
| 134 |
question = st.session_state.question
|
| 135 |
|
| 136 |
+
# Re-Render the Page
|
| 137 |
+
st.experimental_rerun()
|
| 138 |
+
|
| 139 |
+
if end_test:
|
| 140 |
+
correct = (options == question["Correct Answer"])
|
| 141 |
+
question["correct"] = correct
|
| 142 |
+
|
| 143 |
+
# Response -> Updated Question with Correct or Not
|
| 144 |
+
response = question
|
| 145 |
+
|
| 146 |
+
# Update Score
|
| 147 |
+
st.session_state.score += int(response["correct"])
|
| 148 |
+
|
| 149 |
# Update L, H, R, W
|
| 150 |
st.session_state.L = st.session_state.question_no
|
| 151 |
st.session_state.H = st.session_state.level + 1
|
| 152 |
st.session_state.R += int(response["correct"])
|
| 153 |
st.session_state.W += int(not response["correct"])
|
| 154 |
|
| 155 |
+
# Display Values
|
| 156 |
+
st.write("No of Questions : ", st.session_state.question_no)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
st.write("Ability Score : ", ability(st.session_state.H, st.session_state.L, st.session_state.R, st.session_state.W))
|
| 158 |
st.write("Correct Answers : ", st.session_state.R)
|
| 159 |
st.write("Wrong Answers : ", st.session_state.W)
|
| 160 |
|
| 161 |
+
# Reset Values
|
| 162 |
+
st.session_state.next_class = next_question_level({'easy':50,'medium':30, 'hard':20})
|
| 163 |
+
st.session_state.probability = st.session_state.next_class.get_probabilty
|
| 164 |
+
st.session_state.score = 0
|
| 165 |
+
st.session_state.level = lvl[st.session_state.next_class.level()]
|
| 166 |
+
st.session_state.visited_question = []
|
| 167 |
+
st.session_state.question_no = 1
|
| 168 |
+
st.session_state.H = 0
|
| 169 |
+
st.session_state.L = 0
|
| 170 |
+
st.session_state.R = 0
|
| 171 |
+
st.session_state.W = 0
|
| 172 |
+
st.session_state.question = fetch_question(fileName, st.session_state.level, st.session_state.visited_question)
|
| 173 |
+
|
| 174 |
+
# Re-Test Button
|
| 175 |
+
re_test = st.button("Re Test")
|
| 176 |
+
|
| 177 |
+
if re_test:
|
| 178 |
+
st.session_state.clicked = False
|
| 179 |
+
|
| 180 |
+
# Re-Render the Page
|
| 181 |
+
st.experimental_rerun()
|
| 182 |
+
|
| 183 |
# Probability and Chart
|
| 184 |
probabilty = st.session_state.next_class.get_probabilty()
|
| 185 |
+
st.write(probabilty)
|
| 186 |
|
| 187 |
+
data = {"Difficulty Level" : ["1 - Easy", "2 - Medium", "3 - Hard"], "Probabilty" : probabilty.values()}
|
| 188 |
chart_data = pd.DataFrame(data)
|
| 189 |
st.bar_chart(chart_data, x = "Difficulty Level", y = "Probabilty")
|
| 190 |
|