Esempio n. 1
0
def store_score(student, assessment_type, score):
    """Stores a student's score on a particular assessment.

    Args:
        student: the student whose data is stored.
        assessment_type: the type of the assessment.
        score: the student's score on this assessment.

    Returns:
        the (possibly modified) assessment_type, which the caller can
        use to render an appropriate response page.
    """
    # FIXME: Course creators can edit this code to implement custom
    # assessment scoring and storage behavior
    # TODO(pgbovine): Note that the latest version of answers are always saved,
    # but scores are only saved if they're higher than the previous attempt.
    # This can lead to unexpected analytics behavior. Resolve this.
    existing_score = utils.get_score(student, assessment_type)
    # remember to cast to int for comparison
    if (existing_score is None) or (score > int(existing_score)):
        utils.set_score(student, assessment_type, score)

    # special handling for computing final score:
    if assessment_type == 'postcourse':
        midcourse_score = utils.get_score(student, 'midcourse')
        if midcourse_score is None:
            midcourse_score = 0
        else:
            midcourse_score = int(midcourse_score)

        if existing_score is None:
            postcourse_score = score
        else:
            postcourse_score = int(existing_score)
            if score > postcourse_score:
                postcourse_score = score

        # Calculate overall score based on a formula
        overall_score = int((0.3 * midcourse_score) + (0.7 * postcourse_score))

        # TODO(pgbovine): this changing of assessment_type is ugly ...
        if overall_score >= 70:
            assessment_type = 'postcourse_pass'
        else:
            assessment_type = 'postcourse_fail'
        utils.set_score(student, 'overall_score', overall_score)

    return assessment_type
Esempio n. 2
0
def store_score(student, assessment_type, score):
    """Stores a student's score on a particular assessment.

    Args:
        student: the student whose data is stored.
        assessment_type: the type of the assessment.
        score: the student's score on this assessment.

    Returns:
        the (possibly modified) assessment_type, which the caller can
        use to render an appropriate response page.
    """
    # FIXME: Course creators can edit this code to implement custom
    # assessment scoring and storage behavior
    # TODO(pgbovine): Note that the latest version of answers are always saved,
    # but scores are only saved if they're higher than the previous attempt.
    # This can lead to unexpected analytics behavior. Resolve this.
    existing_score = utils.get_score(student, assessment_type)
    # remember to cast to int for comparison
    if (existing_score is None) or (score > int(existing_score)):
        utils.set_score(student, assessment_type, score)

    # special handling for computing final score:
    if assessment_type == 'postcourse':
        midcourse_score = utils.get_score(student, 'midcourse')
        if midcourse_score is None:
            midcourse_score = 0
        else:
            midcourse_score = int(midcourse_score)

        if existing_score is None:
            postcourse_score = score
        else:
            postcourse_score = int(existing_score)
            if score > postcourse_score:
                postcourse_score = score

        # Calculate overall score based on a formula
        overall_score = int((0.3 * midcourse_score) + (0.7 * postcourse_score))

        # TODO(pgbovine): this changing of assessment_type is ugly ...
        if overall_score >= 70:
            assessment_type = 'postcourse_pass'
        else:
            assessment_type = 'postcourse_fail'
        utils.set_score(student, 'overall_score', overall_score)

    return assessment_type
Esempio n. 3
0
def calc_total_score(student):
    #
    mn = MODULE_QUESTIONS
#    mm = MANDATORY_MODULES
    #
    overall_score = -1
    ms = []
    for i in range(1,MAX_MODULES+1):
      course = 'a'+str(i)+'course'  
      ms.append(utils.get_score(student, course))

    # get profile for this user - mandatary modules
    valid = ValidStudent.get_valid(student.key().name())
    prof = Profile.get_by_key_name(valid.profile)
    auth = eval(prof.auth)

    # complete = mandatory modules are done (have scores)
    complete = True
    i = 0
    for score in ms[:MAX_MODULES]:
	if auth[i]:
	    complete = complete and (score <> None)    
        i += 1
    # compute overall score after mandatory modules are done
    if complete:
        part_score = 0
        tq = 0
	for i in range(MAX_MODULES):
	  if ms[i] <> None:
	    part_score +=  mn[i] * ms[i]
	    tq += mn[i]
