Beispiel #1
0
def update_ratings(id_user, id_section, id_task, is_success):
    user = get_object_or_404(User, id=id_user)
    task = get_object_or_404(Task, id=id_task)
    section = get_object_or_404(Section, id=id_section)
    try:
        user_rating_in_section = get_object_or_404(UserRatingInSection, id_user=user, id_section=section)
    except:
        user_rating_in_section = UserRatingInSection(id_user=user, id_section=section, rating=1000)
        user_rating_in_section.save()
    old_user_rating = user_rating_in_section.rating
    task_in_section = get_object_or_404(TaskInSection, id_task=task, id_section=section)
    old_task_rating = task_in_section.rating
    submission_count = get_submission_count(user, task, section)
    user_factor = factor(old_user_rating, get_user_time_diff(user))
    task_factor = factor(old_task_rating, get_task_time_diff(task))
    user_exp_sc = user_expected_score(old_user_rating, old_task_rating)
    task_exp_sc = task_expected_score(old_user_rating, old_task_rating)
    if is_success:
        user_sc = user_score(submission_count)
        task_sc = task_score(submission_count)
    else:
        user_sc = 0
        task_sc = 1
    new_user_rating = new_rating(old_user_rating, user_factor, user_sc, user_exp_sc)
    new_task_rating = new_rating(old_task_rating, task_factor, task_sc, task_exp_sc)
    user_rating_in_section.rating = new_user_rating
    user_rating_in_section.save()
    task_in_section.rating = new_task_rating
    task_in_section.save()
    TaskRatingHistory(id_task=task,id_section=section, rating=new_task_rating).save()
    RatingHistory(id_user=user, id_section=section, rating=new_user_rating).save()
Beispiel #2
0
def section_page(request, section_id):
    test_tasks = {}
    task_id = []
    test_tasks_in_sect = TestTaskInSection.objects.all().filter(id_section=section_id)
    for i in test_tasks_in_sect:
        task_id.append(i.id_test_task)
    for i in task_id:
        task = get_object_or_404(TestTask, id=i.id)
        test_tasks[task_library.task_reader.get_task_html(task.id)] = task_library.task_reader.get_tutorial_html(
            task.id)
    context = {}
    context['test_tasks'] = test_tasks
    section = get_object_or_404(Section, id=section_id)
    context['section'] = section
    context['user_is_authenticated'] = request.user.is_authenticated()
    if request.user.is_authenticated():
        try:
            user_rating_in_section = get_object_or_404(UserRatingInSection, id_user = request.user, id_section = section_id)
        except:
            user_rating_in_section = UserRatingInSection(id_user=request.user, id_section=section, rating=1000)
            RatingHistory(id_user=request.user, id_section=section, rating=1000).save()
            user_rating_in_section.save()
        context['user_rating'] = user_rating_in_section.rating
        try:
            userPT = UserPickedTask.objects.get(id_user = request.user, id_section = section)
            context['button_name'] = 'Продолжить'
        except UserPickedTask.DoesNotExist:
            tasks_in_section = TaskInSection.objects.filter(id_section=section)
            tasks_in_section_id = set(tasks_in_section.values_list('id_task', flat=True))
            # user_submissions = Submission.objects.filter(id_user = request.user, id_section = section)
            user_closed_tasks = UserClosedTasks.objects.filter(id_user=request.user, id_section=section)
            solved_tasks_id = set(user_closed_tasks.values_list('id_task', flat=True))
            suitable_tasks_id = list(tasks_in_section_id - solved_tasks_id)
            user_rating = UserRatingInSection.objects.get(id_user=request.user, id_section=section).rating
            best_task, deviation = None, 10**10
            for task in tasks_in_section:
                current_deviation = task.rating - user_rating
                if task.id_task.id in suitable_tasks_id:
                    if abs(deviation) > abs(current_deviation):
                        best_task, deviation = task, current_deviation
                    elif abs(deviation) == abs(current_deviation) and current_deviation > 0:
                        best_task, deviation = task, current_deviation
            if len(suitable_tasks_id) == 0:
                context['no_tasks'] = True
            else: 
                context['button_name'] = 'Начать обучение'
        if request.POST:
            if context['button_name'] == 'Начать обучение':
                selected_task = best_task.id_task
                userPT = UserPickedTask(id_section = section, id_user = request.user, id_task = selected_task)
                userPT.save()
            return redirect('task_page', section_id, userPT.id_task.id)
        else: 
            return render(request, 'section_page/section_page.html', context)
    else:
        return render(request, 'section_page/section_page.html', context)
