def yw_book_list(grade_id): """ 语文教材列表--北师,人教,苏教 :param subject_id: :param grade_id: :return: """ grade_num = "NJ00100" + str(grade_id) sql = ''' SELECT b.dict_Name,a.ct_SeesawVolumes,a.ct_ID,b.dict_ID,a.version from yw_chinesetextbooks a INNER JOIN yw_dictionary b ON b.dict_Code = a.ct_VersionNum where b.dict_ID in(2,3,4) AND a.ct_Status = 0 AND a.enable_flag = 0 and a.ct_Grade="%s"; ''' % grade_num data_grade = db.tbkt_yw_slave.fetchall_dict(sql) for i in data_grade: i.volume_name = {1: u'上册', 2: u'下册', 3: u'全册'}.get(i.ct_SeesawVolumes, u'') i.press_name = i.dict_Name i.subject_id = 51 i.grade_id = grade_id i.grade_name = num_to_ch(grade_id) + u"年级" i.name = i.grade_name + i.volume_name i.id = i.ct_ID del i.dict_Name del i.ct_SeesawVolumes del i.ct_ID return data_grade
def get_grade_cn(grade_id): """ 返回年级中文名 :param grade_id: :return: """ g_map = {i: u'%s年级%%%%' % num_to_ch(i) for i in range(1, 10)} return g_map.get(grade_id)
def get_list(): """ 获取教材列表 :return: """ grade = range(1, 7) out = [] for i in grade: d = dict(id=i, name=u'数学-人教版%s年级下册' % num_to_ch(i)) out.append(d) return out
def p_booklist(subject_id, type, grade_id, book_id=0): """ :param subject_id: 学科 :param type:1教材 2教辅 :param grade_id:年级ID :param book_id:设置教材要对应年级 :return:[{id:BOOKID, name:书名, press_name:出版社, version:版本, volume:上下册}] """ # 数学英语列表返回 if subject_id in (21, 91): book_all = get_gradelist(subject_id, type, grade_id, book_id) books = [] for b in book_all: if str(b.grade_id) in grade_id: books.append(b) return books # 资源不统一 语文单独查询 if subject_id == 51: sql = """ select b.dict_Name,a.ct_SeesawVolumes,a.ct_ID,a.ct_Grade,b.dict_ID from yw_chinesetextbooks a inner join yw_dictionary b ON b.dict_Code = a.ct_VersionNum where b.dict_ID = 2 and a.ct_SeesawVolumes = 2 and a.ct_Status = 0 AND a.enable_flag = 0 or a.ct_ID = 65; """ # 查询本次活动指定教材信息 book_info = db.tbkt_yw_slave.fetchall_dict(sql) books = [] for b in book_info: if b.ct_Grade[-1] in grade_id: books.append(b) if not books: return for i in books: i.press_id = i.dict_ID # 出版社id i.volume_name = { 1: u'上册', 2: u'下册', 3: u'全册' }.get(i.ct_SeesawVolumes, u'') # 上下册 i.press_name = u"人教版" # 出版社名称 i.subject_id = 51 i.grade_id = int(i.ct_Grade[-1]) i.grade_name = num_to_ch(i.grade_id) + u"年级" i.name = i.grade_name + i.volume_name i.id = i.ct_ID i.book_type = 1 del i.dict_Name del i.ct_SeesawVolumes del i.ct_ID del i.ct_Grade del i.dict_ID return books
def get_user_book_name(user): """ 获取用户教材 :param user: :return: """ grade_id = user.grade_id book = db.tbkt_active.full_score_book_set.get(user_id=user.id) if book: grade_id = book.grade_id if grade_id <= 0: grade_id = 1 return u'数学-人教版%s年级下册' % num_to_ch(grade_id)
def paper_list(user_id, subject_id): """ 活动试卷列表 :param user_id: 年级_id :param subject_id: 二位学科id :return: """ if subject_id != 21: return # 用户已设置教材信息 book = db.default.user_book.get(user_id=user_id, is_work_book=0, subject_id=subject_id) if not book: return book_id = book.book_id book = db.ziyuan_slave.zy_book.get(id=book_id) if book.volume != 1: return grade_name = get_grade_cn(book.grade_id) press_id = get_press(book.press_id) active_id = 48 sql = """ select t.id from (select p.id, p.name, c.name grade_name, (select c1.id from tbkt_a_active_catalog c1 where c1.id= c.parent_id) press_id from sx_paper p, sx_paper_relate r, tbkt_a_active_catalog c where p.id = r.paper_id and c.id = r.object_id and c.active_id = %s and r.status = 1) t where t.grade_name like '%s' and press_id like '%s' """ % (active_id, grade_name, press_id) print sql rows = db.ziyuan_slave.fetchall_dict(sql) if not rows: return # 获取试卷id集合 object_ids = [i.id for i in rows] # 查询已发试卷 task = db.tbkt_shuxue.sx_task.filter(add_user=user_id, type=101, status__gt=0, object_id__in=object_ids) # {试卷id:1} task_map = {i.object_id: 1 for i in task} for i, v in enumerate(rows): v.status = task_map.get(v.id, 0) v.name = "期末提分试卷(%s)" % (num_to_ch(i+1)) return rows
def p_yw_user_book(user_id): """ 获取语文教材信息 :param user_id: :return: """ # 获取用户设置的期末活动教材 book = db.tbkt_active.mid_term_user_book.select('book_id').get( user_id=user_id, is_work_book=0, subject_id=51) if book: book_id = book.book_id else: # 获取用户设置教材 _book = db.default.user_book.select('book_id').get(user_id=user_id, is_work_book=0, subject_id=51) if not _book: return {} data = db.tbkt_yw.yw_chinesetextbooks.select("ct_ID").filter( ct_VersionNum__in=("JC001001", "JC001008"), ct_status=0, enable_flag=0).flat("ct_ID")[:] if _book.book_id in data: # 说明用户设置的是人教版 则直接进行保存 db.tbkt_active.mid_term_user_book.create(book_id=_book.book_id, subject_id=51, user_id=user_id, add_time=int(time.time()), is_work_book=0) book_id = _book.book_id else: return {} sql = """ SELECT b.dict_Name name,a.ct_SeesawVolumes volumes,a.ct_Grade grade from yw_chinesetextbooks a INNER JOIN yw_dictionary b ON b.dict_Code = a.ct_VersionNum where a.ct_ID = %s AND a.ct_Status = 0 AND a.enable_flag = 0; """ % book_id info = db.tbkt_yw_slave.fetchone_dict(sql) if not info: return {} out = Struct() out.id = book_id grade = num_to_ch(info.grade.replace("NJ00100", "")) + u'年级' volume = {1: u'上册', 2: u'下册', 3: u'全册'}.get(info.volumes, u'') out.name = u"人教版" + grade + volume out.grade_id = info.grade[-1] return out
def get_gradelist(subject_id, type, grade_id, book_id=0): """ 选年级教材列表 --------------------- 王晨光 2017-1-4 --------------------- :param subject_id: 学科ID :param type: 1教材 2教辅 :param grade_id: 年级ID :param book_id: 设置教材要对应年级 :return: [{id:BOOKID, name:书名, press_name:出版社, version:版本, volume:上下册}] """ if type == 1: order_by = "order by press_name,p.id, volume" else: order_by = "order by name,press_name, volume" book_related = '' if type == 2 and subject_id in (21, 22) and book_id: book_related = 'and b.book_id =%s' % book_id if subject_id in(21, 91): version_str = 'and p.id in (2,8,4) ' else: version_str = '' # and p.id in (2,4,8) 代表教材属于人教 北师大 苏教 sql = """ select b.id, b.name, b.subject_id, b.grade_id, p.name press_name, p.id press_id, v.name version_name, b.volume, b.book_type from zy_book b inner join zy_press p on p.id=b.press_id inner join zy_press_version v on v.id=b.version_id where b.subject_id=%s and b.grade_id=%s and b.book_type=%s and b.is_active=1 %s %s %s """ % (subject_id, grade_id, type, book_related, version_str, order_by) print sql books = db.ziyuan_slave.fetchall_dict(sql) for b in books: b.volume_name = {1: u'上册', 2: u'下册', 3: u'全册'}.get(b.volume, u'') b.grade_name = num_to_ch(b.grade_id) + u'年级' if b.book_type == 1: b.name = b.grade_name + b.volume_name if subject_id == 51: return yw_book_list(grade_id) return books
def sx_paper_list(user, subject_id): """ 数学试卷列表 :return: """ book_info = p_user_book(user.id, subject_id) if not book_info: return [] book_id = book_info.id book = db.ziyuan_slave.zy_book.get(id=book_id) grade_name = get_grade_cn(book.grade_id) press_id = get_press(book.press_id) # ziyuan_new 表 中 tbkt_a_active_catalog 活动教材信息 active_id = 50 sql = """ select t.id from (select p.id, p.name, c.name grade_name, (select c1.id from tbkt_a_active_catalog c1 where c1.id= c.parent_id) press_id from sx_paper p, sx_paper_relate r, tbkt_a_active_catalog c where p.id = r.paper_id and c.id = r.object_id and c.active_id = %s and r.status = 1) t where t.grade_name like '%s' and press_id like '%s' """ % (active_id, grade_name, press_id) rows = db.ziyuan_slave.fetchall_dict(sql) if not rows: return [] # 查询已发试卷 sql = """ select yt.object_id paper_id, ytc.unit_class_id unit_id from sx_task yt join sx_task_class ytc on yt.id = ytc.task_id where ytc.status > 0 and yt.add_user = %s and yt.type = 103 and ytc.unit_class_id in (%s) """ % (user.id, ",".join(str(i.id) for i in user.units)) pub_papers = db.tbkt_shuxue.fetchall_dict(sql) paper_map = defaultdict(list) for i in pub_papers: paper_map[i.paper_id].append(i.unit_id) # 查询指定教材下的试卷id for i, v in enumerate(rows): done_unit = len(paper_map.get(v.id, [])) v.status = 1 if done_unit >= len(user.units) else 0 v.name = "期末提分试卷--(%s)" % num_to_ch(i + 1) return rows
def _get_question(question_ids): """ get question :param question_ids: :return: """ if not isinstance(question_ids, (list, tuple)): return [] questions = db.tbkt_yw.yw_question.select( "content", "video", "image", "type", "show_parse", "category", "id", "article_text").filter(id__in=question_ids)[:] if not questions: return [] out = [] ask_map = get_ask(question_ids) for k, i in enumerate(questions): d = Struct() d.article_title = "" d.article_text = "" d.content = "" if i.type == 8: # 阅读理解 d.article_title = format_content(i.content) d.article_text = i.article_text else: # 不是阅读理解 d.content = i.content d.video = get_absurl(i.video).replace("//", "/") d.image = get_absurl(i.image).replace("//", "/") d.type = i.type d.category = i.category d.no = num_to_ch(k + 1) d.num = k + 1 d.asks = ask_map.get(i.id, []) d.id = i.id out.append(d) return out
def get_paper_number(paper_id): """ 根据试卷ID返回 题目标题 :param paper_id: 试卷ID :return: {ask_id:{'q_num': 大题号, 'a_num': 小题号}} """ paper_type = db.ziyuan_slave.sx2_paper_question_number.select( "object_id").filter(paper_id=paper_id, type=1).flat("object_id")[:] sql = """ select a.id ask_id, a.question_id, d.paper_type_id from sx2_paper_question_number n inner join sx2_paper_detail d on n.paper_id = %s and n.paper_id = d.paper_id and n.type = 2 and n.object_id = d.question_id inner join sx2_question_ask a on a.question_id = d.question_id """ % paper_id papers = db.ziyuan_slave.fetchall_dict(sql) if not papers: return {} out = {} n = 0 # 初始化小题号 for k, p in enumerate(paper_type): q_num = num_to_ch(k + 1) for a in papers: if a.paper_type_id == p: r = len([i for i in papers if i.paper_type_id == p]) n += 1 # 题号 (1) a_num = u"(%s)" % n # if r > 1 else '' out[int(a.ask_id)] = Struct(q_num=q_num, a_num=a_num) # 题目ID else: # 重新赋值 避免返回整张试卷问题 n = 0 return out
def get_question_by_type(object_id, paper_id, scan_type): """ 根据试卷题目类型 返回题目信息 :param scan_type: 扫描类型 1:整张试卷 2:题目类型 3:题目ID :param object_id: 1:paper_id, 2:paper_type_id(试卷类型ID), 3:question_id(题目ID) :param paper_id: 试卷ID :return: """ sql = """ select a.id ask_id, a.question_id, d.paper_type_id from sx2_paper_question_number n inner join sx2_paper_detail d on n.paper_id = %s and n.paper_id = d.paper_id and n.type = 2 and n.object_id = d.question_id inner join sx2_question_ask a on a.question_id = d.question_id """ % paper_id rows = db.ziyuan_slave.fetchall_dict(sql) if not rows: return # 试卷题目类型去重 paper_type = db.ziyuan_slave.sx2_paper_question_number.select( "object_id").filter(paper_id=paper_id, type=1).flat("object_id")[:] if scan_type == 2: # 按试卷题目类型查询 ask_ids = [i for i in rows if i.paper_type_id == object_id] elif scan_type == 3: # 按照题目ID查询 ask_ids = [i for i in rows if i.question_id == object_id] else: ask_ids = [i for i in rows] print ask_ids # 获取举一反三试题详情 out = Struct() out.title = get_paper_title(paper_id) out.paper_id = paper_id out.list = [] paper_number = get_paper_number(paper_id) n = 0 # 初始化小题号 for k, p in enumerate(paper_type): ask_info = Struct() ask_info.q_num = num_to_ch(k + 1) ask_info.paper_type_id = p asks = [] for a in ask_ids: if a.paper_type_id == p: n += 1 info = Struct() # 题号 (1) info.num = paper_number.get(a.ask_id, Struct()).a_num or "" # 题目ID info.aid = a.ask_id asks.append(info) else: # 重新赋值 避免返回整张试卷问题 n = 0 ask_info.asks = asks out.list.append(ask_info) out.list = [i for i in out.list if i.asks] return out
def r_check_task(request): """ @api {post} /huodong/terminal/yw/check/task/info [期末提分试卷]语文检查作业 @apiGroup terminal @apiParamExample {json} 请求示例 { "task_id": 作业id, "unit_id": 班级id } @apiSuccessExample {json} 成功返回 { "message": "", "next": "", "data": { "is_end": 1, # 是否已截止 "task_date": "05-16 9:00(星期三)" # 作业时间 "finish_num": 0 # 完成人数 "unfinish_num": 0 # 未完成人数 "list":[ { "user_name": "张三", # 学生姓名 "status": 0, # 1 完成 2 未完成 "score": 0, # 用户成绩 "is_after": 1/0, # 1补交 0不是 "test_id": 0 # 测试id "date": "作业完成时间" }, ... ], "wrong_info": [ { "no": 题号 "rate": 错误率 "ask_id": 小题id }, ] }, "response": "ok", "error": "" } * list 班级学生完成情况 wrong_info 错题率 已排序 """ args = request.QUERY.casts(task_id=int, unit_id=int) task_id = args.task_id unit_id = args.unit_id if not task_id: return ajax.jsonp_fail(request, message="缺少作业id") if not unit_id: return ajax.jsonp_fail(request, message="缺少班级id") update_check_status(task_id, unit_id) sql = """ select t.end_time, d.question_id, t.object_id from yw_task_new t, yw_task_detail_new d where t.id = %s and t.id = d.task_id """ % task_id task = db.tbkt_yuwen.fetchone_dict(sql) out = Struct() out.is_end = 0 if not task: return ajax.jsonp_ok(request, out) now = int(time.time()) if task.end_time < now: out.is_end = 1 out.task_date = format_stamp(task.test_time) + u"(星期%s)" % num_to_ch( time.localtime(task.test_time).tm_wday + 1) stu_map = dict() r = Hub(request).com.post("/class/students", dict(unit_id=unit_id)) if r and r.response == "ok": stus = map(Struct, r.data["students"]) stu_map = {i.user_id: i for i in stus} stu_test = db.tbkt_yuwen.yw_test_new.filter(task_id=task_id, user_id__in=stu_map.keys(), status=1)[:] stu_score = db.tbkt_yuwen.yw_test_detail_new.filter( task_id=task_id, user_id__in=stu_map.keys(), status=1)[:] score_map = {s.user_id: s.score for s in stu_score} test_map = {i.user_id: i for i in stu_test} out.finish_num = 0 out.unfinish_num = 0 out.paper_id = task.object_id out.list = [] for user_id, info in stu_map.iteritems(): d = Struct() d.user_id = info.user_id # 学生id d.user_name = info.user_name # 学生姓名 d.status = 0 # 是否完成 d.score = 0 # 成绩 d.is_after = 0 # 是否补交 d.date = "" # 完成时间 d.test_time = 0 # 完成时间戳(排序使用) d.test_id = 0 test = test_map.get(user_id) if not test: out.unfinish_num += 1 else: out.finish_num += 1 if test.test_time > task.end_time: d.is_after = 1 d.score = score_map.get(user_id) d.status = 1 d.date = format_stamp(test.test_time) d.test_time = test.test_time d.test_id = test.id out.list.append(d) out.list.sort(key=lambda x: (-x.score, x.test_time)) out.wrong_info = check_wrong_info(task_id, stu_map.keys(), task.question_id.split(",")) return ajax.jsonp_ok(request, out)