Exemplo n.º 1
0
def close_review(review: Review, session) -> Review:
    review.status = "closed"
    review.finish_timestamp = helper.get_date_time_now()
    user_handler.give_experience_point(review.user_id, session)

    pair = review_pair_handler.get_review_pair_from_review(review, session)
    partner_review = get_partner_review(review, session)

    if partner_review != None and partner_review.status == 'closed':

        difference = review_pair_handler.compute_difference(pair)
        pair.variance = difference
        pair.is_good = True if difference <= 1 else False

        review.item.in_progress_reviews_level_1 -= 1
        review.item.in_progress_reviews_level_2 -= 1
        if pair.is_good:
            review.item.open_reviews -= 1
            review.item.open_reviews_level_1 -= 1
            review.item.open_reviews_level_2 -= 1

        pairs = review_pair_handler.get_review_pairs_by_item(
            pair.item_id, session)

        if(len(list(filter(lambda p: p.is_good, pairs))) >= 4):
            review.item.status = "closed"
            review.item.close_timestamp = review.finish_timestamp
            review.item.result_score = item_handler.compute_item_result_score(
                review.item_id, session)

    update_object(review, session)
    update_object(pair, session)
    update_object(review.item, session)

    return review
Exemplo n.º 2
0
def new_senior_review(item):
    rip2 = Review()
    rip2.id = str(uuid4())
    rip2.start_timestamp = datetime.now()
    rip2.is_peer_review = True
    rip2.status = "in_progress"
    rip2.item_id = item.id
    return rip2
Exemplo n.º 3
0
def old_junior_review(item):
    rip1 = Review()
    rip1.id = str(uuid4())
    rip1.start_timestamp = datetime.now() + timedelta(hours=-2)
    rip1.is_peer_review = False
    rip1.status = "in_progress"
    rip1.item_id = item.id
    return rip1
Exemplo n.º 4
0
def create_review(user, item, is_test, session) -> Review:
    """Accepts an item for review

    Parameters
    ----------
    user: User
        The user that reviews the item
    item: Item
        The item to be reviewed by the user

    Returns
    ------
    item: Item
        The case to be assigned to the user
    """
    # If a ReviewInProgress exists for the user, return
    session = get_db_session(is_test, session)

    try:
        review = session.query(Review).filter(Review.user_id == user.id,
                                              Review.status == "in_progress",
                                              Review.item_id == item.id).one()
        return review
    except:
        pass

    # If the amount of reviews in progress equals the amount of reviews needed, raise an error
    if item.in_progress_reviews_level_1 >= item.open_reviews_level_1:
        if user.level_id > 1:
            if item.in_progress_reviews_level_2 >= item.open_reviews_level_2:
                raise Exception(
                    'Item cannot be accepted since enough other detecitves are already working on the case'
                )
        else:
            raise Exception(
                'Item cannot be accepted since enough other detecitves are already working on the case'
            )
    # Create a new ReviewInProgress
    rip = Review()
    rip.id = str(uuid4())
    rip.item_id = item.id
    rip.user_id = user.id
    rip.start_timestamp = helper.get_date_time_now(is_test)
    rip.status = "in_progress"
    session.add(rip)
    session.commit()

    # If a user is a senior, the review will by default be a senior review,
    # except if no senior reviews are needed
    if user.level_id > 1 and item.open_reviews_level_2 > item.in_progress_reviews_level_2:
        rip.is_peer_review = True
        item.in_progress_reviews_level_2 = item.in_progress_reviews_level_2 + 1

        # Check if a pair with open senior review exists
        pair_found = False
        for pair in item.review_pairs:
            if pair.senior_review_id == None:
                pair.senior_review_id = rip.id
                pair_found = True
                session.merge(pair)
                break

        # Create new pair, if review cannot be attached to existing pair
        if pair_found == False:
            pair = ReviewPair()
            pair.id = str(uuid4())
            pair.senior_review_id = rip.id
            item.review_pairs.append(pair)
            session.merge(pair)

    # If review is junior review
    else:
        rip.is_peer_review = False
        item.in_progress_reviews_level_1 = item.in_progress_reviews_level_1 + 1

        # Check if a pair with open junior review exists
        pair_found = False
        for pair in item.review_pairs:
            if pair.junior_review_id == None:
                pair.junior_review_id = rip.id
                pair_found = True
                session.merge(pair)
                break

        # Create new pair, if review cannot be attached to existing pair
        if pair_found == False:
            pair = ReviewPair()
            pair.id = str(uuid4())
            pair.junior_review_id = rip.id
            item.review_pairs.append(pair)
            session.merge(pair)

    session.merge(rip)
    session.merge(item)
    session.commit()
    rip = create_answers_for_review(rip, is_test, session)
    return rip
