Ejemplo n.º 1
0
def create_context_review(request):
    data = {}
    if "id" in request.GET:
        user = RequestContext(request)["user"]
        challenge = Challenge.objects.get(pk=request.GET.get("id"))
        if not challenge.is_enabled_for_user(user):
            raise Http404
        if challenge.has_enough_user_reviews(user):
            raise Http404
        if not challenge.submitted_by_user(user):
            raise Http404
        review = Review.get_open_review(challenge, user)
        if not review:
            # number of hours needed to pass until elaboration is applicable as candidate
            offset = randint(ReviewConfig.get_candidate_offset_min(), ReviewConfig.get_candidate_offset_max())
            review_candidate = Elaboration.get_review_candidate(challenge, user, offset)
            if review_candidate:
                review = Review(elaboration=review_candidate, reviewer=user)
                review.save()
            else:
                return data
        data["review"] = review
        data["stack_id"] = challenge.get_stack().id
        review_questions = ReviewQuestion.objects.filter(challenge=challenge).order_by("order")
        data["questions"] = review_questions
    return data
Ejemplo n.º 2
0
def create_context_review(request):
    data = {}
    if 'id' in request.GET:
        user = RequestContext(request)['user']
        challenge = Challenge.objects.get(pk=request.GET.get('id'))
        if not challenge.is_enabled_for_user(user):
            raise Http404
        if challenge.has_enough_user_reviews(user):
            raise Http404
        if not challenge.submitted_by_user(user):
            raise Http404
        review = Review.get_open_review(challenge, user)
        if not review:
            # number of hours needed to pass until elaboration is applicable as candidate
            offset = randint(ReviewConfig.get_candidate_offset_min(),
                             ReviewConfig.get_candidate_offset_max())
            review_candidate = Elaboration.get_review_candidate(
                challenge, user, offset)
            if review_candidate:
                review = Review(elaboration=review_candidate, reviewer=user)
                review.save()
            else:
                return data
        data['review'] = review
        data['stack_id'] = challenge.get_stack().id
        review_questions = ReviewQuestion.objects.filter(
            challenge=challenge).order_by("order")
        data['questions'] = review_questions
    return data
Ejemplo n.º 3
0
    def get_random_review_candidate(challenge, user):
        # Wait x hours before making elaborations available for review
        offset = randint(ReviewConfig.get_candidate_offset_min(),
                         ReviewConfig.get_candidate_offset_max())
        threshold = datetime.now() - timedelta(hours=offset)

        # Exclude elaborations the user has already submitted a review for
        already_submitted_reviews_ids = (Review.objects.filter(
            reviewer=user,
            elaboration__challenge=challenge).values_list('elaboration__id',
                                                          flat=True))

        # Get all possible candidates, ignore treshold for now because we need
        # to fall back to a random elaboration if no elaboration is old enough
        candidates = (Elaboration.objects.filter(
            challenge=challenge,
            submission_time__isnull=False,
            user__is_staff=False).annotate(
                num_reviews=Count('review')).exclude(user=user).exclude(
                    id__in=already_submitted_reviews_ids)
                      ).order_by('num_reviews')

        # Separate candidates
        old_enough_candidates, newer_candidates = [], []
        for candidate in candidates:
            old_enough_candidates.append(
                candidate
            ) if candidate.submission_time < threshold else newer_candidates.append(
                candidate)

        if len(old_enough_candidates) > 0:
            chosen_candidate = old_enough_candidates[0]
        elif len(newer_candidates) > 0:
            chosen_candidate = newer_candidates[0]
        else:
            # Fall back to dummy elaborations
            candidates = (Elaboration.objects.filter(
                challenge=challenge, submission_time__isnull=False).annotate(
                    num_reviews=Count('review')).exclude(user=user).exclude(
                        id__in=already_submitted_reviews_ids)
                          ).order_by('num_reviews')
            chosen_candidate = candidates[0]

        return {'chosen_by': 'random', 'candidate': chosen_candidate}
Ejemplo n.º 4
0
    def get_random_review_candidate(challenge, user):
        # Wait x hours before making elaborations available for review
        offset = randint(ReviewConfig.get_candidate_offset_min(), ReviewConfig.get_candidate_offset_max())
        threshold = datetime.now() - timedelta(hours=offset)

        # Exclude elaborations the user has already submitted a review for
        already_submitted_reviews_ids = (
            Review.objects
            .filter(reviewer=user, elaboration__challenge=challenge)
            .values_list('elaboration__id', flat=True)
        )

        # Get all possible candidates, ignore treshold for now because we need
        # to fall back to a random elaboration if no elaboration is old enough
        candidates = (
            Elaboration.objects
            .filter(challenge=challenge, submission_time__isnull=False, user__is_staff=False)
            .annotate(num_reviews=Count('review'))
            .exclude(user=user)
            .exclude(id__in=already_submitted_reviews_ids)
        ).order_by('num_reviews')


        # Separate candidates
        old_enough_candidates, newer_candidates = [], []
        for candidate in candidates:
            old_enough_candidates.append(candidate) if candidate.submission_time < threshold else newer_candidates.append(candidate)

        if len(old_enough_candidates) > 0:
            chosen_candidate = old_enough_candidates[0]
        elif len(newer_candidates) > 0:
            chosen_candidate = newer_candidates[0]
        else:
            # Fall back to dummy elaborations
            candidates = (
                Elaboration.objects
                .filter(challenge=challenge, submission_time__isnull=False)
                .annotate(num_reviews=Count('review'))
                .exclude(user=user)
                .exclude(id__in=already_submitted_reviews_ids)
            ).order_by('num_reviews')
            chosen_candidate = candidates[0]

        return { 'chosen_by': 'random', 'candidate': chosen_candidate }
Ejemplo n.º 5
0
def import_all():
    """
    To import everything, there have to be some files present:
    courses are hardcoded
    tutors in /tmp/tutors.csv
    students have to be in /tmp/<coursename>.csv (i.e. bhci.csv and gsi.csv)

    when files are placed correctly call:
    python manage.py import_all
    """
    print("import all")
    print("Import Review Config")
    ReviewConfig.setup()
    print("Import Comments Config")
    CommentsConfig.setup()
    print("Comments Config Imported")
    call_command('import_courses')
    call_command('import_tutors')
    call_command('import_students')
    call_command('import_faq')
    call_command('import_chapters')
Ejemplo n.º 6
0
 def test_review_config_offset(self):
     assert ReviewConfig.get_candidate_offset_min() == 0
     assert ReviewConfig.get_candidate_offset_max() == 0
     ReviewConfig(candidate_offset_min=1, candidate_offset_max=2).save()
     assert ReviewConfig.get_candidate_offset_min() == 1
     assert ReviewConfig.get_candidate_offset_max() == 2
Ejemplo n.º 7
0
 def test_review_config_offset(self):
     assert ReviewConfig.get_candidate_offset_min() == 0
     assert ReviewConfig.get_candidate_offset_max() == 0
     ReviewConfig(candidate_offset_min=1, candidate_offset_max=2).save()
     assert ReviewConfig.get_candidate_offset_min() == 1
     assert ReviewConfig.get_candidate_offset_max() == 2