Exemplo n.º 1
0
def get_active_paper_question_number_sheet(user_id, active_id, paper_id):
    details = db.tbkt_active_slave.active_paper_detail.select('text')\
        .filter(user_id=user_id, active_id=active_id, paper_id=paper_id).last()
    if not details:
        return [], []

    numbers = []
    ask_no = 1
    text = details.text
    text = json.loads(text)
    text = [Struct(t) for t in text]
    text.sort(lambda x, y: cmp(x['qid'], y['qid']))
    for d in text:
        number = Struct()
        number.ask_no = ask_no
        number.qid = d.qid
        number.aid = d.aid
        numbers.append(number)
        ask_no += 1
    qids = [q.qid for q in numbers]
    if not qids:
        return [], []
    ask_list = [d.aid for d in text]

    sheet = {}
    for d in text:
        detail = {}
        detail['question_id'] = d.qid
        detail['ask_id'] = d.aid
        detail['option_id'] = d.oid
        detail['answer'] = d.answer
        detail['result'] = d.result
        sheet[d.aid] = detail
    sheets = [sheet[d] for d in ask_list if sheet.get(d)]
    return numbers, sheets
Exemplo n.º 2
0
def get_answer_sheet(questions=[]):
    """
    功能说明:            对正确答案进行格式化
    {ask_id:{qid:1,right_answer:用户答案}}
    -----------------------------------------------
    修改人                    修改时间
    -----------------------------------------------
    张帅男                    2016-11-3
    """
    sheet = []
    for q in questions:
        for ask in q.asks:
            ask = Struct(ask)
            row = Struct()
            row.qid = q.id
            row.aid = ask.id
            row.right_answer = ''
            if ask:
                sql = "SELECT `option` from yy_ask_options WHERE ask_id = %s and is_right = 1;" % ask.id
                _ask = db.ziyuan_slave.fetchall_dict(sql)
                if _ask:
                    _ask = _ask[0]
                row.right_answer = _ask.option if _ask else ''
            if ask and q.type == 2:
                row.right_answer = format_link_answer(ask.options)
            sheet.append(row)
    return sheet