Пример #1
0
    def post(self, request, format=None):
        annotation_id = request.POST.get('annotationId', None)
        age = request.POST.get('ageGroup', None)
        gender = request.POST.get('gender', None)
        newSubjectId = request.POST.get('newSubjectId', None)
        person_album = None
        if newSubjectId and newSubjectId != '':
            person_album = Album.objects.filter(pk=newSubjectId).first()
        new_rectangle = FaceRecognitionRectangle.objects.get(pk=annotation_id)
        if (person_album and len(
                AlbumPhoto.objects.filter(photo=new_rectangle.photo,
                                          album=person_album)) < 1):
            albumPhoto = AlbumPhoto(album=person_album,
                                    photo=new_rectangle.photo,
                                    type=AlbumPhoto.FACE_TAGGED,
                                    profile=request.user.profile)
            albumPhoto.save()
            person_album.set_calculated_fields()
            person_album.save()

        additional_subject_data = AddAdditionalSubjectData(
            subject_rectangle_id=annotation_id,
            age=age,
            gender=gender,
            newSubjectId=newSubjectId)

        return self.add_subject_data(
            additional_subject_data=additional_subject_data, request=request)
def add_subject_data(new_face_annotation_id,
                     add_detection_annotation: AddDetectionAnnotation,
                     request: HttpRequest):
    is_gender_sent = add_detection_annotation.gender is not None and add_detection_annotation.gender < GENDER_NOT_SURE
    is_age_sent = add_detection_annotation.age_group is not None and add_detection_annotation.age_group < AGE_NOT_SURE

    if is_gender_sent or is_age_sent:
        add_additional_subject_data = AddAdditionalSubjectData(
            subject_rectangle_id=new_face_annotation_id,
            age=add_detection_annotation.age_group,
            gender=add_detection_annotation.gender)

        AddSubjectData.add_subject_data(add_additional_subject_data, request)
Пример #3
0
    def post(self, request, format=None):
        subject_id = request.POST.get('annotationId', None)
        age = request.POST.get('ageGroup', None)
        gender = request.POST.get('gender', None)
        newSubjectId = request.POST.get('newSubjectId', None)

        additional_subject_data = AddAdditionalSubjectData(
            subject_rectangle_id=subject_id,
            age=age,
            gender=gender,
            newSubjectId=newSubjectId)

        return self.add_subject_data(
            additional_subject_data=additional_subject_data, request=request)
def update_user_guesses(http_request: HttpRequest, annotation_id: int, update_request: FaceAnnotationUpdateRequest):
    user_guess = get_existing_user_additional_data_guess(
        guesser=AddSubjectData.get_profile(http_request),
        annotation_id=annotation_id
    )

    has_age_guess = update_request.new_age_guess is not None and update_request.new_age_guess != AGE_NOT_SURE
    has_gender_guess = \
        update_request.new_gender_guess is not None and update_request.new_gender_guess != GENDER_NOT_SURE

    if user_guess is None and (has_age_guess or has_gender_guess):
        add_additional_subject_data = AddAdditionalSubjectData(
            subject_rectangle_id=annotation_id,
            age=update_request.new_age_guess,
            gender=update_request.new_gender_guess
        )
        AddSubjectData.add_subject_data(add_additional_subject_data, http_request)
    elif user_guess.gender != update_request.new_gender_guess or user_guess.age != update_request.new_age_guess:
        user_guess.age = update_request.new_age_guess
        user_guess.gender = update_request.new_gender_guess
        user_guess.save()
def add_gender_and_age_feedback(
        user: Profile,
        face_annotation: FaceRecognitionRectangle,
        request: FaceAnnotationFeedbackRequest,
        http_request: HttpRequest
):
    existing_additional_data_guess = get_existing_user_additional_data_guess(user, face_annotation.id)

    age = None if request.is_correct_age else request.alternative_age
    gender = None if request.is_correct_gender else request.alternative_gender

    if existing_additional_data_guess is None:
        add_additional_subject_data = AddAdditionalSubjectData(
            subject_rectangle_id=face_annotation.id,
            age=age,
            gender=gender
        )
        AddSubjectData.add_subject_data(add_additional_subject_data, http_request)
    else:
        existing_additional_data_guess.age = age
        existing_additional_data_guess.gender = gender
        existing_additional_data_guess.save()
Пример #6
0
def update_user_suggestions(http_request: HttpRequest, annotation_id: int,
                            update_request: FaceAnnotationUpdateRequest):
    user_suggestion = get_existing_user_additional_data_suggestion(
        proposer=AddSubjectData.get_profile(http_request),
        annotation_id=annotation_id)

    has_age_suggestion = update_request.new_age_suggestion and update_request.new_age_suggestion != AGE_NOT_SURE
    has_gender_suggestion = \
        update_request.new_gender_suggestion is not None and update_request.new_gender_suggestion != GENDER_NOT_SURE

    if user_suggestion is None and (has_age_suggestion
                                    or has_gender_suggestion):
        add_additional_subject_data = AddAdditionalSubjectData(
            subject_rectangle_id=annotation_id,
            age=update_request.new_age_suggestion,
            gender=update_request.new_gender_suggestion)
        AddSubjectData.add_subject_data(add_additional_subject_data,
                                        http_request)
    elif user_suggestion.gender != update_request.new_gender_suggestion \
            or user_suggestion.age != update_request.new_age_suggestion:
        user_suggestion.age = update_request.new_age_suggestion
        user_suggestion.gender = update_request.new_gender_suggestion
        user_suggestion.save()