Ejemplo n.º 1
0
def create_calibration_records(location,student_id,num_to_create,sub_ids,scores,actual_scores):
    cal_hist,success=CalibrationHistory.objects.get_or_create(location=location,student_id=int(student_id))
    cal_hist.save()

    for i in xrange(0,num_to_create):
        sub=Submission.objects.get(id=int(sub_ids[i]))
        cal_record=CalibrationRecord(
            submission=sub,
            calibration_history=cal_hist,
            score=scores[i],
            actual_score=actual_scores[i],
            feedback="",
        )
        cal_record.save()
Ejemplo n.º 2
0
def create_calibration_records(location,student_id,num_to_create,sub_ids,scores,actual_scores):
    cal_hist,success=CalibrationHistory.objects.get_or_create(location=location,student_id=int(student_id))
    cal_hist.save()

    for i in xrange(0,num_to_create):
        sub=Submission.objects.get(id=int(sub_ids[i]))
        cal_record=CalibrationRecord(
            submission=sub,
            calibration_history=cal_hist,
            score=scores[i],
            actual_score=actual_scores[i],
            feedback="",
        )
        cal_record.save()
Ejemplo n.º 3
0
def create_and_save_calibration_record(calibration_data):
    """
    This function will create and save a calibration record object.
    Input:
        Dictionary containing keys submission_id, score, feedback, student_id, location
    Output:
        Boolean indicating success and dictionary with calibration id
        Or boolean indicating failure and error message
    """

    for tag in ['submission_id', 'score', 'feedback', 'student_id', 'location', 'rubric_scores_complete', 'rubric_scores']:
        if not tag in calibration_data:
            error_msg = "Cannot find needed key {0} in request.".format(tag)
            log.error(error_msg)
            return False, (error_msg)

    try:
        calibration_history, success = CalibrationHistory.objects.get_or_create(
            student_id=calibration_data['student_id'],
            location=calibration_data['location'],
        )
    except:
        error_msg = "Cannot get or create CalibrationRecord with "
        "student id {0} and location {1}.".format(calibration_data['student_id'],
                                                  calibration_data['location'])
        log.exception(error_msg)
        return False, (error_msg)
    try:
        submission = Submission.objects.get(
            id=calibration_data['submission_id']
        )
    except:
        error_msg = "Invalid submission id {0}.".format(calibration_data['submission_id'])
        log.exception(error_msg)
        return False, (error_msg)

    try:
        last_grader = submission.get_last_successful_instructor_grader()
        actual_score = last_grader['score']
        actual_rubric = last_grader['rubric']
        actual_feedback = last_grader['feedback']
    except:
        error_msg = "Error getting actual score for submission id {0}.".format(calibration_data['submission_id'])
        log.exception(error_msg)
        return False, (error_msg)

    if actual_score == -1:
        error_msg = "No instructor graded submission for submission id {0}.".format(calibration_data['submission_id'])
        log.error(error_msg)
        return False, (error_msg)

    cal_record = CalibrationRecord(
        submission=submission,
        calibration_history=calibration_history,
        score=calibration_data['score'],
        actual_score=actual_score,
        feedback=calibration_data['feedback'],
        rubric_scores_complete = calibration_data['rubric_scores_complete'],
        rubric_scores = json.dumps(calibration_data['rubric_scores']),
    )

    cal_record.save()

    return True, {'cal_id': cal_record.id, 'actual_score' : actual_score, 'actual_rubric' : actual_rubric, 'actual_feedback' : actual_feedback}
Ejemplo n.º 4
0
def create_and_save_calibration_record(calibration_data):
    """
    This function will create and save a calibration record object.
    Input:
        Dictionary containing keys submission_id, score, feedback, student_id, location
    Output:
        Boolean indicating success and dictionary with calibration id
        Or boolean indicating failure and error message
    """

    for tag in [
            'submission_id', 'score', 'feedback', 'student_id', 'location',
            'rubric_scores_complete', 'rubric_scores'
    ]:
        if not tag in calibration_data:
            error_msg = "Cannot find needed key {0} in request.".format(tag)
            log.error(error_msg)
            return False, (error_msg)

    try:
        calibration_history, success = CalibrationHistory.objects.get_or_create(
            student_id=calibration_data['student_id'],
            location=calibration_data['location'],
        )
    except Exception:
        error_msg = "Cannot get or create CalibrationRecord with "
        "student id {0} and location {1}.".format(
            calibration_data['student_id'], calibration_data['location'])
        log.exception(error_msg)
        return False, (error_msg)
    try:
        submission = Submission.objects.get(
            id=calibration_data['submission_id'])
    except Exception:
        error_msg = "Invalid submission id {0}.".format(
            calibration_data['submission_id'])
        log.exception(error_msg)
        return False, (error_msg)

    try:
        last_grader = submission.get_last_successful_instructor_grader()
        actual_score = last_grader['score']
        actual_rubric = last_grader['rubric']
        actual_feedback = last_grader['feedback']
    except Exception:
        error_msg = "Error getting actual score for submission id {0}.".format(
            calibration_data['submission_id'])
        log.exception(error_msg)
        return False, (error_msg)

    if actual_score == -1:
        error_msg = "No instructor graded submission for submission id {0}.".format(
            calibration_data['submission_id'])
        log.error(error_msg)
        return False, (error_msg)

    cal_record = CalibrationRecord(
        submission=submission,
        calibration_history=calibration_history,
        score=calibration_data['score'],
        actual_score=actual_score,
        feedback=calibration_data['feedback'],
        rubric_scores_complete=calibration_data['rubric_scores_complete'],
        rubric_scores=json.dumps(calibration_data['rubric_scores']),
    )

    cal_record.save()

    return True, {
        'cal_id': cal_record.id,
        'actual_score': actual_score,
        'actual_rubric': actual_rubric,
        'actual_feedback': actual_feedback
    }