Esempio n. 1
0
def attempt_problem_pop(user_data, user_exercise, attempt_number,
    completed, count_hints, time_taken, attempt_content, module,   
    ex_question, ip_address, request_post):
    
    data = request_post.get('code') 
    
    generatedList =request_post.get('genlist')
    
    progexType =request_post.get('progexType')
   
    checkDefinedvar= request_post.get('checkdefvar')

    if checkDefinedvar == "True":
       listoftypes= request_post.get('listoftypes')
    else : 
       listoftypes=""
    # Clean the strings from bad characters
    
    #listoftypes = ''.join([x for x in listoftypes if ord(x) < 128])

    data = ''.join([x for x in data if ord(x) < 128])

    # Summary Programming Exercises so we need to get the current selected exercise name to run the eqivelant unit test
    if request_post.get('summexname')  != 'null':
       exerciseName = request_post.get('summexname')

    else:
        exerciseName = request_post.get('sha1')
    
    feedback, pathtouserFiles= setparameters(exerciseName, data, generatedList, checkDefinedvar , listoftypes , progexType, user_data)

    if  os.path.exists(pathtouserFiles ):
        shutil.rmtree(pathtouserFiles)
     
    if user_exercise:   # and user_exercise.belongs_to(user_data):
        dt_now = datetime.datetime.now()
        #exercise = user_exercise.exercise
        user_exercise.last_done = dt_now
        # Build up problem log for deferred put
        problem_log = models.UserExerciseLog(
                user=user_data.user,
                exercise=user_exercise.exercise,
                time_taken=time_taken,
                time_done=dt_now,
                count_hints=count_hints,
                hint_used=int(count_hints) > 0,
                correct=feedback[0],
                count_attempts=attempt_number,
                ex_question=ex_question,
                ip_address=ip_address,
        )


        first_response = (attempt_number == 1 and count_hints == 0) or (count_hints == 1 and attempt_number == 0)

        if user_exercise.total_done > 0 and user_exercise.streak == 0 and first_response:
            bingo('hints_keep_going_after_wrong')

        just_earned_proficiency = False
        #update list of started exercises
        if not user_data.has_started(user_exercise.exercise):
            user_data.started(user_exercise.exercise.id)

        proficient = user_data.is_proficient_at(user_exercise.exercise)
        #if str2bool(completed):

        user_exercise.total_done += 1
        if problem_log.correct:

                # Streak only increments if problem was solved correctly (on first attempt)
           user_exercise.total_correct += 1
           user_exercise.streak += 1
           user_exercise.longest_streak = max(user_exercise.longest_streak, user_exercise.streak)
           user_exercise.progress = Decimal(user_exercise.streak)/Decimal(user_exercise.exercise.streak)
           if not proficient:
              problem_log.earned_proficiency = user_exercise.update_proficiency_ka(correct=True,ubook=user_data.book)
              if user_exercise.progress >= 1:
                 if len(user_data.all_proficient_exercises)==0:
                    user_data.all_proficient_exercises += "%s" %user_exercise.exercise.id
                 else:
                    user_data.all_proficient_exercises += ",%s" %user_exercise.exercise.id
           else:
             user_exercise.total_done += 1
             user_exercise.progress = Decimal(user_exercise.streak)/Decimal(user_exercise.exercise.streak)
    
        # Saving student's code and the feedback received
       
        problem_log.save()
        user_exercise.save()
        user_data.save()
        if proficient or problem_log.earned_proficiency:
            update_module_proficiency(user_data, module, user_exercise.exercise)
        userprog_log = models.UserProgLog(
               problem_log= problem_log ,
               student_code= data,
               feedback=feedback[1],
              )
 
        userprog_log.save()
        return user_exercise,feedback
