示例#1
0
def csv_to_grade_changes(course, grading_opportunity, attempt_id, file_contents,
        id_column, points_column, feedback_column, max_points,
        creator, grade_time, has_header):
    result = []

    import csv

    spamreader = csv.reader(file_contents)
    for row in spamreader:
        if has_header:
            has_header = False
            continue

        gchange = GradeChange()
        result.append(gchange)
        gchange.opportunity = grading_opportunity
        gchange.participation = find_participant_from_id(course, row[id_column-1])
        gchange.state = grade_state_change_types.graded
        gchange.attempt_id = attempt_id
        gchange.points = float(row[points_column-1])
        gchange.max_points = max_points
        if feedback_column is not None:
            gchange.comment = row[feedback_column-1]

        gchange.creator = creator
        gchange.grade_time = grade_time

    return result
示例#2
0
文件: grades.py 项目: akiyoko/relate
def csv_to_grade_changes(
        log_lines,
        course, grading_opportunity, attempt_id, file_contents,
        id_column, points_column, feedback_column, max_points,
        creator, grade_time, has_header):
    result = []

    import csv

    total_count = 0
    spamreader = csv.reader(file_contents)
    for row in spamreader:
        if has_header:
            has_header = False
            continue

        gchange = GradeChange()
        gchange.opportunity = grading_opportunity
        try:
            gchange.participation = find_participant_from_id(
                    course, row[id_column-1])
        except ParticipantNotFound as e:
            log_lines.append(e)
            continue

        gchange.state = grade_state_change_types.graded
        gchange.attempt_id = attempt_id

        points_str = row[points_column-1].strip()
        # Moodle's "NULL" grades look like this.
        if points_str in ["-", ""]:
            gchange.points = None
        else:
            gchange.points = float(fix_decimal(points_str))

        gchange.max_points = max_points
        if feedback_column is not None:
            gchange.comment = row[feedback_column-1]

        gchange.creator = creator
        gchange.grade_time = grade_time

        last_grades = (GradeChange.objects
                .filter(
                    opportunity=grading_opportunity,
                    participation=gchange.participation,
                    attempt_id=gchange.attempt_id)
                .order_by("-grade_time")[:1])

        if last_grades.count():
            last_grade, = last_grades

            if last_grade.state == grade_state_change_types.graded:

                updated = []
                if last_grade.points != gchange.points:
                    updated.append("points")
                if last_grade.max_points != gchange.max_points:
                    updated.append("max_points")
                if last_grade.comment != gchange.comment:
                    updated.append("comment")

                if updated:
                    log_lines.append(
                            "%(participation)s: %(updated)s "
                            "updated" % {
                                'participation': gchange.participation,
                                'updated': ", ".join(updated)})

                    result.append(gchange)
            else:
                result.append(gchange)

        else:
            result.append(gchange)

        total_count += 1

    return total_count, result
示例#3
0
文件: grades.py 项目: kwangkim/relate
def csv_to_grade_changes(
        log_lines,
        course, grading_opportunity, attempt_id, file_contents,
        id_column, points_column, feedback_column, max_points,
        creator, grade_time, has_header):
    result = []

    import csv

    total_count = 0
    spamreader = csv.reader(file_contents)
    for row in spamreader:
        if has_header:
            has_header = False
            continue

        gchange = GradeChange()
        gchange.opportunity = grading_opportunity
        try:
            gchange.participation = find_participant_from_id(
                    course, row[id_column-1])
        except ParticipantNotFound as e:
            log_lines.append(e)
            continue

        gchange.state = grade_state_change_types.graded
        gchange.attempt_id = attempt_id

        points_str = row[points_column-1].strip()
        # Moodle's "NULL" grades look like this.
        if points_str in ["-", ""]:
            gchange.points = None
        else:
            gchange.points = float(fix_decimal(points_str))

        gchange.max_points = max_points
        if feedback_column is not None:
            gchange.comment = row[feedback_column-1]

        gchange.creator = creator
        gchange.grade_time = grade_time

        last_grades = (GradeChange.objects
                .filter(
                    opportunity=grading_opportunity,
                    participation=gchange.participation,
                    attempt_id=gchange.attempt_id)
                .order_by("-grade_time")[:1])

        if last_grades.count():
            last_grade, = last_grades

            if last_grade.state == grade_state_change_types.graded:

                updated = []
                if last_grade.points != gchange.points:
                    updated.append("points")
                if last_grade.max_points != gchange.max_points:
                    updated.append("max_points")
                if last_grade.comment != gchange.comment:
                    updated.append("comment")

                if updated:
                    log_lines.append("%s: %s updated" % (
                        gchange.participation,
                        ", ".join(updated)))

                    result.append(gchange)
            else:
                result.append(gchange)

        else:
            result.append(gchange)

        total_count += 1

    return total_count, result
