Skip to content

Commit

Permalink
[AJP-2]
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Grund authored and Anna Grund committed Sep 27, 2023
1 parent 9a10e06 commit a1ee575
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/ajapaik/settings/local.py
/ajapaik/settings/local.py
/ajapaik/settings/test.py

/media/
Expand Down
8 changes: 1 addition & 7 deletions ajapaik/ajapaik/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ class FrontpagePagingForm(forms.Form):


class ApiAlbumNearestPhotosForm(forms.Form):
print("HERE")
id = forms.ModelChoiceField(queryset=Album.objects.filter(is_public=True), required=False)
latitude = forms.FloatField(min_value=-85.05115, max_value=85)
longitude = forms.FloatField(min_value=-180, max_value=180)
Expand All @@ -325,7 +324,6 @@ class ApiAlbumNearestPhotosForm(forms.Form):


class ApiFinnaNearestPhotosForm(forms.Form):
print("HERE")
id = forms.ModelChoiceField(queryset=Album.objects.filter(is_public=True), required=False)
latitude = forms.FloatField(min_value=-85.05115, max_value=85)
longitude = forms.FloatField(min_value=-180, max_value=180)
Expand All @@ -337,22 +335,19 @@ class ApiFinnaNearestPhotosForm(forms.Form):


class ApiAlbumStateForm(forms.Form):
print("HERE")
id = forms.ModelChoiceField(queryset=Album.objects.filter(is_public=True))
state = forms.CharField(max_length=255, required=False)
start = forms.IntegerField(required=False)
limit = forms.IntegerField(required=False)


class ApiAlbumSourceForm(forms.Form):
print("HERE")
query = forms.CharField(max_length=255, required=True)
start = forms.IntegerField(required=False)
limit = forms.IntegerField(required=False)


class ApiPhotoUploadForm(forms.Form):
print("HERE")
id = forms.CharField(max_length=255)
latitude = forms.FloatField(min_value=-85.05115, max_value=85, required=False)
longitude = forms.FloatField(min_value=-180, max_value=180, required=False)
Expand Down Expand Up @@ -461,8 +456,6 @@ def clean_images(self):
if not images:
raise forms.ValidationError(_('At least one image file is required.'))

# Additional validation for image files can be added here if needed.

return images

def clean(self):
Expand All @@ -473,6 +466,7 @@ def clean(self):
if not self.cleaned_data.get('uploader_is_author') and not self.cleaned_data.get('licence'):
self.errors['licence'] = [_('Missing licence')]


class UserPhotoUploadAddAlbumForm(forms.ModelForm):
location = forms.CharField(max_length=255, required=False)

Expand Down
21 changes: 0 additions & 21 deletions ajapaik/ajapaik/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,27 +2075,6 @@ class PhotoViewpointElevationSuggestion(Suggestion):
on_delete=CASCADE)


# TODO: to be deleted
class PhotoModelSuggestionConfirmReject(Suggestion):
INTERIOR, EXTERIOR = range(2)
GROUND_LEVEL, RAISED, AERIAL = range(3)
SCENE_CHOICES = (
(INTERIOR, _('Interior')),
(EXTERIOR, _('Exterior'))
)
VIEWPOINT_ELEVATION_CHOICES = (
(GROUND_LEVEL, _('Ground')),
(RAISED, _('Raised')),
(AERIAL, _('Aerial'))
)
viewpoint_elevation_to_confirm = PositiveSmallIntegerField(_('Viewpoint elevation'), choices=VIEWPOINT_ELEVATION_CHOICES, blank=True, null=True)
scene_to_confirm = PositiveSmallIntegerField(_('Scene'), choices=SCENE_CHOICES, blank=True, null=True)

viewpoint_elevation_to_reject = PositiveSmallIntegerField(_('Viewpoint elevation'), choices=VIEWPOINT_ELEVATION_CHOICES, blank=True, null=True)
scene_to_reject = PositiveSmallIntegerField(_('Scene'), choices=SCENE_CHOICES, blank=True, null=True)

proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_scene_suggestions_confirmation', on_delete=CASCADE)

