Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rossum_api/clients/external_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ async def retrieve_annotation_processing_duration(
"GET",
Comment thread
stancld marked this conversation as resolved.
build_resource_processing_duration_url(Resource.Annotation, annotation_id),
)
return AnnotationProcessingDuration(**data)
return self._deserializer(Resource.AnnotationProcessingDuration, data)

# ##### DOCUMENTS #####
async def retrieve_document(self, document_id: int) -> DocumentType:
Expand Down
2 changes: 1 addition & 1 deletion rossum_api/clients/external_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def retrieve_annotation_processing_duration(
"GET",
build_resource_processing_duration_url(Resource.Annotation, annotation_id),
)
return AnnotationProcessingDuration(**data)
return self._deserializer(Resource.AnnotationProcessingDuration, data)

# ##### DOCUMENTS #####

Expand Down
1 change: 1 addition & 0 deletions rossum_api/domain_logic/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Resource(Enum):
"""

Annotation = "annotations"
AnnotationProcessingDuration = "annotations/processing_duration"
Auth = "auth"
Connector = "connectors"
Document = "documents"
Expand Down
3 changes: 2 additions & 1 deletion rossum_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import dacite

from rossum_api.domain_logic.resources import Resource
from rossum_api.models.annotation import Annotation
from rossum_api.models.annotation import Annotation, AnnotationProcessingDuration
from rossum_api.models.connector import Connector
from rossum_api.models.document import Document
from rossum_api.models.document_relation import DocumentRelation
Expand Down Expand Up @@ -42,6 +42,7 @@

RESOURCE_TO_MODEL = {
Resource.Annotation: Annotation,
Resource.AnnotationProcessingDuration: AnnotationProcessingDuration,
Resource.Connector: Connector,
Resource.Document: Document,
Resource.DocumentRelation: DocumentRelation,
Expand Down
8 changes: 8 additions & 0 deletions rossum_api/models/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class AnnotationProcessingDuration:
Time spent on emails in seconds.
time_spent_opening
Time spent opening the annotation in seconds.
duration_latest_validate_started
Duration of the latest validate call with ``started`` action after opening
the annotation, in seconds. Can be None.
duration_latest_validate_updated_before_confirm
Duration of the latest validate call with ``updated`` action before
confirmation of the annotation, in seconds. Can be None.

References
----------
Expand All @@ -43,6 +49,8 @@ class AnnotationProcessingDuration:
time_spent_blockers: float
time_spent_emails: float
time_spent_opening: float
duration_latest_validate_started: float | None
duration_latest_validate_updated_before_confirm: float | None


@dataclass
Expand Down
30 changes: 30 additions & 0 deletions tests/elis_api_client/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def dummy_annotation_processing_duration():
"time_spent_blockers": 2.34,
"time_spent_emails": 3.45,
"time_spent_opening": 4.56,
"duration_latest_validate_started": 5.67,
"duration_latest_validate_updated_before_confirm": 6.78,
}


Expand Down Expand Up @@ -473,6 +475,20 @@ async def test_retrieve_annotation_processing_duration(
"GET", f"{Resource.Annotation.value}/{aid}/processing_duration"
)

async def test_retrieve_annotation_processing_duration_ignores_unknown_fields(
self, elis_client, dummy_annotation, dummy_annotation_processing_duration
):
client, http_client = elis_client
data_with_extra = {**dummy_annotation_processing_duration, "unexpected_field": 99.9}
http_client.request_json.return_value = data_with_extra

aid = dummy_annotation["id"]
processing_duration = await client.retrieve_annotation_processing_duration(aid)

assert processing_duration == AnnotationProcessingDuration(
**dummy_annotation_processing_duration
)


class TestAnnotationsSync:
def test_list_annotations(self, elis_client_sync, dummy_annotation):
Expand Down Expand Up @@ -792,3 +808,17 @@ def test_retrieve_annotation_processing_duration(
http_client.request_json.assert_called_with(
"GET", f"{Resource.Annotation.value}/{aid}/processing_duration"
)

def test_retrieve_annotation_processing_duration_ignores_unknown_fields(
self, elis_client_sync, dummy_annotation, dummy_annotation_processing_duration
):
client, http_client = elis_client_sync
data_with_extra = {**dummy_annotation_processing_duration, "unexpected_field": 99.9}
http_client.request_json.return_value = data_with_extra

aid = dummy_annotation["id"]
processing_duration = client.retrieve_annotation_processing_duration(aid)

assert processing_duration == AnnotationProcessingDuration(
**dummy_annotation_processing_duration
)