Exemplo n.º 1
0
Arquivo: app.py Projeto: dlsun/ohms
def download_grades():
    admin = validate_admin()

    homeworks = get_homework()
    categories = session.query(Category).all()
    gradebook, max_scores = get_gradebook()

    csv = '"SUNet","Student","Overall",'
    csv += ','.join(('"' + c.name.replace('"', '""') + ' Total"') for c in categories) + ","
    csv += ','.join(('"' + hw.name.replace('"', '""') + '"') for hw in homeworks) + "\n"

    csv += ',"MAXIMUM",,' + ",".join("" for c in categories) + "," 
    csv += ",".join(str(max_scores[hw.id]) for hw in homeworks) + "\n"
    
    for student, grades in gradebook:
        row = [student.stuid, student.name, str(grades["overall"])]
        for category in categories:
            row.append(str(grades[category.name]))
        for hw in homeworks:
            if hw.id not in grades:
                row.append("")
            else:
                row.append("E" if grades[hw.id].excused else str(grades[hw.id].score))
        csv += ",".join(row) + "\n"
        
    response = make_response(csv)
    course = options.title.replace(" ", "")
    date = datetime.now().strftime("%m-%d-%Y")
    filename = "%sGrades%s.csv" % (course, date)
    response.headers["Content-Disposition"] = "attachment; filename=%s" % filename

    return response
Exemplo n.º 2
0
Arquivo: app.py Projeto: flywind2/ohms
def admin():
    admin = validate_admin()

    # change back to admin view
    admin.proxy = admin.stuid
    session.commit()

    homeworks = get_homework()
    categories = session.query(Category).all()

    users = get_users()
    guests = []
    admins = []
    for user in users:
        if user.type == "guest":
            guests.append(user)
        elif user.type == "admin":
            admins.append(user)

    gradebook, max_scores = get_gradebook()

    return render_template("admin/index.html",
                           homeworks=homeworks,
                           guests=guests,
                           admins=admins,
                           categories=categories,
                           gradebook=gradebook,
                           max_scores=max_scores,
                           options=options)
Exemplo n.º 3
0
Arquivo: app.py Projeto: dlsun/ohms
def update_max_score():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    max_score = request.form['max_score'].strip()

    homework = get_homework(hw_id)
    homework.max_score = None if max_score == "" else float(max_score)
    session.commit()

    return "The maximum score for %s has been successfully updated!" % homework.name
Exemplo n.º 4
0
Arquivo: app.py Projeto: flywind2/ohms
def refresh_grades():
    """
    This updates all students' grades on all homeworks.
    """
    homeworks = get_homework()
    students = get_students()
    for student in students:
        update_hw_grades(student, homeworks)
        print student.name
    session.commit()
    return "Successfully updated all students' grades."
Exemplo n.º 5
0
Arquivo: app.py Projeto: flywind2/ohms
def update_hw_name():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw_name = request.form['hw_name']

    homework = get_homework(hw_id)
    homework.name = hw_name
    session.commit()

    return '''The homework name was successfully updated to "%s"!''' % homework.name
Exemplo n.º 6
0
Arquivo: app.py Projeto: dlsun/ohms
def refresh_grades():
    """
    This updates all students' grades on all homeworks.
    """
    homeworks = get_homework()
    students = get_students()
    for student in students:
        update_hw_grades(student, homeworks)
        print student.name
    session.commit()
    return "Successfully updated all students' grades."
Exemplo n.º 7
0
Arquivo: app.py Projeto: dlsun/ohms
def update_hw_name():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw_name = request.form['hw_name']

    homework = get_homework(hw_id)
    homework.name = hw_name
    session.commit()

    return '''The homework name was successfully updated to "%s"!''' % homework.name
Exemplo n.º 8
0
Arquivo: app.py Projeto: flywind2/ohms
def update_max_score():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    max_score = request.form['max_score'].strip()

    homework = get_homework(hw_id)
    homework.max_score = None if max_score == "" else float(max_score)
    session.commit()

    return "The maximum score for %s has been successfully updated!" % homework.name
Exemplo n.º 9
0
Arquivo: app.py Projeto: dlsun/ohms
def hw():
    user = validate_user()
    hw_id = request.args.get("id")
    hw = get_homework(hw_id)
    question_list = get_all_regular_questions() if user.type == "admin" else None

    if user.type == "admin":
        return render_template("hw.html",
                               hw_list=get_homework(),
                               homework=hw,
                               user=user,
                               question_list=question_list,
                               options=options)
    else:
        if hw.start_date and hw.start_date > pdt_now():
            raise Exception("This homework has not yet been released.")
        return render_template("hw.html",
                               homework=hw,
                               user=user,
                               question_list=question_list,
                               options=options)
