def get_read_result(user_id, task_detail): """返回单词普通作业结果""" cache_data = cache.yy_study_result.get((user_id, task_detail.id)) if cache_data: study = Struct(cache_data["study"]) details = [Struct(r) for r in cache_data["details"]] else: sql = """select id,score from yy_study where user_id=%s and object_id=%s """ % ( user_id, task_detail.id) study = db.tbkt_yingyu.fetchone_dict(sql) if not study: return sql = """select id,study_id,object_id,answer,result, remote_audio,score from yy_study_detail where study_id=%s""" % study.id details = db.tbkt_yingyu.fetchall_dict(sql) data = Struct() data.score = study.score data.grade = score_to_en(study.score) word_ids = [d.object_id for d in details] if not word_ids: return sql = """select id, translation, male_audio,female_audio,phonetic,word from yy_word where id in (%s)""" % ",".join( str(i) for i in word_ids) words = db.ziyuan_slave.fetchall_dict(sql) for word in words: word.female_audio = format_ziyuan_url(word.female_audio) word.male_audio = format_ziyuan_url(word.male_audio) word.audio = word.female_audio or word.male_audio word_dict = dict((w.id, w) for w in words) rows = [] for d in details: row = Struct() word = word_dict[d.object_id] row.text = word.word.strip() row.phonetic = word.phonetic row.translation = word.translation row.audio = word.audio row.mgrade = score_to_en(d.score) if not d.answer: d.answer = "<em>%s</em>" % word.phonetic row.user_answer = d.answer row.user_audio = d.remote_audio.strip() if d.remote_audio else None row.result = d.result rows.append(row) data.words = rows return data
def get_dialog(cid): '情景对话' if not cid: return data = cache.yy_chapter_dialog.get(cid) if data: data = Struct(data) data.roles = [Struct(r) for r in data.roles if r] sentences = [] for r in data.sentences: r = Struct(r) r.role = Struct(r.role) if r.role else None sentences.append(r) data.sentences = sentences else: sql = """select id,title from yy_standard_pool where status<>-1 and catalog_id=%s and type in (1,3) and tts=1""" % cid lesson = db.ziyuan_slave.fetchone_dict(sql) if not lesson: return sql = """select id,pool_id,text,audio_text,translation,male_audio,female_audio,is_key,role_id,sequence,line,duration from yy_standard_pool_detail s where s.pool_id=%s and s.status<>-1 ORDER BY s.sequence """ % lesson.id sentences = db.ziyuan_slave.fetchall_dict(sql) role_dict = {} roles_list = [i.role_id for i in sentences if i.role_id] if roles_list: sql = """select r.id ,r.name_en,r.name_zh,r.code,r.image_id,r.sequence,i.portrait, i.gif_1, i.gif_2 from yy_role r LEFT JOIN yy_role_image i on i.id=r.image_id where r.id in (%s)""" % ','.join(str(i) for i in roles_list) rows = db.ziyuan_slave.fetchall_dict(sql) role_dict = {r.id: r for r in rows} for s in sentences: s.role = role_dict.get(s.role_id) path = s.female_audio or s.male_audio if path: s.audio = format_ziyuan_url(path) roles = OrderedDict() for s in sentences: if s.role and s.role.id not in roles: roles[s.role.id] = s.role if s.role.gif_1: s.role.gif_1 = format_ziyuan_url(s.role.gif_1) if s.role.gif_2: s.role.gif_2 = format_ziyuan_url(s.role.gif_2) s.role.portrait = format_ziyuan_url(s.role.portrait) rename_role(sentences) data = Struct() data.title = lesson.title data.roles = [] for role in roles.values(): row = Struct() row.id = role.id row.name_en = role.name_en row.portrait = role.portrait row.gif_1 = role.gif_1 row.gif_2 = role.gif_2 data.roles.append(row) data.sentences = [] for s in sentences: row = Struct() row.id = s.id row.role_id = s.role.id if s.role else None row.name_en = 'A' if s.role and s.role.name_en: row.name_en = s.role.name_en row.audio = s.audio row.audio_text = s.audio_text row.text = s.text row.translation = s.translation row.duration = math.ceil(s.duration) data.sentences.append(row) cache.yy_chapter_dialog.set(cid, data) return data