-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anna Grund
authored and
Anna Grund
committed
Oct 14, 2023
1 parent
ef7a0a7
commit f5b285f
Showing
10 changed files
with
349 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...paik_object_categorization/service/object_categorization/object_categorization_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import json | ||
|
||
from django.http import HttpRequest | ||
|
||
from ajapaik.ajapaik.models import Photo, PhotoModelSuggestionResult, \ | ||
PhotoModelSuggestionAlternativeCategory | ||
from django.core import serializers | ||
import datetime | ||
|
||
|
||
def get_latest_category_from_result_table(photo_id=None): | ||
result = PhotoModelSuggestionResult.objects.filter(photo_id=photo_id).order_by('-created') | ||
result_categories = [] | ||
|
||
if result.exists(): | ||
categories = serializers.serialize('python', result) | ||
result_categories.append(categories) | ||
return categories | ||
return result_categories | ||
|
||
|
||
def get_uncategorized_photos(): | ||
photos = Photo.objects.filter(scene=None, viewpoint_elevation=None).values_list('id', 'user', 'image') | ||
|
||
photos_without_results = [] | ||
for photo in photos: | ||
if not PhotoModelSuggestionResult.objects.filter(photo_id=photo[0]).exists(): | ||
photos_without_results.append(photo) | ||
|
||
return photos_without_results | ||
|
||
|
||
def post_image_category_result_table(request: HttpRequest): | ||
result = PhotoModelSuggestionResult() | ||
data = json.loads(request.body) | ||
|
||
result.viewpoint_elevation = data.get("verdict_view_point_elevation", None) | ||
result.scene = data.get("verdict_scene", None) | ||
result.photo_id = data.get("photo_id", None) | ||
result.save() | ||
return result | ||
|
||
|
||
def aggregate_category_data(): | ||
one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7) | ||
|
||
alternative_category = PhotoModelSuggestionAlternativeCategory.objects.filter(created__gte=one_week_ago).order_by( | ||
'-created') | ||
|
||
result_categories = {} | ||
|
||
if alternative_category.exists(): | ||
confirm_reject_dict = serializers.serialize('python', alternative_category) | ||
result_categories['alternative_category_data'] = confirm_reject_dict | ||
|
||
return result_categories | ||
|
||
|
||
class UncategorizedPhoto: | ||
def __init__(self, image_id, user_id, image_name): | ||
self.image_id = image_id | ||
self.user_id = user_id | ||
self.image_name = image_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.conf.urls import url | ||
|
||
from ajapaik.ajapaik_object_categorization import views | ||
|
||
urlpatterns = [ | ||
url(r'^get-latest-category/(?P<photo_id>\d+)/$', views.get_latest_category_from_result_table, | ||
name='picture_recognition_get_latest_category'), | ||
url(r'^confirm-latest-category', views.propose_alternative_category, | ||
name='picture_recognition_get_latest_category'), | ||
url(r'^publish-picture-category-result', views.post_image_category_result_table, | ||
name='publish_picture_category_result'), | ||
url(r'aggregate-category-data', views.aggregate_category_data, | ||
name='aggregate_category_data'), | ||
url(r'get-uncategorized-images', views.get_uncategorized_photos, | ||
name='get_uncategorized_images') | ||
] |
Oops, something went wrong.