コード例 #1
0
def make_params(ans_str, att_str, variable_list={}):
    """
    input: answer string, attemp string,
    optional input: variable dictionary {'variable_name':value to test, 'variable_name2':value}
    return: list of dict with format
        'user_id':d['user_id'],'answer':d['answer'], 'attempt':d['attempt'],
        'ans_tree':eval_tree,'att_tree':eval_tree_att
    """

    parse_tree = webwork_parser.parse_webwork(ans_str)
    if parse_tree[0] == None:
        return {}
    eval_tree = Eval_parsed.eval_parsed(parse_tree[0], variable_list)
    if eval_tree == None:
        return {}

    parse_tree_att = webwork_parser.parse_webwork(att_str)
    if parse_tree_att[0] == None:
        return {}
    eval_tree_att = Eval_parsed.eval_parsed(parse_tree_att[0], variable_list)
    if eval_tree_att == None:
        return {}

    params = {
        'answer': ans_str,
        'attempt': att_str,
        'ans_tree': eval_tree,
        'att_tree': eval_tree_att
    }
    return params
コード例 #2
0
ファイル: make_params.py プロジェクト: zhenzhai/edx-platform
def make_params(ans_str, att_str, variable_list={}):
    """
    input: answer string, attemp string,
    optional input: variable dictionary {'variable_name':value to test, 'variable_name2':value}
    return: list of dict with format
        'user_id':d['user_id'],'answer':d['answer'], 'attempt':d['attempt'],
        'ans_tree':eval_tree,'att_tree':eval_tree_att
    """

    parse_tree = webwork_parser.parse_webwork(ans_str)
    if parse_tree[0] == None:
        return {}
    eval_tree = Eval_parsed.eval_parsed(parse_tree[0], variable_list)
    if eval_tree == None:
        return {}

    parse_tree_att = webwork_parser.parse_webwork(att_str)
    if parse_tree_att[0] == None:
        return {}
    eval_tree_att = Eval_parsed.eval_parsed(parse_tree_att[0], variable_list)
    if eval_tree_att == None:
        return {}

    params = {'answer':ans_str, 'attempt':att_str, 'ans_tree':eval_tree, 'att_tree':eval_tree_att}
    return params
コード例 #3
0
def show_matching_group_w_variables(ans_str, att_str, variable_values, test_all=False):
    """ can test all values provided in variable_values
    and return a list of hits """
    matches = find_matches_w_variables(ans_str, att_str, variable_values, test_all)
    parse_tree_att = webwork_parser.parse_webwork(att_str)
    matching_exps = []
    if parse_tree_att[0] == None:
        print 'parse_tree empty'
        return None
    if matches:
        for m in matches:
            tree_index = [int(i)+1 for i in m[0].split('.')[1:]]
            node = parse_tree_att[0]
            for t in tree_index:
                node = node[t]
            matching_exps.append(att_str[node[0][1][0]:node[0][1][1]+1])
        return matching_exps
    else:
        return None