Beispiel #3
0
def update_ratings(id_user, id_section, id_task, is_success):
    user = get_object_or_404(User, id=id_user)
    task = get_object_or_404(Task, id=id_task)
    section = get_object_or_404(Section, id=id_section)
    try:
        user_rating_in_section = get_object_or_404(UserRatingInSection,
                                                   id_user=user,
                                                   id_section=section)
    except:
        user_rating_in_section = UserRatingInSection(id_user=user,
                                                     id_section=section,
                                                     rating=1000)
        user_rating_in_section.save()
    old_user_rating = user_rating_in_section.rating
    task_in_section = get_object_or_404(TaskInSection,
                                        id_task=task,
                                        id_section=section)
    old_task_rating = task_in_section.rating
    submission_count = get_submission_count(user, task, section)
    user_factor = factor(old_user_rating, get_user_time_diff(user))
    task_factor = factor(old_task_rating, get_task_time_diff(task))
    user_exp_sc = user_expected_score(old_user_rating, old_task_rating)
    task_exp_sc = task_expected_score(old_user_rating, old_task_rating)
    if is_success:
        user_sc = user_score(submission_count)
        task_sc = task_score(submission_count)
    else:
        user_sc = 0
        task_sc = 1
    new_user_rating = new_rating(old_user_rating, user_factor, user_sc,
                                 user_exp_sc)
    new_task_rating = new_rating(old_task_rating, task_factor, task_sc,
                                 task_exp_sc)
    user_rating_in_section.rating = new_user_rating
    user_rating_in_section.save()
    task_in_section.rating = new_task_rating
    task_in_section.save()
    TaskRatingHistory(id_task=task, id_section=section,
                      rating=new_task_rating).save()
    RatingHistory(id_user=user, id_section=section,
                  rating=new_user_rating).save()
Beispiel #4
0
def section_page(request, section_id):
    test_tasks = {}
    task_id = []
    test_tasks_in_sect = TestTaskInSection.objects.all().filter(
        id_section=section_id)
    for i in test_tasks_in_sect:
        task_id.append(i.id_test_task)
    for i in task_id:
        task = get_object_or_404(TestTask, id=i.id)
        test_tasks[task_library.task_reader.get_task_html(
            task.id)] = task_library.task_reader.get_tutorial_html(task.id)
    context = {}
    context['test_tasks'] = test_tasks
    section = get_object_or_404(Section, id=section_id)
    context['section'] = section
    context['user_is_authenticated'] = request.user.is_authenticated()
    if request.user.is_authenticated():
        try:
            user_rating_in_section = get_object_or_404(UserRatingInSection,
                                                       id_user=request.user,
                                                       id_section=section_id)
        except:
            user_rating_in_section = UserRatingInSection(id_user=request.user,
                                                         id_section=section,
                                                         rating=1000)
            RatingHistory(id_user=request.user,
                          id_section=section,
                          rating=1000).save()
            user_rating_in_section.save()
        context['user_rating'] = user_rating_in_section.rating
        try:
            userPT = UserPickedTask.objects.get(id_user=request.user,
                                                id_section=section)
            context['button_name'] = 'Продолжить'
        except UserPickedTask.DoesNotExist:
            tasks_in_section = TaskInSection.objects.filter(id_section=section)
            tasks_in_section_id = set(
                tasks_in_section.values_list('id_task', flat=True))
            # user_submissions = Submission.objects.filter(id_user = request.user, id_section = section)
            user_closed_tasks = UserClosedTasks.objects.filter(
                id_user=request.user, id_section=section)
            solved_tasks_id = set(
                user_closed_tasks.values_list('id_task', flat=True))
            suitable_tasks_id = list(tasks_in_section_id - solved_tasks_id)
            user_rating = UserRatingInSection.objects.get(
                id_user=request.user, id_section=section).rating
            best_task, deviation = None, 10**10
            for task in tasks_in_section:
                current_deviation = task.rating - user_rating
                if task.id_task.id in suitable_tasks_id:
                    if abs(deviation) > abs(current_deviation):
                        best_task, deviation = task, current_deviation
                    elif abs(deviation) == abs(
                            current_deviation) and current_deviation > 0:
                        best_task, deviation = task, current_deviation
            if len(suitable_tasks_id) == 0:
                context['no_tasks'] = True
            else:
                context['button_name'] = 'Начать обучение'
        if request.POST:
            if context['button_name'] == 'Начать обучение':
                selected_task = best_task.id_task
                userPT = UserPickedTask(id_section=section,
                                        id_user=request.user,
                                        id_task=selected_task)
                userPT.save()
            return redirect('task_page', section_id, userPT.id_task.id)
        else:
            return render(request, 'section_page/section_page.html', context)
    else:
        return render(request, 'section_page/section_page.html', context)