示例#4
0
文件: flow.py 项目: zenny/courseflow
def grade_flow_session(fctx, flow_session, current_access_rule,
        answer_visits=None):
    """Updates the grade on an existing flow session and logs a
    grade change with the grade records subsystem.
    """

    if answer_visits is None:
        answer_visits = assemble_answer_visits(flow_session)

    (answered_count, unanswered_count) = count_answered(
            fctx, flow_session, answer_visits)

    is_graded_flow = bool(answered_count + unanswered_count)

    is_graded_flow = bool(answered_count + unanswered_count)
    grade_info = gather_grade_info(flow_session, answer_visits)
    assert grade_info is not None

    comment = None
    points = grade_info.points

    if points is not None and current_access_rule.credit_percent is not None:
        comment = "Counted at %.1f%% of %.1f points" % (
                current_access_rule.credit_percent, points)
        points = points * current_access_rule.credit_percent / 100

    flow_session.points = points
    flow_session.max_points = grade_info.max_points

    flow_session.result_comment = comment
    flow_session.save()

    # Need to save grade record even if no grade is available yet, because
    # a grade record may *already* be saved, and that one might be mistaken
    # for the current one.
    if (is_graded_flow
            and flow_session.participation is not None
            and flow_session.for_credit):
        from course.models import get_flow_grading_opportunity
        gopp = get_flow_grading_opportunity(
                flow_session.course, flow_session.flow_id, fctx.flow_desc)

        from course.models import grade_state_change_types
        gchange = GradeChange()
        gchange.opportunity = gopp
        gchange.participation = flow_session.participation
        gchange.state = grade_state_change_types.graded
        gchange.attempt_id = "flow-session-%d" % flow_session.id
        gchange.points = points
        gchange.max_points = grade_info.max_points
        # creator left as NULL
        gchange.flow_session = flow_session
        gchange.comment = comment
        gchange.save()

    return grade_info
示例#5
0
文件: flow.py 项目: gboone/relate
def grade_flow_session(fctx, flow_session, grading_rule, answer_visits=None):
    """Updates the grade on an existing flow session and logs a
    grade change with the grade records subsystem.
    """

    if answer_visits is None:
        answer_visits = assemble_answer_visits(flow_session)

    (answered_count, unanswered_count) = count_answered_gradable(fctx, flow_session, answer_visits)

    is_graded_flow = bool(answered_count + unanswered_count)

    grade_info = gather_grade_info(fctx, flow_session, answer_visits)
    assert grade_info is not None

    comment = None
    points = grade_info.points

    if points is not None and grading_rule.credit_percent is not None and grading_rule.credit_percent != 100:
        comment = (
            # Translators: grade flow: calculating grade.
            _("Counted at %(percent).1f%% of %(point).1f points")
            % {"percent": grading_rule.credit_percent, "point": points}
        )
        points = points * grading_rule.credit_percent / 100

    flow_session.points = points
    flow_session.max_points = grade_info.max_points

    flow_session.append_comment(comment)
    flow_session.save()

    # Need to save grade record even if no grade is available yet, because
    # a grade record may *already* be saved, and that one might be mistaken
    # for the current one.
    if grading_rule.grade_identifier and is_graded_flow and flow_session.participation is not None:
        from course.models import get_flow_grading_opportunity

        gopp = get_flow_grading_opportunity(flow_session.course, flow_session.flow_id, fctx.flow_desc, grading_rule)

        from course.models import grade_state_change_types

        gchange = GradeChange()
        gchange.opportunity = gopp
        gchange.participation = flow_session.participation
        gchange.state = grade_state_change_types.graded
        gchange.attempt_id = "flow-session-%d" % flow_session.id
        gchange.points = points
        gchange.max_points = grade_info.max_points
        # creator left as NULL
        gchange.flow_session = flow_session
        gchange.comment = comment

        previous_grade_changes = list(
            GradeChange.objects.filter(
                opportunity=gchange.opportunity,
                participation=gchange.participation,
                state=gchange.state,
                attempt_id=gchange.attempt_id,
                flow_session=gchange.flow_session,
            ).order_by("-grade_time")[:1]
        )

        # only save if modified or no previous grades
        do_save = True
        if previous_grade_changes:
            previous_grade_change, = previous_grade_changes
            if (
                previous_grade_change.points == gchange.points
                and previous_grade_change.max_points == gchange.max_points
                and previous_grade_change.comment == gchange.comment
            ):
                do_save = False
        else:
            # no previous grade changes
            if points is None:
                do_save = False

        if do_save:
            gchange.save()

    return grade_info
示例#6
0
def finish_flow_session(fctx, flow_session, current_access_rule,
        force_regrade=False):
    if not flow_session.in_progress:
        raise RuntimeError("Can't end a session that's already ended")

    answer_visits = assemble_answer_visits(flow_session)

    (answered_count, unanswered_count) = count_answered(
            fctx, flow_session, answer_visits)

    is_graded_flow = bool(answered_count + unanswered_count)

    if is_graded_flow:
        grade_page_visits(fctx, flow_session, answer_visits,
                force_regrade=force_regrade)

    # ORDERING RESTRICTION: Must grade pages before gathering grade info

    grade_info = gather_grade_info(flow_session, answer_visits)

    comment = None

    if grade_info is not None:
        points = grade_info.points

        if current_access_rule.credit_percent is not None:
            comment = "Counted at %.1f%% of %.1f points" % (
                    current_access_rule.credit_percent, points)
            points = points * current_access_rule.credit_percent / 100
    else:
        points = None

    from django.utils.timezone import now
    flow_session.completion_time = now()
    flow_session.in_progress = False

    if grade_info is not None:
        flow_session.points = points
        flow_session.max_points = grade_info.max_points
    else:
        flow_session.points = None
        flow_session.max_points = None

    flow_session.result_comment = comment
    flow_session.save()

    if (is_graded_flow
            and flow_session.participation is not None
            and grade_info is not None
            and flow_session.for_credit):
        from course.models import get_flow_grading_opportunity
        gopp = get_flow_grading_opportunity(
                flow_session.course, flow_session.flow_id, fctx.flow_desc)

        from course.models import grade_state_change_types
        gchange = GradeChange()
        gchange.opportunity = gopp
        gchange.participation = flow_session.participation
        gchange.state = grade_state_change_types.graded
        gchange.attempt_id = "flow-session-%d" % flow_session.id
        gchange.points = points
        gchange.max_points = grade_info.max_points
        # creator left as NULL
        gchange.flow_session = flow_session
        gchange.comment = comment
        gchange.save()

    return grade_info