class PhotoModelSuggestionResult(Suggestion):
INTERIOR, EXTERIOR = range(2)
GROUND_LEVEL, RAISED, AERIAL = range(3)
Expand Down
114 changes: 29 additions & 85 deletions ajapaik/ajapaik/static/js/ajp-picture-category-retrival.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getPictureCategoryCategories(photoId, callback) {
var onSuccess = function (response) {
function getImageCategory(photoId, callback) {
let onSuccess = function (response) {
callback(determinePictureCategory(response.data));
};
getRequest(
Expand All @@ -11,8 +11,32 @@ function getPictureCategoryCategories(photoId, callback) {
);
}

function determinePictureCategory(responseData) {
let responseDict = {};
for (let i = 0; i < responseData.length; i++) {
let data = responseData[i];
let fields = data["fields"];
if ("scene" in fields) {
if (fields["scene"] === 0) {
responseDict["scene"] = "interior";
} else {
responseDict["scene"] = "exterior";
}
}
if ("viewpoint_elevation" in fields) {
if (fields["viewpoint_elevation"] === 0) {
responseDict["viewpoint_elevation"] = "ground";
} else if (fields["viewpoint_elevation"] === 1) {
responseDict["viewpoint_elevation"] = "raised";
} else if (fields["viewpoint_elevation"] === 2) {
responseDict["viewpoint_elevation"] = "areal";
}
}
}
return responseDict;
}

function sendCategoryFeedback(photoId, category, categoryValue) {
console.log("Persisting category alternation to db")
let payload = {
"photo_id": photoId
};
Expand All @@ -23,7 +47,7 @@ function sendCategoryFeedback(photoId, category, categoryValue) {
} else if (categoryValue === "exterior") {
payload["scene_to_alternate"] = 1
}
} else if (category === "view-point") {
} else if (category === "view-point-elevation") {
if (categoryValue === "ground") {
payload["viewpoint_elevation_to_alternate"] = 0
} else if (categoryValue === "raised") {
Expand All @@ -33,54 +57,7 @@ function sendCategoryFeedback(photoId, category, categoryValue) {
}
}

var onSuccess = function () {
console.log("It was a success!")
};

postRequest(
'/object-categorization/confirm-latest-category',
payload,
constants.translations.queries.POST_CATEGORY_CONFIRMATION_SUCCESS,
constants.translations.queries.POST_CATEGORY_CONFIRMATION_FAILED,
onSuccess
);
}

//TODO: to remove
function sendCategoryConfirmation(photoId, category, categoryValue, confirm) {


console.log("categoryValue")
console.log(categoryValue)

var payload = {
"photo_id": photoId
// "viewpoint_elevation_to_confirm": 1,
// "scene_to_confirm": 1,
// "viewpoint_elevation_to_reject": 1,
// "scene_to_reject": 1
}

if (category === "scene") {
if (categoryValue === "interior") {
confirm === 1 ? payload["scene_to_confirm"] = 0 : payload["scene_to_reject"] = 0
} else if (categoryValue === "exterior") {
confirm === 1 ? payload["scene_to_confirm"] = 1 : payload["scene_to_reject"] = 1
}
} else if (category === "view-point") {
if (categoryValue === "ground") {
confirm === 1 ? payload["viewpoint_elevation_to_confirm"] = 0 : payload["viewpoint_elevation_to_reject"] = 0
} else if (categoryValue === "raised") {
confirm === 1 ? payload["viewpoint_elevation_to_confirm"] = 1 : payload["viewpoint_elevation_to_reject"] = 1
} else {
confirm === 1 ? payload["viewpoint_elevation_to_confirm"] = 2 : payload["viewpoint_elevation_to_reject"] = 2
}
}

console.log("PALYLOAD")
console.log(payload)

var onSuccess = function () {
const onSuccess = function () {
console.log("It was a success!")
};

Expand All @@ -91,37 +68,4 @@ function sendCategoryConfirmation(photoId, category, categoryValue, confirm) {
constants.translations.queries.POST_CATEGORY_CONFIRMATION_FAILED,
onSuccess
);
console.log(photoId);
console.log(category);
console.log(confirm);
}

function determinePictureCategory(responseData) {
var responseDict = {}
var category;

for (let i = 0; i < responseData.length; i++) {
var data = responseData[i]
var model = data["model"];
if (model === "ajapaik.photomodelsuggestionresult") {
category = data["fields"]["scene"]
if (category === 0) {
responseDict["scene"] = "interior";
} else {
responseDict["scene"] = "exterior";
}
}
if (model === "ajapaik.photoviewpointelevationsuggestion") {
category = data["fields"]["viewpoint_elevation"]
if (category === 0) {
responseDict["viewpoint_elevation"] = "ground";
} else if (category === 1) {
responseDict["viewpoint_elevation"] = "raised";
} else {
responseDict["viewpoint_elevation"] = "areal";
}
}

}
return responseDict;
}
Loading

0 comments on commit a1ee575

Please sign in to comment.