Exemplo n.º 10
0
Arquivo: app.py Projeto: dlsun/ohms
def hw_list():
    user = validate_user()
    homeworks = get_homework()
    categories = session.query(Category).all()

    to_do = update_hw_grades(user, homeworks)
    session.commit()

    return render_template("list.html", homeworks=homeworks, categories=categories,
                           user=user,
                           options=options,
                           current_time=pdt_now(),
                           to_do=to_do)
Exemplo n.º 11
0
Arquivo: app.py Projeto: flywind2/ohms
def update_due_date():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    start_date = datetime.strptime(request.form['start_date'],
                                   "%m/%d/%Y %H:%M:%S")
    due_date = datetime.strptime(request.form['due_date'], "%m/%d/%Y %H:%M:%S")
    homework = get_homework(hw_id)
    homework.start_date = start_date
    homework.due_date = due_date
    session.commit()

    return "Due date for %s updated successfully!" % homework.name
Exemplo n.º 12
0
Arquivo: app.py Projeto: flywind2/ohms
def hw():
    user = validate_user()
    hw_id = request.args.get("id")
    hw = get_homework(hw_id)
    question_list = get_all_regular_questions(
    ) if user.type == "admin" else None

    if user.type == "admin":
        return render_template("hw.html",
                               hw_list=get_homework(),
                               homework=hw,
                               user=user,
                               question_list=question_list,
                               options=options)
    else:
        if hw.start_date and hw.start_date > pdt_now():
            raise Exception("This homework has not yet been released.")
        return render_template("hw.html",
                               homework=hw,
                               user=user,
                               question_list=question_list,
                               options=options)
Exemplo n.º 13
0
Arquivo: app.py Projeto: dlsun/ohms
def update_due_date():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    start_date = datetime.strptime(request.form['start_date'],
                                   "%m/%d/%Y %H:%M:%S")
    due_date = datetime.strptime(request.form['due_date'],
                                 "%m/%d/%Y %H:%M:%S")
    homework = get_homework(hw_id)
    homework.start_date = start_date
    homework.due_date = due_date
    session.commit()

    return "Due date for %s updated successfully!" % homework.name
Exemplo n.º 14
0
Arquivo: app.py Projeto: flywind2/ohms
def hw_list():
    user = validate_user()
    homeworks = get_homework()
    categories = session.query(Category).all()

    to_do = update_hw_grades(user, homeworks)
    session.commit()

    return render_template("list.html",
                           homeworks=homeworks,
                           categories=categories,
                           user=user,
                           options=options,
                           current_time=pdt_now(),
                           to_do=to_do)
Exemplo n.º 15
0
Arquivo: app.py Projeto: flywind2/ohms
def add_question():
    admin = validate_admin()

    xml = request.form['xml']
    node = ET.fromstring(xml)

    # remove any ID tags
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")

    question = Question.from_xml(node)
    question.homework = get_homework(request.form['hw_id'])

    session.commit()

    return "Question added successfully!"
Exemplo n.º 16
0
Arquivo: app.py Projeto: flywind2/ohms
def import_homework():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw = get_homework(hw_id)

    xml = request.files['xml'].read()
    if not xml:
        return "Empty file uploaded."

    try:
        hw.update_from_xml(xml)
    except:
        return "Invalid XML uploaded"

    return "Homework updated successfully from XML."
Exemplo n.º 17
0
Arquivo: app.py Projeto: dlsun/ohms
def add_question():
    admin = validate_admin()

    xml = request.form['xml']
    node = ET.fromstring(xml)

    # remove any ID tags
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")

    question = Question.from_xml(node)
    question.homework = get_homework(request.form['hw_id'])

    session.commit()

    return "Question added successfully!"
Exemplo n.º 18
0
Arquivo: app.py Projeto: dlsun/ohms
def import_homework():
    admin = validate_admin()

    hw_id = request.form['hw_id']
    hw = get_homework(hw_id)

    xml = request.files['xml'].read()
    if not xml:
        return "Empty file uploaded."

    try:
        hw.update_from_xml(xml)
    except:
        return "Invalid XML uploaded"

    return "Homework updated successfully from XML."