def test_get_review(item_id, review_id, review_question_id, user_id, tag_id,
                    item_tag_id, monkeypatch):
    """
    Gets a simple Review
    """
    monkeypatch.setenv("CORS_ALLOW_ORIGIN", "http://localhost:4200")

    with Session() as session:

        item = Item()
        item.id = item_id

        user = User()
        user.id = user_id

        level = Level(id=1)

        review = Review()
        review.id = review_id
        review.item_id = item.id
        review.user_id = user.id
        review.status = 'in_progress'

        tag = Tag(tag='test', id=tag_id)
        item_tag = ItemTag(id=item_tag_id,
                           item_id=item_id,
                           tag_id=tag_id,
                           review_id=review_id)

        comment = Comment(id='comment_id',
                          comment='testcomment',
                          review_id=review_id,
                          is_review_comment=True)

        review_question = ReviewQuestion()
        review_question.id = review_question_id
        review_question.content = "Question content"
        review_question.info = "Question info"
        review_question.hint = "Question hint"

        o1 = AnswerOption(id="1", text="Option 1", value=0)
        o2 = AnswerOption(id="2",
                          text="Option 2",
                          value=1,
                          tooltip="Tooltip 2")
        o3 = AnswerOption(id="3", text="Option 3", value=2)
        o4 = AnswerOption(id="4", text="Option 4", value=3)

        o1.questions = [review_question]
        o2.questions = [review_question]
        o4.questions = [review_question]
        o3.questions = [review_question]

        # all answers use the same review questions in order to keep the test data small
        reviewanswer1 = generate_review_answer(1, review_id,
                                               review_question_id)
        reviewanswer2 = generate_review_answer(0, review_id,
                                               review_question_id)
        reviewanswer3 = generate_review_answer(1, review_id,
                                               review_question_id)
        reviewanswer4 = generate_review_answer(3, review_id,
                                               review_question_id)
        reviewanswer5 = generate_review_answer(2, review_id,
                                               review_question_id)
        reviewanswer6 = generate_review_answer(1, review_id,
                                               review_question_id)
        reviewanswer7 = generate_review_answer(2, review_id,
                                               review_question_id)
        review.review_answers = [
            reviewanswer1, reviewanswer2, reviewanswer3, reviewanswer4,
            reviewanswer5, reviewanswer6, reviewanswer7
        ]

        session.add(item)
        session.add(user)
        session.add(level)
        session.add(review_question)
        session.add_all([tag, item_tag, comment])
        # referenced ReviewAnswers are stored as well
        session.add(review)

        session.commit()

        event = event_creator.get_get_review_event(user_id, review_id)

        resp = get_review(event, None)

        status = resp["statusCode"]
        assert status == 200

        body = json.loads(resp["body"])
        assert body["id"] == review_id

        assert len(body["questions"]) == 7
        assert body["questions"][0]["answer_id"] != None
        assert body["questions"][0]["question_id"] != None
        assert body["questions"][0]["parent_question_id"] == None
        assert body["questions"][0]["max_children"] == None
        assert body["questions"][0]["content"] != None
        assert body["questions"][0]["info"] != None
        assert body["questions"][0]["hint"] != None
        assert body["questions"][0]["answer_value"] == 1
        assert len(body["questions"][0]["options"]) == 4
        assert body["questions"][0]["options"][0]["text"] != None
        assert body["questions"][0]["options"][0]["value"] == 0
        assert body["questions"][0]["options"][1]["tooltip"] != None

        assert 'tags' in body
        assert len(body['tags']) == 1
        assert body['tags'][0] == 'test'

        assert 'comment' in body
        assert body['comment'] == 'testcomment'