# todo - somar 0.5 antes do int?
        overall_score = int((part_score/tq)+0.5)

    return overall_score
Esempio n. 4
0
    def post(self):
        """Handles POST requests."""
        student = self.personalize_page_and_get_enrolled()
        if not student:
            return

        if not self.assert_xsrf_token_or_fail(self.request, 'assessment-post'):
            return

        assessment_type = self.request.get('assessment_type')

        # Convert answers from JSON to dict.
        answers = self.request.get('answers')
        if answers:
            answers = json.loads(answers)
        else:
            answers = []

        # TODO(pgbovine): consider storing as float for better precision
        score = int(round(float(self.request.get('score'))))

        # Record score.
        (student, assessment_type) = self.update_assessment_transaction(
            student.key().name(), assessment_type, answers, score)

        self.template_value['navbar'] = {'course': True}
        self.template_value['assessment'] = assessment_type
#        self.template_value['end_date'] = '26 May 2013'
        self.template_value['student_score'] = utils.get_score(
            student, 'overall_score')
        self.render('test_confirmation.html')
Esempio n. 5
0
    def post(self):
        """Handles POST requests."""
        student = self.personalize_page_and_get_enrolled()
        if not student:
            return

        if not self.assert_xsrf_token_or_fail(self.request, 'assessment-post'):
            return

        assessment_type = self.request.get('assessment_type')

        # Convert answers from JSON to dict.
        answers = self.request.get('answers')
        if answers:
            answers = json.loads(answers)
        else:
            answers = []

        # TODO(pgbovine): consider storing as float for better precision
        score = int(round(float(self.request.get('score'))))

        # Record score.
        (student, assessment_type) = self.update_assessment_transaction(
            student.key().name(), assessment_type, answers, score)

        self.template_value['navbar'] = {'course': True}
        self.template_value['assessment'] = assessment_type
        self.template_value['student_score'] = utils.get_score(
            student, 'overall_score')
        self.render('test_confirmation.html')