Exemplo n.º 19
0
Arquivo: app.py Projeto: flywind2/ohms
def export_homework():
    admin = validate_admin()

    hw_id = request.args['id']
    hw = get_homework(hw_id)

    # get XML for questions, wrap in <homework> tags
    xml = "\n\n".join(q.xml for q in hw.questions)
    xml = "<homework>\n" + xml + "\n</homework>"

    # get tree, remove any ID tags, convert back to string
    node = ET.fromstring(xml)
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")
    xml = ET.tostring(node)

    return Response(xml, content_type='text')
Exemplo n.º 20
0
Arquivo: app.py Projeto: dlsun/ohms
def export_homework():
    admin = validate_admin()

    hw_id = request.args['id']
    hw = get_homework(hw_id)

    # get XML for questions, wrap in <homework> tags
    xml = "\n\n".join(q.xml for q in hw.questions)
    xml = "<homework>\n" + xml + "\n</homework>"

    # get tree, remove any ID tags, convert back to string
    node = ET.fromstring(xml)
    for e in node.iter():
        if "id" in e.attrib: e.attrib.pop("id")
    xml = ET.tostring(node)

    return Response(xml, content_type='text')
Exemplo n.º 21
0
Arquivo: app.py Projeto: flywind2/ohms
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!"
Exemplo n.º 22
0
Arquivo: app.py Projeto: dlsun/ohms
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!"
Exemplo n.º 23
0
Arquivo: app.py Projeto: flywind2/ohms
def download_grades():
    admin = validate_admin()

    homeworks = get_homework()
    categories = session.query(Category).all()
    gradebook, max_scores = get_gradebook()

    csv = '"SUNet","Student","Overall",'
    csv += ','.join(('"' + c.name.replace('"', '""') + ' Total"')
                    for c in categories) + ","
    csv += ','.join(
        ('"' + hw.name.replace('"', '""') + '"') for hw in homeworks) + "\n"

    csv += ',"MAXIMUM",,' + ",".join("" for c in categories) + ","
    csv += ",".join(str(max_scores[hw.id]) for hw in homeworks) + "\n"

    for student, grades in gradebook:
        row = [student.stuid, student.name, str(grades["overall"])]
        for category in categories:
            row.append(str(grades[category.name]))
        for hw in homeworks:
            if hw.id not in grades:
                row.append("")
            else:
                row.append(
                    "E" if grades[hw.id].excused else str(grades[hw.id].score))
        csv += ",".join(row) + "\n"

    response = make_response(csv)
    course = options.title.replace(" ", "")
    date = datetime.now().strftime("%m-%d-%Y")
    filename = "%sGrades%s.csv" % (course, date)
    response.headers[
        "Content-Disposition"] = "attachment; filename=%s" % filename

    return response
Exemplo n.º 24
0
Arquivo: app.py Projeto: dlsun/ohms
def admin():
    admin = validate_admin()

    # change back to admin view
    admin.proxy = admin.stuid
    session.commit()

    homeworks = get_homework()
    categories = session.query(Category).all()

    users = get_users()
    guests = []
    admins = []
    for user in users:
        if user.type == "guest":
            guests.append(user)
        elif user.type == "admin":
            admins.append(user)

    gradebook, max_scores = get_gradebook()
    
    return render_template("admin/index.html", homeworks=homeworks, 
                           guests=guests, admins=admins, categories=categories,
                           gradebook=gradebook, max_scores=max_scores, options=options)
