Ejemplo n.º 1
0
def generate_rubric_object(grader, scores, rubric_xml):
    success, max_scores=generate_targets_from_rubric(rubric_xml)
    if not success:
        return False, "Could not parse rubric XML to extract max scores."
    for i in xrange(0,len(scores)):
        score=scores[i]
        try:
            score=int(score)
        except:
            return False, "Scores must be numeric."
        if score<0:
            return False, "Scores cannot be below zero. : {0}".format(score)
        if score>max_scores[i]:
            return False, "Score: {0} is greater than max score for this item: {1}".format(score, max_scores[i])

    try:
        rubric=Rubric(
            grader=grader,
            rubric_version=RUBRIC_VERSION,
            finished_scoring=True,
        )
        rubric.save()
        success, rubric_items=parse_rubric(rubric_xml)
        if not success:
            return False, "Could not parsed rubric items properly: {0}".format(rubric_items)
        if len(scores)!=len(rubric_items):
            return False, "Length of passed in scores: {0} does not match number of rubric items: {1}".format(len(scores), len(rubric_items))

        for i in xrange(0,len(rubric_items)):
            rubric_item=rubric_items[i]
            description = rubric_item['description']
            options = rubric_item['options']

            text=description
            score=scores[i]
            max_score=len(options)

            rubric_item=RubricItem(
                rubric=rubric,
                text=text,
                score=score,
                item_number=i,
                max_score=max_score,
                finished_scoring=True,
            )
            rubric_item.save()
            for z in xrange(0,len(options)):
                option=options[z]
                rubric_option=RubricOption(
                    points=z,
                    text = option,
                    item_number=z,
                    rubric_item=rubric_item,
                )
                rubric_option.save()
        return True, rubric
    except:
        error_message="Could not save and/or parse rubric properly"
        log.info(error_message)
        return False, error_message
Ejemplo n.º 2
0
def create_rubric_objects(rubric_data, request):
    """
    For a given user and problem id, create a local rubric object
    rubric_data - the dictionary data associated with the rubric
    request - the request that the user has made
    """
    #Create the rubric
    rubric = Rubric(associated_problem = int(rubric_data['problem_id']), user = request.user)
    rubric.save()
    #Create each rubric option
    for option in rubric_data['options']:
        option = RubricOption(rubric=rubric, option_points =option['points'], option_text = option['text'])
        option.save()
Ejemplo n.º 3
0
def create_rubric_objects(rubric_data, request):
    """
    For a given user and problem id, create a local rubric object
    rubric_data - the dictionary data associated with the rubric
    request - the request that the user has made
    """
    # Create the rubric
    rubric = Rubric(associated_problem=int(rubric_data['problem_id']), user=request.user)
    rubric.save()
    # Create each rubric option
    for option in rubric_data['options']:
        option = RubricOption(rubric=rubric, option_points=option['points'], option_text=option['text'])
        option.save()
Ejemplo n.º 4
0
def generate_rubric_object(grader, scores, rubric_xml):
    success, max_scores = generate_targets_from_rubric(rubric_xml)
    if not success:
        error_message = "Could not parse rubric XML to extract max scores."
        log.error(error_message)
        return False, error_message
    for i in xrange(0, len(scores)):
        score = scores[i]
        try:
            score = int(score)
        except Exception:
            error_message = "Scores must be numeric."
            log.exception(error_message)
            return False, error_message
        if score < 0:
            error_message = "Scores cannot be below zero. : {0}".format(score)
            log.error(error_message)
            return False, error_message
        if score > max_scores[i]:
            return False, "Score: {0} is greater than max score for this item: {1}".format(
                score, max_scores[i])

    try:
        rubric = Rubric(
            grader=grader,
            rubric_version=RUBRIC_VERSION,
            finished_scoring=True,
        )
        rubric.save()
        success, rubric_items = parse_rubric(rubric_xml)
        if not success:
            error_message = "Could not parse rubric items properly: {0}".format(
                rubric_items)
            log.error(error_message)
            return False, error_message
        if len(scores) != len(rubric_items):
            error_message = "Length of passed in scores: {0} does not match number of rubric items: {1}".format(
                len(scores), len(rubric_items))
            log.error(error_message)
            return False, error_message

        for i in xrange(0, len(rubric_items)):
            rubric_item = rubric_items[i]
            description = rubric_item['description']
            options = rubric_item['options']

            text = description
            score = scores[i]
            max_score = len(options)

            rubric_item = RubricItem(
                rubric=rubric,
                text=text,
                score=score,
                item_number=i,
                max_score=max_score,
                finished_scoring=True,
            )
            rubric_item.save()
            for z in xrange(0, len(options)):
                option = options[z]
                rubric_option = RubricOption(
                    points=z,
                    text=option,
                    item_number=z,
                    rubric_item=rubric_item,
                )
                rubric_option.save()
        return True, rubric
    except Exception:
        error_message = "Could not save and/or parse rubric properly"
        log.error(error_message)
        return False, error_message