Commit b44bf1c04f9542d88b86c26409a0c294314a2c6f
1 parent
c6d6055c
Exists in
master
and in
1 other branch
- changed the way progress bar was calculated.
- all answers are saved, right or wrong, when submitted.
Showing
2 changed files
with
30 additions
and
43 deletions
Show diff stats
knowledge.py
... | ... | @@ -68,7 +68,6 @@ class StudentKnowledge(object): |
68 | 68 | # ------------------------------------------------------------------------ |
69 | 69 | # Start a new topic. If not provided, gets a recommendation. |
70 | 70 | # questions: list of generated questions to do in the topic |
71 | - # finished_questions: [] will contain correctly answered questions | |
72 | 71 | # current_question: the current question to be presented |
73 | 72 | # ------------------------------------------------------------------------ |
74 | 73 | def init_topic(self, topic=''): |
... | ... | @@ -92,7 +91,6 @@ class StudentKnowledge(object): |
92 | 91 | |
93 | 92 | self.correct_answers = 0 |
94 | 93 | self.wrong_answers = 0 |
95 | - self.finished_questions = [] | |
96 | 94 | |
97 | 95 | size = min(self.MAX_QUESTIONS, len(questionlist)) # number of questions |
98 | 96 | questionlist = random.sample(questionlist, k=size) |
... | ... | @@ -135,14 +133,11 @@ class StudentKnowledge(object): |
135 | 133 | logger.debug('StudentKnowledge.check_answer()') |
136 | 134 | |
137 | 135 | q = self.current_question |
138 | - ref = q['ref'] | |
139 | - | |
140 | 136 | q['answer'] = answer |
141 | 137 | q['finish_time'] = datetime.now() |
142 | 138 | grade = q.correct() |
143 | - logger.debug(f'Grade = {grade:.2} ({q["ref"]})') | |
144 | 139 | |
145 | - self.finished_questions.append(q) # both correct and wrong answers | |
140 | + logger.debug(f'Grade {grade:.2} ({q["ref"]})') | |
146 | 141 | |
147 | 142 | # if answer is correct, get next question |
148 | 143 | if grade > 0.999: |
... | ... | @@ -159,9 +154,8 @@ class StudentKnowledge(object): |
159 | 154 | self.wrong_answers += 1 |
160 | 155 | factory = self.deps.node[self.current_topic]['factory'] |
161 | 156 | self.questions.append(factory[q['ref']].generate()) |
162 | - | |
163 | 157 | # returns answered and corrected question |
164 | - return ref, grade | |
158 | + return q | |
165 | 159 | |
166 | 160 | |
167 | 161 | # ======================================================================== |
... | ... | @@ -180,10 +174,6 @@ class StudentKnowledge(object): |
180 | 174 | return self.current_question |
181 | 175 | |
182 | 176 | # ------------------------------------------------------------------------ |
183 | - def get_finished_questions(self): | |
184 | - return self.finished_questions | |
185 | - | |
186 | - # ------------------------------------------------------------------------ | |
187 | 177 | def get_current_topic(self): |
188 | 178 | return self.current_topic |
189 | 179 | |
... | ... | @@ -206,7 +196,7 @@ class StudentKnowledge(object): |
206 | 196 | |
207 | 197 | # ------------------------------------------------------------------------ |
208 | 198 | def get_topic_progress(self): |
209 | - return len(self.finished_questions) / (1 + len(self.finished_questions) + len(self.questions)) | |
199 | + return self.correct_answers / (1 + self.correct_answers + len(self.questions)) | |
210 | 200 | |
211 | 201 | # ------------------------------------------------------------------------ |
212 | 202 | def get_topic_level(self, topic): | ... | ... |
learnapp.py
... | ... | @@ -106,23 +106,32 @@ class LearnApp(object): |
106 | 106 | # ------------------------------------------------------------------------ |
107 | 107 | def check_answer(self, uid, answer): |
108 | 108 | knowledge = self.online[uid]['state'] |
109 | - ref, grade = knowledge.check_answer(answer) # also moves to next question | |
110 | - logger.info(f'User "{uid}" got {grade:.2} in question "{ref}"') | |
111 | - | |
112 | - if knowledge.get_current_question() is None: | |
113 | - # finished topic, save into database | |
114 | - finished_topic = knowledge.get_current_topic() | |
115 | - level = knowledge.get_topic_level(finished_topic) | |
116 | - date = str(knowledge.get_topic_date(finished_topic)) | |
117 | - finished_questions = knowledge.get_finished_questions() | |
118 | - logger.info(f'User "{uid}" finished "{finished_topic}"') | |
119 | - | |
120 | - with self.db_session(autoflush=False) as s: | |
121 | - # save topic | |
122 | - a = s.query(StudentTopic).filter_by(student_id=uid, topic_id=finished_topic).one_or_none() | |
109 | + q = knowledge.check_answer(answer) # also moves to next question | |
110 | + logger.info(f'User "{uid}" got {q["grade"]:.2} in question "{q["ref"]}"') | |
111 | + topic = knowledge.get_current_topic() | |
112 | + | |
113 | + # always save grade of answered question | |
114 | + with self.db_session(autoflush=False) as s: | |
115 | + s.add(Answer( | |
116 | + ref=q['ref'], | |
117 | + grade=q['grade'], | |
118 | + starttime=str(q['start_time']), | |
119 | + finishtime=str(q['finish_time']), | |
120 | + student_id=uid, | |
121 | + topic_id=topic)) | |
122 | + logger.debug(f'Saved "{q["ref"]}" into database') | |
123 | + | |
124 | + if knowledge.get_current_question() is None: | |
125 | + # finished topic, save into database | |
126 | + logger.info(f'User "{uid}" finished "{topic}"') | |
127 | + level = knowledge.get_topic_level(topic) | |
128 | + date = str(knowledge.get_topic_date(topic)) | |
129 | + | |
130 | + # with self.db_session(autoflush=False) as s: | |
131 | + a = s.query(StudentTopic).filter_by(student_id=uid, topic_id=topic).one_or_none() | |
123 | 132 | if a is None: |
124 | 133 | # insert new studenttopic into database |
125 | - t = s.query(Topic).get(finished_topic) | |
134 | + t = s.query(Topic).get(topic) | |
126 | 135 | a = StudentTopic(level=level, date=date, topic=t) |
127 | 136 | u = s.query(Student).get(uid) |
128 | 137 | u.topics.append(a) |
... | ... | @@ -132,21 +141,9 @@ class LearnApp(object): |
132 | 141 | a.date = date |
133 | 142 | |
134 | 143 | s.add(a) |
135 | - logger.debug(f'Saved topic "{finished_topic}" into database') | |
136 | - | |
137 | - # save answered questions from finished_questions list | |
138 | - s.add_all([ | |
139 | - Answer( | |
140 | - ref=q['ref'], | |
141 | - grade=q['grade'], | |
142 | - starttime=str(q['start_time']), | |
143 | - finishtime=str(q['finish_time']), | |
144 | - student_id=uid, | |
145 | - topic_id=finished_topic) | |
146 | - for q in finished_questions]) | |
147 | - logger.debug(f'Saved {len(finished_questions)} answers into database') | |
148 | - | |
149 | - return grade | |
144 | + logger.debug(f'Saved topic "{topic}" into database') | |
145 | + | |
146 | + return q['grade'] | |
150 | 147 | |
151 | 148 | # ------------------------------------------------------------------------ |
152 | 149 | # Start new topic | ... | ... |