def attempt_problem_pop(user_data, user_exercise, attempt_number,
    completed, count_hints, time_taken, attempt_content, module,   
    ex_question, ip_address, request_post):
    
    data = request_post.get('code') 
    generatedList =request_post.get('genlist')
    # Will have here a check from which programming exercise we got this request
    # Temp: will use generated list --- if it has binarytree not a list then call the binary tree
    if generatedList == "Binarytree" :
       feedback= assesskaexbintree (data)
    else : # should have many else and if here by time 
       feedback= assesskaex(data , generatedList)

    if user_exercise:   # and user_exercise.belongs_to(user_data):
        dt_now = datetime.datetime.now()
        #exercise = user_exercise.exercise
        user_exercise.last_done = dt_now
        # Build up problem log for deferred put
        problem_log = models.UserExerciseLog(
                user=user_data.user,
                exercise=user_exercise.exercise,
                time_taken=time_taken,
                time_done=dt_now,
                count_hints=count_hints,
                hint_used=int(count_hints) > 0,
                correct=feedback[0],
                count_attempts=attempt_number,
                ex_question=ex_question,
                ip_address=ip_address,
        )


        first_response = (attempt_number == 1 and count_hints == 0) or (count_hints == 1 and attempt_number == 0)

        if user_exercise.total_done > 0 and user_exercise.streak == 0 and first_response:
            bingo('hints_keep_going_after_wrong')

        just_earned_proficiency = False
        #update list of started exercises
        if not user_data.has_started(user_exercise.exercise):
            user_data.started(user_exercise.exercise.id)

        proficient = user_data.is_proficient_at(user_exercise.exercise)
        #if str2bool(completed):

        user_exercise.total_done += 1
        if problem_log.correct:

                # Streak only increments if problem was solved correctly (on first attempt)
           user_exercise.total_correct += 1
           user_exercise.streak += 1
           user_exercise.longest_streak = max(user_exercise.longest_streak, user_exercise.streak)
           user_exercise.progress = Decimal(user_exercise.streak)/Decimal(user_exercise.exercise.streak)
           if not proficient:
              problem_log.earned_proficiency = user_exercise.update_proficiency_ka(correct=True,ubook=user_data.book)
              if user_exercise.progress >= 1:
                 if len(user_data.all_proficient_exercises)==0:
                    user_data.all_proficient_exercises += "%s" %user_exercise.exercise.id
                 else:
                    user_data.all_proficient_exercises += ",%s" %user_exercise.exercise.id
           else:
             user_exercise.total_done += 1
             user_exercise.progress = Decimal(user_exercise.streak)/Decimal(user_exercise.exercise.streak)
        #else:
            #if (int(count_hints) ==0) and (attempt_content!='hint') and (int(attempt_number) == 1):
            # Only count wrong answer at most once per problem
             #  if user_exercise.streak - 1 > 0:
             #      user_exercise.streak = user_exercise.streak - 1
             #  else:
             #      user_exercise.streak = 0
            #user_exercise.progress = Decimal(user_exercise.streak)/Decimal(user_exercise.exercise.streak)
            #if first_response:
            #       user_exercise.update_proficiency_model(correct=False)

        problem_log.save()
        user_exercise.save()
        user_data.save()
        if proficient or problem_log.earned_proficiency:
            update_module_proficiency(user_data, module, user_exercise.exercise)

       
        return user_exercise,feedback     #, user_exercise_graph, goals_updated
Esempio n. 3
0
def attempt_problem_pop(
    user_data,
    user_exercise,
    attempt_number,
    completed,
    count_hints,
    time_taken,
    attempt_content,
    module,
    ex_question,
    ip_address,
    request_post,
):

    data = request_post.get("code")
    generatedList = request_post.get("genlist")
    # Will have here a check from which programming exercise we got this request
    # Temp: will use generated list --- if it has binarytree not a list then call the binary tree
    if generatedList == "Binarytree":
        feedback = assesskaexbintree(data)
    else:  # should have many else and if here by time
        feedback = assesskaex(data, generatedList)

    if user_exercise:  # and user_exercise.belongs_to(user_data):
        dt_now = datetime.datetime.now()
        # exercise = user_exercise.exercise
        user_exercise.last_done = dt_now
        # Build up problem log for deferred put
        problem_log = models.UserExerciseLog(
            user=user_data.user,
            exercise=user_exercise.exercise,
            time_taken=time_taken,
            time_done=dt_now,
            count_hints=count_hints,
            hint_used=int(count_hints) > 0,
            correct=feedback[0],
            count_attempts=attempt_number,
            ex_question=ex_question,
            ip_address=ip_address,
        )

        first_response = (attempt_number == 1 and count_hints == 0) or (count_hints == 1 and attempt_number == 0)

        if user_exercise.total_done > 0 and user_exercise.streak == 0 and first_response:
            bingo("hints_keep_going_after_wrong")

        just_earned_proficiency = False
        # update list of started exercises
        if not user_data.has_started(user_exercise.exercise):
            user_data.started(user_exercise.exercise.id)

        proficient = user_data.is_proficient_at(user_exercise.exercise)
        # if str2bool(completed):

        user_exercise.total_done += 1
        if problem_log.correct:

            # Streak only increments if problem was solved correctly (on first attempt)
            user_exercise.total_correct += 1
            user_exercise.streak += 1
            user_exercise.longest_streak = max(user_exercise.longest_streak, user_exercise.streak)
            user_exercise.progress = Decimal(user_exercise.streak) / Decimal(user_exercise.exercise.streak)
            if not proficient:
                problem_log.earned_proficiency = user_exercise.update_proficiency_ka(correct=True, ubook=user_data.book)
                if user_exercise.progress >= 1:
                    if len(user_data.all_proficient_exercises) == 0:
                        user_data.all_proficient_exercises += "%s" % user_exercise.exercise.id
                    else:
                        user_data.all_proficient_exercises += ",%s" % user_exercise.exercise.id
            else:
                user_exercise.total_done += 1
                user_exercise.progress = Decimal(user_exercise.streak) / Decimal(user_exercise.exercise.streak)
        # else:
        # if (int(count_hints) ==0) and (attempt_content!='hint') and (int(attempt_number) == 1):
        # Only count wrong answer at most once per problem
        #  if user_exercise.streak - 1 > 0:
        #      user_exercise.streak = user_exercise.streak - 1
        #  else:
        #      user_exercise.streak = 0
        # user_exercise.progress = Decimal(user_exercise.streak)/Decimal(user_exercise.exercise.streak)
        # if first_response:
        #       user_exercise.update_proficiency_model(correct=False)

        problem_log.save()
        user_exercise.save()
        user_data.save()
        if proficient or problem_log.earned_proficiency:
            update_module_proficiency(user_data, module, user_exercise.exercise)

        return user_exercise, feedback  # , user_exercise_graph, goals_updated