Esempio n. 6
0
    def test_assessments(self):
        """Test assessment scores are properly submitted and summarized."""
        email = '*****@*****.**'
        name = 'Test Assessments'

        pre_answers = [{'foo': 'bar'}, {'Alice': 'Bob'}]
        pre = {
            'assessment_type': 'precourse', 'score': '1.00',
            'answers': json.dumps(pre_answers)}
        mid = {'assessment_type': 'midcourse', 'score': '2.00'}
        post = {'assessment_type': 'postcourse', 'score': '3.00'}
        second_mid = {'assessment_type': 'midcourse', 'score': '1.00'}
        second_post = {'assessment_type': 'postcourse', 'score': '100000'}

        # Register.
        actions.login(email)
        actions.register(self, name)

        old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace(self.namespace)
        try:
            # Check that no scores exist right now.
            student = models.Student.get_enrolled_student_by_email(email)
            assert len(get_all_scores(student)) == 0  # pylint: disable=C6411

            # Submit assessments and check the numbers of scores recorded.
            self.submit_assessment('Pre', pre)
            student = models.Student.get_enrolled_student_by_email(email)
            assert len(get_all_scores(student)) == 1

            self.submit_assessment('Mid', mid)
            student = models.Student.get_enrolled_student_by_email(email)
            assert len(get_all_scores(student)) == 2

            self.submit_assessment('Post', post)
            student = models.Student.get_enrolled_student_by_email(email)

            # Check final score also includes overall_score.
            assert len(get_all_scores(student)) == 4

            # Check assessment answers.
            answers = json.loads(
                models.StudentAnswersEntity.get_by_key_name(
                    student.user_id).data)
            assert pre_answers == answers['precourse']

            # pylint: disable-msg=g-explicit-bool-comparison
            assert [] == answers['midcourse']
            assert [] == answers['postcourse']
            # pylint: enable-msg=g-explicit-bool-comparison

            # Check that scores are recorded properly.
            student = models.Student.get_enrolled_student_by_email(email)
            assert int(get_score(student, 'precourse')) == 1
            assert int(get_score(student, 'midcourse')) == 2
            assert int(get_score(student, 'postcourse')) == 3
            assert (int(get_score(student, 'overall_score')) ==
                    int((0.30 * 2) + (0.70 * 3)))

            # Try posting a new midcourse exam with a lower score;
            # nothing should change.
            self.submit_assessment('Mid', second_mid)
            student = models.Student.get_enrolled_student_by_email(email)
            assert int(get_score(student, 'precourse')) == 1
            assert int(get_score(student, 'midcourse')) == 2
            assert int(get_score(student, 'postcourse')) == 3
            assert (int(get_score(student, 'overall_score')) ==
                    int((0.30 * 2) + (0.70 * 3)))

            # Now try posting a postcourse exam with a higher score and note
            # the changes.
            self.submit_assessment('Post', second_post)
            student = models.Student.get_enrolled_student_by_email(email)
            assert int(get_score(student, 'precourse')) == 1
            assert int(get_score(student, 'midcourse')) == 2
            assert int(get_score(student, 'postcourse')) == 100000
            assert (int(get_score(student, 'overall_score')) ==
                    int((0.30 * 2) + (0.70 * 100000)))
        finally:
            namespace_manager.set_namespace(old_namespace)
Esempio n. 7
0
def store_score(course, student, assessment_name, assessment_type,score):
    """Stores a student's score on a particular assessment.

    Args:
        course: the course containing the assessment.
        student: the student whose data is stored.
        assessment_type: the type of the assessment.
        score: the student's score on this assessment.

    Returns:
        the result of the assessment, if appropriate.
    """
    # FIXME: Course creators can edit this code to implement custom
    # assessment scoring and storage behavior
    # TODO(pgbovine): Note that the latest version of answers are always saved,
    # but scores are only saved if they're higher than the previous attempt.
    # This can lead to unexpected analytics behavior. Resolve this.
    existing_score = course.get_score(student, assessment_name)
    # remember to cast to int for comparison
    
#    logging.error('assessment name : %s  exist score : %s score %s ',assessment_name,existing_score, score)

    if assessment_name != 'postcourse':
        if (existing_score is None) or (score > int(existing_score)):
            utils.set_score(student, assessment_name, score)

    # special handling for computing final score:
    if assessment_name == 'postcourse':
#        midcourse_score = utils.get_score(student, 'midcourse')
#        if midcourse_score is None:
#            midcourse_score = 0
#        else:
#            midcourse_score = int(midcourse_score)

        if existing_score is None:
            postcourse_score = score
        else:
            postcourse_score = int(existing_score)
            if score > postcourse_score:
                postcourse_score = score

        # Calculate overall score based on a formula
        overall_score = calc_total_score(student)
#        logging.error('overall_score : %s ', overall_score)

#	if utils.get_score(student, 'postcourse') == 0 and (overall_score > -1) :
#          utils.set_score(student, 'postcourse', overall_score)
#          utils.set_score(student, 'overall_score', overall_score)

        # TODO(pgbovine): this changing of assessment_type is ugly ...

        if overall_score == 100:
            assessment_name = 'postcourse_100'
	else:
	  if overall_score >= 90:
            assessment_name = 'postcourse_pass'
          else:
	    if overall_score > 0:
                assessment_name = 'postcourse_fail'
	    else:
	        assessment_name = 'not_complete'
#        utils.set_score(student, 'overall_score', overall_score)

        # store the overall_score of the first run of training in post_course 
