Beispiel #1
0
def check_attempt(p):
    att = get_numerical_answer(p['att_tree'])
    ans = get_numerical_answer(p['ans_tree'])

    if float(ans).is_integer() and not float(att).is_integer():
        return "Can the number of strings satisfying the constraint be fractional?"
    return ""
Beispiel #2
0
def check_attempt(p):
    att = get_numerical_answer(p['att_tree'])
    ans = get_numerical_answer(p['ans_tree'])

    if att * ans < 0:
        return "Can the number of strings satisfying the constraint be negative?"
    return ""
def evaluate_test(ans, att):
	ans = ans.strip("\[")
	ans = ans.strip("\]")
	ans = ans.replace("{","")
	ans = ans.replace("}","")
	att = att.strip("'")
	try:
		update_sql = """UPDATE eval_info 
						SET attempt = %s
						SET answer = %s"""
		db_cursor.execute(update_sql,(att,ans))
		db.commit()
	except:
		db.rollback()
		print "Database has been rolled back because of an Exception !!!"
		#print(traceback.format_exc())  

	p = make_params(ans, att)
	if p == {}:
		#logger.info("param empty from evaluate")
		return False
	att_value = get_numerical_answer(p['att_tree'])
	ans_value = get_numerical_answer(p['ans_tree'])
	final_pairs = find_matches(p)
	#logger.info("output matching: {0}.".format(final_pairs))

	if len(final_pairs) == 1 and final_pairs[0][0] == 'R':
		return True
	elif check_w_tol(ans_value, att_value):
		return True
	else:
		return False
Beispiel #4
0
def check_final_answer(params,tol = 1+1e-3):
    att_tree = params['att_tree']
    ans_tree = params['ans_tree']
    att_result = get_numerical_answer(att_tree)
    ans_result = get_numerical_answer(ans_tree)
    if ans_result != 0:
        ratio = att_result/ans_result
    else:
        if att_result == 0:
            ratio = 1
        else:
            ratio = 0

    if ratio < tol and ratio > (1/tol):
        return True
    else:
        return False
Beispiel #5
0
def evaluate(ans, att):
	ans = ans.strip("\[")
  	ans = ans.strip("\]")
  	ans = ans.replace("{","")
  	ans = ans.replace("}","")
  	att = att.strip("'")
  	#logger.info("evaluating attempt: {0}, answer: {1}.".format(att, ans))
	p = make_params(ans, att)
	if p == {}:
		#logger.info("param empty from evaluate")
		return False
	att_value = get_numerical_answer(p['att_tree'])
	ans_value = get_numerical_answer(p['ans_tree'])
	final_pairs = find_matches(p)
	#logger.info("output matching: {0}.".format(final_pairs))

	if len(final_pairs) == 1 and final_pairs[0][0] == 'R':
		return True
	elif check_w_tol(ans_value, att_value):
		return True
	else:
		return False
Beispiel #6
0
def evaluate(ans, att, tol=1 + 1e-5):
    ans = ans.strip("\[")
    ans = ans.strip("\]")
    ans = ans.replace("{", "")
    ans = ans.replace("}", "")
    att = att.strip("'")
    #logger.info("evaluating attempt: {0}, answer: {1}.".format(att, ans))
    p = make_params(ans, att)
    if p == {}:
        #logger.info("param empty from evaluate")
        return False
    att_value = get_numerical_answer(p['att_tree'])
    ans_value = get_numerical_answer(p['ans_tree'])
    final_pairs = find_matches(p, tol)
    #logger.info("output matching: {0}.".format(final_pairs))

    if len(final_pairs) == 1 and final_pairs[0][0] == 'R':
        return True
    elif check_w_tol(ans_value, att_value, tol):
        return True
    else:
        return False