def grades(): user = validate_user() categories = session.query(Category).all() homeworks = get_homeworks_before() update_hw_grades(user, homeworks) session.commit() gradebook, max_scores = get_gradebook() grades = [entry for entry in gradebook if entry[0] == user] if grades: grades = grades[0][1] else: grades = {hw.id: get_grade(user.stuid, hw.id) for hw in homeworks} return render_template("grades.html", homeworks=homeworks, grades=grades, max_scores=max_scores, options=options, user=user, categories=categories)
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!"