def calculate_grade(user, hw): """ helper function that calculates a student's grade on a given homework """ # total up the points score = 0. if len(hw.questions) == 0: return None for q in hw.questions: out = q.load_response(user) if out['submission'] is None: continue elif out['submission'].score is None: return None else: score += out['submission'].score # fill in grades grade = get_grade(user.stuid, hw.id) if not grade: add_grade(user, hw, score) elif grade.score != score: grade.score = score else: return grade return grade
def update_grade(): admin = validate_admin() stuid = request.form['stuid'] hw_id = request.form['hw_id'] score = request.form['score'].strip() excused = 1 if request.form['excused'] == "true" else 0 # check that score is valid try: float(score) except: assert (score in ["", "E"]) # fill in grades grade = get_grade(stuid, hw_id) if not grade: add_grade(get_user(stuid), get_homework(hw_id), score, excused) else: grade.score = score grade.excused = excused session.commit() return "Grade update successful!"
def update_grade(): admin = validate_admin() stuid = request.form['stuid'] hw_id = request.form['hw_id'] score = request.form['score'].strip() excused = 1 if request.form['excused'] == "true" else 0 # check that score is valid try: float(score) except: assert(score in ["", "E"]) # fill in grades grade = get_grade(stuid, hw_id) if not grade: add_grade(get_user(stuid), get_homework(hw_id), score, excused) else: grade.score = score grade.excused = excused session.commit() return "Grade update successful!"