Esempio n. 4
0
def attempt_problem_pop(user_data, user_exercise, attempt_number, completed,
                        count_hints, time_taken, attempt_content, module,
                        ex_question, ip_address, request_post):

    data = request_post.get('code')

    generatedList = request_post.get('genlist')

    progexType = request_post.get('progexType')

    checkDefinedvar = request_post.get('checkdefvar')

    if checkDefinedvar == "True":
        listoftypes = request_post.get('listoftypes')
    else:
        listoftypes = ""
    # Clean the strings from bad characters

    #listoftypes = ''.join([x for x in listoftypes if ord(x) < 128])

    data = ''.join([x for x in data if ord(x) < 128])

    # Summary Programming Exercises so we need to get the current selected exercise name to run the eqivelant unit test
    if request_post.get('summexname') != 'null':
        exerciseName = request_post.get('summexname')

    else:
        exerciseName = request_post.get('sha1')

    feedback, pathtouserFiles = setparameters(exerciseName, data,
                                              generatedList, checkDefinedvar,
                                              listoftypes, progexType,
                                              user_data)

    if os.path.exists(pathtouserFiles):
        shutil.rmtree(pathtouserFiles)

    if user_exercise:  # and user_exercise.belongs_to(user_data):
        dt_now = datetime.datetime.now()
        #exercise = user_exercise.exercise
        user_exercise.last_done = dt_now
        # Build up problem log for deferred put
        problem_log = models.UserExerciseLog(
            user=user_data.user,
            exercise=user_exercise.exercise,
            time_taken=time_taken,
            time_done=dt_now,
            count_hints=count_hints,
            hint_used=int(count_hints) > 0,
            correct=feedback[0],
            count_attempts=attempt_number,
            ex_question=ex_question,
            ip_address=ip_address,
        )

        first_response = (attempt_number == 1
                          and count_hints == 0) or (count_hints == 1
                                                    and attempt_number == 0)

        if user_exercise.total_done > 0 and user_exercise.streak == 0 and first_response:
            bingo('hints_keep_going_after_wrong')

        just_earned_proficiency = False
        #update list of started exercises
        if not user_data.has_started(user_exercise.exercise):
            user_data.started(user_exercise.exercise.id)

        proficient = user_data.is_proficient_at(user_exercise.exercise)
        #if str2bool(completed):

        user_exercise.total_done += 1
        if problem_log.correct:

            # Streak only increments if problem was solved correctly (on first attempt)
            user_exercise.total_correct += 1
            user_exercise.streak += 1
            user_exercise.longest_streak = max(user_exercise.longest_streak,
                                               user_exercise.streak)
            user_exercise.progress = Decimal(user_exercise.streak) / Decimal(
                user_exercise.exercise.streak)
            if not proficient:
                problem_log.earned_proficiency = user_exercise.update_proficiency_ka(
                    correct=True, ubook=user_data.book)
                if user_exercise.progress >= 1:
                    if len(user_data.all_proficient_exercises) == 0:
                        user_data.all_proficient_exercises += "%s" % user_exercise.exercise.id
                    else:
                        user_data.all_proficient_exercises += ",%s" % user_exercise.exercise.id
            else:
                user_exercise.total_done += 1
                user_exercise.progress = Decimal(
                    user_exercise.streak) / Decimal(
                        user_exercise.exercise.streak)

        # Saving student's code and the feedback received

        problem_log.save()
        user_exercise.save()
        user_data.save()
        if proficient or problem_log.earned_proficiency:
            update_module_proficiency(user_data, module,
                                      user_exercise.exercise)
        userprog_log = models.UserProgLog(
            problem_log=problem_log,
            student_code=data,
            feedback=feedback[1],
        )

        userprog_log.save()
        return user_exercise, feedback