Skip to content

Commit

Permalink
Annotation cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Dec 22, 2023
1 parent 62ee720 commit ebd05f5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 44 deletions.
1 change: 0 additions & 1 deletion install/crm/cidoc_rtfs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def import_cidoc() -> None:

# Classes
for code, class_ in classes.items():
print(code)
sql = """
INSERT INTO model.cidoc_class (code, name, comment)
VALUES (%(code)s, %(name)s, %(comment)s);"""
Expand Down
21 changes: 8 additions & 13 deletions openatlas/api/endpoints/iiif.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import math
import mimetypes
from typing import Any

import requests
from flask import jsonify, Response, url_for, g
from flask import Response, g, jsonify, url_for
from flask_restful import Resource
from shapely.geometry import Polygon

from openatlas.api.resources.model_mapper import get_entity_by_id
from openatlas.api.resources.util import get_license_name
Expand Down Expand Up @@ -173,27 +171,24 @@ def calculate_fragment_selector_coordinates(coordinates):
coordinates_list = list(map(float, coordinates_str.split(',')))

# Extracting x, y, width, and height from the coordinates
x_min, y_min, x_max, y_max = min(coordinates_list[::2]), min(coordinates_list[1::2]), max(coordinates_list[::2]), max(coordinates_list[1::2])
x_min, y_min,x_max, y_max = (
min(coordinates_list[::2]),
min(coordinates_list[1::2]),
max(coordinates_list[::2]),
max(coordinates_list[1::2]))
x = x_min
y = y_min
width = x_max - x_min
height = y_max - y_min

return x, y, width, height

def generate_selector(annotation):
print(annotation)
coordinates = [
float(coord) for coord in annotation['coordinates'].split(',')]

def generate_selector(annotation):
x, y, width, height = calculate_fragment_selector_coordinates(annotation)
print(x, y, width, height)
output = {
return {
"@type": "oa:FragmentSelector",
"value": f"xywh={x},{y},{width},{height}"}

return output


class IIIFManifest(Resource):
@staticmethod
Expand Down
29 changes: 15 additions & 14 deletions openatlas/api/routes.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from flask_restful import Api

from openatlas.api.endpoints.iiif import \
(IIIFManifest, IIIFImageV2, IIIFCanvasV2, IIIFSequenceV2, IIIFAnnotationV2,
IIIFAnnotationListV2)
from openatlas.api.endpoints.content import ClassMapping, \
SystemClassCount, GetBackendDetails
from openatlas.api.endpoints.special import GetGeometricEntities, \
ExportDatabase, GetSubunits
from openatlas.api.endpoints.display_image import \
(DisplayImage, LicensedFileOverview)
from openatlas.api.endpoints.entities import GetByCidocClass, \
GetBySystemClass, GetByViewClass, GetEntitiesLinkedToEntity, GetEntity, \
GetLatest, GetQuery, GetTypeEntities, GetTypeEntitiesAll
from openatlas.api.endpoints.type import \
(GetTypeByViewClass, GetTypeOverview, GetTypeTree)
from openatlas.api.endpoints.content import (
ClassMapping, GetBackendDetails, SystemClassCount)
from openatlas.api.endpoints.display_image import (
DisplayImage, LicensedFileOverview)
from openatlas.api.endpoints.entities import (
GetByCidocClass, GetBySystemClass, GetByViewClass,
GetEntitiesLinkedToEntity, GetEntity, GetLatest, GetQuery, GetTypeEntities,
GetTypeEntitiesAll)
from openatlas.api.endpoints.iiif import (
IIIFAnnotationListV2, IIIFAnnotationV2, IIIFCanvasV2, IIIFImageV2,
IIIFManifest, IIIFSequenceV2)
from openatlas.api.endpoints.special import (
ExportDatabase, GetGeometricEntities, GetSubunits)
from openatlas.api.endpoints.type import (
GetTypeByViewClass, GetTypeOverview, GetTypeTree)


def entity_routes(api: Api) -> None:
Expand Down
32 changes: 16 additions & 16 deletions openatlas/database/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class AnnotationImage:
def get_by_id(id_: int) -> Optional[dict[str, Any]]:
g.cursor.execute(
"""
SELECT
image_id,
entity_id,
coordinates,
user_id,
SELECT
image_id,
entity_id,
coordinates,
user_id,
annotation,
created
FROM web.annotation_image
WHERE id = %(id)s;
WHERE id = %(id)s;
""",
{'id': id_})
return dict(g.cursor.fetchone()) if g.cursor.rowcount else None
Expand All @@ -26,16 +26,16 @@ def get_by_id(id_: int) -> Optional[dict[str, Any]]:
def get_by_file(image_id: int) -> list[dict[str, Any]]:
g.cursor.execute(
"""
SELECT
SELECT
id,
image_id,
entity_id,
coordinates,
user_id,
image_id,
entity_id,
coordinates,
user_id,
annotation,
created
FROM web.annotation_image
WHERE image_id = %(image_id)s;
WHERE image_id = %(image_id)s;
""",
{'image_id': image_id})
return [dict(row) for row in g.cursor.fetchall()]
Expand All @@ -45,10 +45,10 @@ def insert(data: dict[str, Any]) -> None:
g.cursor.execute(
"""
INSERT INTO web.annotation_image (
image_id,
entity_id,
coordinates,
user_id,
image_id,
entity_id,
coordinates,
user_id,
annotation
) VALUES (
%(image_id)s,
Expand Down

0 comments on commit ebd05f5

Please sign in to comment.