Beispiel #1
0
def testing(paper_id, index='1'):
    index_index = get_page_index(index)
    num = Item.select().where(Item.paper == paper_id)
    if not num:
        error = '暂无题目'
        return render_template("error.html", error=error)
    p = Page(len(num), index_index, 1)
    items = Item.select().where((Item.paper == paper_id)
                                & (Item.index == index))
    item = items[0]
    return render_template("items.html", item=item, page=p)
Beispiel #2
0
def get_items(paper_id):
    if not paper_id:
        raise APIValueError('item', 'not fond')
    items = Item.select().where(Item.paper == paper_id).order_by(
        Item.index).dicts()
    response = {'items': items}
    return jsonify(response)
Beispiel #3
0
def get_item(paper_id):
    papers = Paper.select().where(Paper.id == paper_id).dicts()
    paper = list(papers)[0]
    paper['state'] = ''
    items = Item.select().where(Item.paper == paper_id).order_by(
        Item.index).dicts()
    state = TestState(paper=paper)
    response = {'state': state.dicts(), 'items': list(items)}
    return jsonify(response)
Beispiel #4
0
def get_testResults(paper_id):
    d1 = datetime.now()
    if not paper_id:
        raise APIValueError('paper', 'not fond')
    paper = list(Paper.select().where(Paper.id == paper_id).dicts())[0]
    data = json.loads(paper['state'])
    print(paper['state'])
    res = data['results']
    paper['state'] = ''
    re_state = TestState(paper=paper)

    re_state.finish_items = list(
        Item.select().where(Item.id << data['finish_items']).dicts())
    re_state.unfinish_items = list(
        Item.select().where(Item.id << data['unfinish_items']).dicts())
    re_state.true_items = list(
        Item.select().where(Item.id << data['true_items']).dicts())
    re_state.false_items = list(
        Item.select().where(Item.id << data['false_items']).dicts())
    '''
    items = list(Item.select().where(Item.paper==paper['id']).dicts())
    for item in items:
        for re in res:
            if item['id'] == re['item']:
                item['user_answer'] = re['user_answer']
        if item['id'] in data['finish_items']:
            re_state.finish_items.append(item)
        if item['id'] in data['unfinish_items']:
            re_state.unfinish_items.append(item)
        if item['id'] in data['true_items']:
            re_state.true_items.append(item)
        if item['id'] in data['false_items']:
            re_state.false_items.append(item)
    '''
    re_state.score = data['score']
    re_state.status = data['status']
    re_state.finish_time = data['finish_time']
    re_state.utime = data['utime']
    response = {'state': re_state.dicts()}
    d2 = datetime.now()
    return jsonify(response)
Beispiel #5
0
def commit_paper():
    data = request.json
    print(data)
    if not data:
        raise APIValueError('state', 'not fond')
    state = data.get('state')
    result_list = state.get('results', [])

    finish_items = state.get('finish_items', [])
    finappend = finish_items.append

    unfinish_items = state.get('unfinish_items', [])
    uappend = unfinish_items.append

    true_items = state.get('true_items', [])
    tappend = true_items.append

    false_items = state.get('false_items', [])
    print('len')
    print(len(false_items))
    falappend = false_items.append
    d1 = datetime.now()
    for i in result_list:
        item_id = i.get('item')
        item = Item.select().where(Item.id == item_id)[0]
        item.user_answer = i.get('user_answer')
        if item.user_answer:
            finappend(item.id)
        else:
            uappend(item.id)
        if item.user_answer == item.answer:
            state['score'] += item.score
            tappend(item.id)
        if item.user_answer and item.user_answer != item.answer:
            falappend(item.id)
        item.save()
    d2 = datetime.now()
    state['status'] = '已完成'
    paper = state['paper']
    paper_id = paper.get('id')
    papers = Paper.select().where(Paper.id == paper_id)
    paper = papers[0]
    #state.pop('results')
    state.pop('paper')
    paper.state = json.dumps(state)
    paper.save()
    response = {'url': '/test/results/' + paper.id}
    return jsonify(response)