Exemplo n.º 1
0
def grade(soln, stdn):
    for soln_record, stdn_record in zip(soln, stdn):
        if soln_record != stdn_record:
            grade_helper.fail('Record mismatch, expected: ' +
                              str(soln_record) + ' got: ' + str(stdn_record))

    grade_helper.success()
Exemplo n.º 2
0
def grade(soln, stdn):
    for key in soln:
        if key not in stdn:
            grade_helper.fail('Missing person: ' + key)
        elif soln[key] != stdn[key]:
            grade_helper.fail('Value mismatch for ' + key + '. Expected: ' + str(soln[key]) + ' Got: ' + str(stdn[key]))

    grade_helper.success()
Exemplo n.º 3
0
def grade(soln, stdn):
    diff = soln - stdn
    if len(diff) != 0:
        grade_helper.fail('Expected student solution to contain: ' + ','.join(diff))

    diff = stdn - soln
    if len(diff) != 0:
        grade_helper.fail('Student solution contains extraneous data: ' + ','.join(diff))

    grade_helper.success()
Exemplo n.º 4
0
def grade(soln, stdn):
    for key in soln:
        if key not in stdn:
            grade_helper.fail('Missing word: ' + key)
        elif sorted(soln[key]) != sorted(stdn[key]):
            grade_helper.fail('Value mismatch for ' + key + '. Expected: ' +
                              ','.join(soln[key]) + ' Got: ' +
                              ','.join(stdn[key]))

    grade_helper.success()
Exemplo n.º 5
0
def gen_dict(stdn_file, graded):
    result = []
    for record_str in stdn_file:
        try:
            record = json.loads(record_str)
            result.append(record)
        except:
            if graded:
                grade_helper.fail('Parse error: ' + record_str)
    return sorted(result)
Exemplo n.º 6
0
def grade(stdn_ten, soln_ten):
    sort_stdn = sorted(stdn_ten.items(), key=lambda x : x[1], reverse=True) 
    sort_soln = sorted(soln_ten.items(), key=lambda x : x[1], reverse=True)
    for i in range(len(sort_soln)):
        stdn_val = sort_stdn[i][1]
        soln_val = sort_soln[i][1]
        if stdn_val != soln_val:
            grade_helper.fail('Expected a count of ' + str(soln_val) + ' at rank ' + str(i) + ', got ' + str(stdn_val))

    grade_helper.success()
Exemplo n.º 7
0
def grade(soln, stdn):
    for key in soln:
        if key not in stdn:
            grade_helper.fail("Missing word: " + key)
        elif sorted(soln[key]) != sorted(stdn[key]):
            grade_helper.fail(
                "Value mismatch for " + key + ". Expected: " + ",".join(soln[key]) + " Got: " + ",".join(stdn[key])
            )

    grade_helper.success()
Exemplo n.º 8
0
def gen_dict(stdn_file, graded):
    result = []
    for record_str in stdn_file:
        try:
            record = json.loads(record_str)
            result.append(record)
        except:
            if graded:
                grade_helper.fail('Parse error: ' + record_str)
    return sorted(result, key=lambda record: (record[0], record[12]))
Exemplo n.º 9
0
def parse(score_file):
    scores = []
    for score_line in score_file:
        try:
            score = float(score_line)
        except:
            grade_helper.fail('parsing error, line should be a number: ' + score_line)
        
        scores.append(score)
    return scores
Exemplo n.º 10
0
def gen_dict(stdn_file, graded):
    result = {}
    for pair in stdn_file:
        try:
            pair_dict = json.loads(unicode(pair, encoding='latin-1'))
            result.update(pair_dict)
        except:
            if graded:
                grade_helper.fail('Parse error: ' + pair)
    return result
Exemplo n.º 11
0
def gen_dict(stdn_file, graded):
    result = []
    for record_str in stdn_file:
        try:
            record = json.loads(record_str)
            result.append(record)
        except:
            if graded:
                grade_helper.fail("Parse error: " + record_str)
    return sorted(result, key=lambda record: (record[0], record[12]))