#	post_s=  utils.get_score(student, 'postcourse')
#        logging.error('postcourse : %s ', utils.get_score(student, 'postcourse'))
	if utils.get_score(student, 'postcourse') == None and (overall_score > -1):
          utils.set_score(student, 'postcourse', overall_score)
          utils.set_score(student, 'overall_score', overall_score)
	  
    over_s=  utils.get_score(student, 'overall_score')
    if over_s <> None:
      overall_score = calc_total_score(student)
      utils.set_score(student, 'overall_score', overall_score)


    return assessment_name
Esempio n. 8
0
    def test_assessments(self):
        """Test assessment scores are properly submitted and summarized."""
        email = '*****@*****.**'
        name = 'Test Assessments'

        pre_answers = [{'foo': 'bar'}, {'Alice': u'Bob (тест данные)'}]
        pre = {
            'assessment_type': 'precourse', 'score': '1.00',
            'answers': json.dumps(pre_answers)}
        mid = {'assessment_type': 'midcourse', 'score': '2.00'}
        post = {'assessment_type': 'postcourse', 'score': '3.00'}
        second_mid = {'assessment_type': 'midcourse', 'score': '1.00'}
        second_post = {'assessment_type': 'postcourse', 'score': '100000'}

        # Register.
        actions.login(email)
        actions.register(self, name)

        old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace(self.namespace)
        try:
            # Check that no scores exist right now.
            student = models.Student.get_enrolled_student_by_email(email)
            assert len(get_all_scores(student)) == 0  # pylint: disable=C6411

            # Submit assessments and check the numbers of scores recorded.
            self.submit_assessment('Pre', pre)
            student = models.Student.get_enrolled_student_by_email(email)
            assert len(get_all_scores(student)) == 1

            self.submit_assessment('Mid', mid)
            student = models.Student.get_enrolled_student_by_email(email)
            assert len(get_all_scores(student)) == 2

            self.submit_assessment('Post', post)
            student = models.Student.get_enrolled_student_by_email(email)

            # Check final score also includes overall_score.
            assert len(get_all_scores(student)) == 4

            # Check assessment answers.
            answers = json.loads(
                models.StudentAnswersEntity.get_by_key_name(
                    student.user_id).data)
            assert pre_answers == answers['precourse']

            # pylint: disable-msg=g-explicit-bool-comparison
            assert [] == answers['midcourse']
            assert [] == answers['postcourse']
            # pylint: enable-msg=g-explicit-bool-comparison

            # Check that scores are recorded properly.
            student = models.Student.get_enrolled_student_by_email(email)
            assert int(get_score(student, 'precourse')) == 1
            assert int(get_score(student, 'midcourse')) == 2
            assert int(get_score(student, 'postcourse')) == 3
            assert (int(get_score(student, 'overall_score')) ==
                    int((0.30 * 2) + (0.70 * 3)))

            # Try posting a new midcourse exam with a lower score;
            # nothing should change.
            self.submit_assessment('Mid', second_mid)
            student = models.Student.get_enrolled_student_by_email(email)
            assert int(get_score(student, 'precourse')) == 1
            assert int(get_score(student, 'midcourse')) == 2
            assert int(get_score(student, 'postcourse')) == 3
            assert (int(get_score(student, 'overall_score')) ==
                    int((0.30 * 2) + (0.70 * 3)))

            # Now try posting a postcourse exam with a higher score and note
            # the changes.
            self.submit_assessment('Post', second_post)
            student = models.Student.get_enrolled_student_by_email(email)
            assert int(get_score(student, 'precourse')) == 1
            assert int(get_score(student, 'midcourse')) == 2
            assert int(get_score(student, 'postcourse')) == 100000
            assert (int(get_score(student, 'overall_score')) ==
                    int((0.30 * 2) + (0.70 * 100000)))
        finally:
            namespace_manager.set_namespace(old_namespace)