def test_check(): for label, cats in exp.EXPERIMENT_KEY.iteritems(): for img in exp.ALL_IMGS: actual = exp.img_to_cat(img) in cats check = exp.check_pair(label, img) assert_equal(actual, check)
def test_gen_pair(): img, label = exp._gen_pair(True) assert_true(exp.check_pair(img, label)) img, label = exp._gen_pair(False) assert_false(exp.check_pair(img, label))
def exp(): if not current_user.is_authenticated(): return render_template( 'experiment.html', img=exper.ALL_IMGS[0], label=exper.LABELS_BY_CAT['1'][0], preview=True, score=0.) new = True if not current_user.is_debriefed() else None current_user.set_debriefed(True) user_id = current_user.get_username() if current_user.participant.current_session.img_index == IMG_PER_SESSION: return redirect(url_for('tree')) if current_user.get_break(): current_user.finish_block() current_user.set_break(False) if TREE_ON_BLOCK: return redirect(url_for('tree')) part = current_user.participant if not QUIZ: return render_template('finish_block.html', quiz=False) best_session = current_user.get_best() score = part.current_session.correct block_count = len(part.current_session.blocks) best_blocks = sorted([b for b in best_session.blocks if b.finished_at], key=lambda b: b.finished_at)[:block_count+1] if not best_blocks: diffsign = 'equal' diff = 0 else: diffbest = score - sum([b.correct for b in best_blocks]) diff = abs(diffbest) diffsign = get_diffsign(diffbest) return render_template( 'finish_block.html', quiz=True, diffsign=diffsign, diff=diff, ) label, img, pair_index, block_index = current_user.get_current_pair() response = None if request.method == 'GET': correct = None elif request.method == 'POST': label = request.form.get('label') if QUIZ: input = request.form['res'] == '1' response = request.form['res'] actual = exper.check_pair(label, img) correct = (input == actual) current_user.update_correct(correct) current_user.add_response(img, label, response) current_user.advance_pair() part = current_user.participant if part.current_session.img_index == 0: current_score = 0. else: current_score = float(part.current_session.correct) / part.current_session.img_index if QUIZ: return render_template( 'experiment.html', quiz=True, label=label, img=img, correct=correct, res=response, pair_index=pair_index, block_size=BLOCKSIZE, block_index=block_index, block_count=BLOCKS, new=new, score=current_score) else: current_user.advance_pair() return render_template( 'experiment.html', quiz=False, label=label, img=img, new=new, block_size=BLOCKSIZE, block_index=block_index, block_count=BLOCKS)