Exemplo n.º 25
0
Arquivo: app.py Projeto: flywind2/ohms
def get_gradebook():
    """
    helper function that gets the gradebook
    """

    user = validate_user()

    if user.type == "admin":
        homeworks = get_homework()
    else:
        homeworks = get_homeworks_before()

    # get all the grades, put them into a gradebook
    gradebook, max_scores = {}, {}

    for user in get_users():
        if user.type == "student":
            gradebook[user] = {}

    for homework in homeworks:

        grades = session.query(Grade).filter_by(hw_id=homework.id).all()

        scores = []
        for g in grades:
            if g.student not in gradebook:
                continue
            gradebook[g.student][homework.id] = g
            try:
                scores.append(float(g.score))
            except:
                pass

        if homework.max_score is not None:
            max_scores[homework.id] = homework.max_score
        elif scores:
            max_scores[homework.id] = max(scores)
        else:
            max_scores[homework.id] = None

    gradebook = gradebook.items()
    gradebook.sort(key=lambda entry: convert_to_last_name(entry[0].name))

    categories = session.query(Category).all()

    # calculate total scores by category, taking into account excused assignments
    for student, grades in gradebook:
        earned = {c: [] for c in categories}
        possible = {c: [] for c in categories}
        for hw in homeworks:
            if max_scores[hw.id] is None or max_scores[hw.id] == 0:
                continue
            possible[hw.category].append(max_scores[hw.id])
            if hw.id in grades:
                if grades[
                        hw.
                        id].excused:  # if student was excused from assignment
                    possible[hw.category].remove(
                        max_scores[hw.id])  # don't count it against
                else:
                    try:
                        earned[hw.category].append(float(grades[hw.id].score))
                    except:
                        earned[hw.category].append(0)
            else:
                earned[hw.category].append(0)

        # add grades to gradebook
        grades["overall"] = 0.
        for category, poss in possible.iteritems():
            if len(poss) == 0:
                grades[category.name] = "0 / 0"
                continue
            # sort scores by benefit to grade if dropped
            e, p = sum(earned[category]), sum(poss)
            if len(poss) > category.drops + 1:
                grades_sorted = sorted(zip(earned[category], poss),
                                       key=lambda x: -(e - x[0]) / (p - x[1]))
                grades_sorted = grades_sorted[category.drops:]
                out = zip(*grades_sorted)
            else:
                out = earned[category], poss
            grades[category.name] = "%0.1f / %0.1f" % (sum(out[0]), sum(
                out[1]))
            if sum(out[1]) > 0:
                grades["overall"] += category.weight * sum(out[0]) / sum(
                    out[1])

    return gradebook, max_scores
Exemplo n.º 26
0
Arquivo: app.py Projeto: dlsun/ohms
def get_gradebook():
    """
    helper function that gets the gradebook
    """

    user = validate_user()

    if user.type == "admin":
        homeworks = get_homework()
    else:
        homeworks = get_homeworks_before()

    # get all the grades, put them into a gradebook
    gradebook, max_scores = {}, {}

    for user in get_users():
        if user.type == "student":
            gradebook[user] = {}

    for homework in homeworks:
        
        grades = session.query(Grade).filter_by(hw_id = homework.id).all()

        scores = []
        for g in grades:
            if g.student not in gradebook:
                continue
            gradebook[g.student][homework.id] = g
            try:
                scores.append(float(g.score))
            except:
                pass

        if homework.max_score is not None:
            max_scores[homework.id] = homework.max_score
        elif scores:
            max_scores[homework.id] = max(scores)
        else:
            max_scores[homework.id] = None
            
    gradebook = gradebook.items()
    gradebook.sort(key=lambda entry: convert_to_last_name(entry[0].name))

    categories = session.query(Category).all()
    
    # calculate total scores by category, taking into account excused assignments
    for student, grades in gradebook:
        earned = {c: [] for c in categories}
        possible = {c: [] for c in categories}
        for hw in homeworks:
            if max_scores[hw.id] is None or max_scores[hw.id] == 0:
                continue
            possible[hw.category].append(max_scores[hw.id])
            if hw.id in grades:
                if grades[hw.id].excused: # if student was excused from assignment
                    possible[hw.category].remove(max_scores[hw.id]) # don't count it against
                else:
                    try:
                        earned[hw.category].append(float(grades[hw.id].score))
                    except:
                        earned[hw.category].append(0)
            else:
                earned[hw.category].append(0)

        # add grades to gradebook
        grades["overall"] = 0.
        for category, poss in possible.iteritems():
            if len(poss) == 0:
                grades[category.name] = "0 / 0"
                continue
            # sort scores by benefit to grade if dropped
            e, p = sum(earned[category]), sum(poss)
            if len(poss) > category.drops + 1:
                grades_sorted = sorted(zip(earned[category], poss), key=lambda x: -(e-x[0])/(p-x[1]))
                grades_sorted = grades_sorted[category.drops:]
                out = zip(*grades_sorted)
            else:
                out = earned[category], poss
            grades[category.name] = "%0.1f / %0.1f" % (sum(out[0]), sum(out[1]))
            if sum(out[1]) > 0:
                grades["overall"] += category.weight * sum(out[0]) / sum(out[1])
                
    return gradebook, max_scores