def knowledge_qid_info(user_id, week_id): """ 获取知识训练场知识点题目信息 :param user_id: :param week_id: 获取题目的week_id :return: """ grade_id = user_grade(user_id) out = Struct() questions = get_knowledge_question(week_id, grade_id) # return questions out.q_num = len(questions) out.info = questions test = db.tbkt_active.full_score_test.get(user_id=user_id, week_id=week_id, grade_id=grade_id, type=2) if not test: return out if test and test.status == 1: out.info = [] return out txt = json.loads(test.text) if test.text else [] qid = [i.get("qid") for i in txt] out.info = [i for i in out.info if i.id not in qid] return out
def get_knowledge_list(user_id, week_id): """ 获取知识训练场列表数据 :param user_id: :param week_id: :return: """ grade_id = user_grade(user_id) # 获取用户设置教材id out = Struct() out.info = [] # 视频信息列表 out.test_status = test_info(user_id, week_id, grade_id) # 测试完成状态 out.finish_status = 0 # 视频完成状态 out.q_num = 0 source = get_source(week_id, grade_id) # 获取课程资源 if not source: return out test = db.tbkt_active.full_score_test.select("text").get(user_id=user_id, week_id=week_id, grade_id=grade_id, type=1) out.finish_status = 1 if test else 0 for i, v in enumerate(source): if not test: if i == 0: status = 0 else: status = -1 else: text = test.text.split(",") if i == 0: if str(v.id) in text: status = 1 else: status = 0 else: if str(source[i - 1].id) in text: status = 0 if str(source[i].id) in text: status = 1 else: status = -1 v.status = status out.info = source out.q_num = len(out.info) return out
def test_result(user_id, week_id): """ 测试结果页 :param user_id: :param week_id: :return: """ grade_id = user_grade(user_id) question = get_knowledge_question(week_id, grade_id) out = Struct() out.info = question out.wrong_name = [] # 用户的答题记录 取出用户答案 test = db.tbkt_active.full_score_test.select("text").get(user_id=user_id, week_id=week_id, grade_id=grade_id, status=1, type=2) if not test: return out text = map(Struct, json.loads(test.text)) wrong_kids = [] test_map = {} for i in text: if i.display_type == 2: # 填空题类型 将答案格式化成数组 i.result = i.result.split(',') if i.is_right == 0: wrong_kids.append(i.kid) # {kid: 对应用户答案} test_map[i.kid] = i.result # 取出知识点视频 know_info = get_source(week_id, grade_id) know_map = {i.id: i for i in know_info} wrong_name = [] for i in out.info: k = know_map.get(i.knowledge_id) i.video_url = k.video_url i.name = k.name user_answer = test_map.get(i.knowledge_id) if i.display_type == 2: i.content = filling(i.content, user_answer, i.answer) i.user_answer = user_answer if i.knowledge_id in wrong_kids: wrong_name.append(i.name) out.wrong_name = wrong_name return out