Exemplo n.º 12
0
def grade(soln, stdn):
    if len(soln) != len(stdn):
        grade_helper.fail('Expected ' + str(len(soln)) + ' scores')

    for i in range(len(soln)):
        soln_score = soln[i]
        stdn_score = stdn[i]
        if soln_score != stdn_score:
            grade_helper.fail('Expected ' + str(soln_score) + ' for tweet #' + str(i) + ' got: ' + str(stdn_score))

    grade_helper.success()
Exemplo n.º 13
0
def grade(stdn_ten, soln_ten):
    sort_stdn = sorted(stdn_ten.items(), key=lambda x: x[1], reverse=True)
    sort_soln = sorted(soln_ten.items(), key=lambda x: x[1], reverse=True)
    for i in range(len(sort_soln)):
        stdn_val = sort_stdn[i][1]
        soln_val = sort_soln[i][1]
        if stdn_val != soln_val:
            grade_helper.fail('Expected a count of ' + str(soln_val) +
                              ' at rank ' + str(i) + ', got ' + str(stdn_val))

    grade_helper.success()
Exemplo n.º 14
0
def grade(soln, stdn):
    diff = soln - stdn
    if len(diff) != 0:
        grade_helper.fail('Expected student solution to contain: ' +
                          ','.join(diff))

    diff = stdn - soln
    if len(diff) != 0:
        grade_helper.fail('Student solution contains extraneous data: ' +
                          ','.join(diff))

    grade_helper.success()
Exemplo n.º 15
0
def grade(stdn, soln):
    soln_min_term = min(soln.items(), key=lambda x: x[1])[0]
    soln_max_term = max(soln.items(), key=lambda x: x[1])[0]
    soln_mid_term = mid_freq_term(soln, soln_min_term, soln_max_term)
    stdn_min_score = stdn[soln_min_term]
    stdn_mid_score = stdn[soln_mid_term]
    stdn_max_score = stdn[soln_max_term]

    if not (stdn_max_score >= stdn_mid_score):
        grade_helper.fail(soln_mid_term + '(' + str(stdn_mid_score) + ') has a greater frequency than ' + soln_max_term + '(' + str(stdn_max_score) + ')')

    if not (stdn_mid_score >= stdn_min_score):
        grade_helper.fail(soln_min_term + '(' + str(stdn_min_score) + ') has a greater frequency than ' + soln_mid_term + '(' + str(stdn_mid_score) + ')')

    grade_helper.success()
Exemplo n.º 16
0
def main():
    sent_file = open(sys.argv[1])
    tweet_file = open(sys.argv[2])
    hap_file = open(sys.argv[3])
    pre_comp_sent = parse_afinn.parse_sentiment_file(sent_file)
    sentiments = sent_grader.get_term_sentiments(pre_comp_sent, tweet_file)
    stdn_hap_state = grade_helper.parse_state(hap_file)

    tweet_file.seek(0)
    soln_hap_state = compute_happiest(sentiments, parse_tweets(tweet_file))

    if stdn_hap_state.lower() != soln_hap_state.lower():
        grade_helper.fail('Student solution returns ' + stdn_hap_state + ' while grader solution returns ' + soln_hap_state)
    else:
        grade_helper.success()
Exemplo n.º 17
0
def main():
    con = sqlite3.connect(sys.argv[1])
    c = con.cursor()

    select = 'select c.row_num, c.col_num, c.value, stdn.value'
    from_clause = 'from c, stdn'
    where = 'where c.row_num = stdn.row_num and c.col_num = stdn.col_num and c.value != stdn.value'

    query = select + ' ' + from_clause + ' ' + where
    c.execute(query)
    row = c.fetchone()

    if row:
        grade_helper.fail('Expected ' + str(row[2]) + ' at (' + str(row[0]) + ',' + str(row[1]) + '), got: ' + str(row[3]))
    else:
        grade_helper.success()
Exemplo n.º 18
0
def main():
    con = sqlite3.connect(sys.argv[1])
    c = con.cursor()

    select = 'select c.row_num, c.col_num, c.value, stdn.value'
    from_clause = 'from c, stdn'
    where = 'where c.row_num = stdn.row_num and c.col_num = stdn.col_num and c.value != stdn.value'

    query = select + ' ' + from_clause + ' ' + where
    c.execute(query)
    row = c.fetchone()

    if row:
        grade_helper.fail('Expected ' + str(row[2]) + ' at (' + str(row[0]) +
                          ',' + str(row[1]) + '), got: ' + str(row[3]))
    else:
        grade_helper.success()
Exemplo n.º 19
0
def main():
    con = sqlite3.connect(sys.argv[1])
    c = con.cursor()

    select = 'select t.term, t.doc_id, t.value, stdn.value'
    from_clause = 'from tfidf as t, stdn'
    where = 'where t.term = stdn.term and t.doc_id = stdn.doc_id and t.value != stdn.value'

    query = select + ' ' + from_clause + ' ' + where
    c.execute(query)
    row = c.fetchone()

    if row:
        grade_helper.fail('Expected ' + str(row[2]) + ' for (' + str(row[0]) +
                          ',' + str(row[1]) + '), got: ' + str(row[3]))
    else:
        grade_helper.success()
Exemplo n.º 20
0
def gen_dict(stdn_file, graded):
    result = set()
    duplicate = False
    for record_str in stdn_file:
        try:
            record = json.loads(record_str)
            if record in result and graded:
                duplicate = True
            else:
                result.add(record)
        except:
            if graded:
                grade_helper.fail('Parse error: ' + record_str)

    if duplicate:
        grade_helper.fail('Duplicate input: ' + record)

    return result
Exemplo n.º 21
0
def grade(student, solution):
    sorted_solution = sorted(solution.items(), key=lambda x : x[1])
    soln_min_term = sorted_solution[0][0]
    soln_max_term = sorted_solution[len(sorted_solution) - 1][0]
    mid_sent = 1.0 * (solution[soln_min_term] + solution[soln_max_term]) / 2
    sorted_by_dist_from_mid = sorted(solution.items(), key=lambda x : abs(x[1] - mid_sent))
    soln_mid_term = sorted_by_dist_from_mid[0][0]
    student_max_sent = student[soln_max_term]
    student_mid_sent = student[soln_mid_term]
    student_min_sent = student[soln_min_term]
    
    if not (student_max_sent >= student_mid_sent):
        grade_helper.fail(soln_mid_term + '(' + str(student_mid_sent) + ') has a greater sentiment score than ' + soln_max_term + '(' + str(student_max_sent) + ')')

    if not (student_mid_sent >= student_min_sent):
        grade_helper.fail(soln_min_term + '(' + str(student_min_sent) + ') has a greater sentiment score than ' + soln_mid_term + '(' + str(student_mid_sent) + ')')

    grade_helper.success()
Exemplo n.º 22
0
def gen_dict(stdn_file, graded):
    result = set()
    duplicate = False
    for record_str in stdn_file:
        try:
            record = json.loads(record_str)
            if record in result and graded:
                duplicate = True
            else:
                result.add(record)
        except:
            if graded:
                grade_helper.fail('Parse error: ' + record_str)

    if duplicate:
        grade_helper.fail('Duplicate input: ' + record)

    return result
Exemplo n.º 23
0
def grade(stdn, soln):
    soln_min_term = min(soln.items(), key=lambda x: x[1])[0]
    soln_max_term = max(soln.items(), key=lambda x: x[1])[0]
    soln_mid_term = mid_freq_term(soln, soln_min_term, soln_max_term)
    stdn_min_score = stdn[soln_min_term]
    stdn_mid_score = stdn[soln_mid_term]
    stdn_max_score = stdn[soln_max_term]

    if not (stdn_max_score >= stdn_mid_score):
        grade_helper.fail(soln_mid_term + '(' + str(stdn_mid_score) +
                          ') has a greater frequency than ' + soln_max_term +
                          '(' + str(stdn_max_score) + ')')

    if not (stdn_mid_score >= stdn_min_score):
        grade_helper.fail(soln_min_term + '(' + str(stdn_min_score) +
                          ') has a greater frequency than ' + soln_mid_term +
                          '(' + str(stdn_mid_score) + ')')

    grade_helper.success()
Exemplo n.º 24
0
def parse(output):
    for obj in output:
        try:
            json.loads(obj)
        except:
            grade_helper.fail('Parse error: ' + obj)
Exemplo n.º 25
0
def grade(soln, stdn):
    for soln_record, stdn_record  in zip(soln, stdn):
        if soln_record != stdn_record:
            grade_helper.fail('Record mismatch, expected: ' + str(soln_record) + ' got: ' + str(stdn_record))

    grade_helper.success()