Skip to content
Snippets Groups Projects
Verified Commit db4bacb7 authored by Yoann Schneider's avatar Yoann Schneider :tennis:
Browse files

Use helper to retrieve ID

parent af3ec31f
No related branches found
No related tags found
1 merge request!18Fix worker_run/version IDs
Pipeline #145093 passed with warnings
...@@ -11,7 +11,7 @@ from typing import List, Optional ...@@ -11,7 +11,7 @@ from typing import List, Optional
from uuid import UUID from uuid import UUID
from apistar.exceptions import ErrorResponse from apistar.exceptions import ErrorResponse
from arkindex_export import Element, open_database from arkindex_export import Element, WorkerRun, WorkerVersion, open_database
from arkindex_export.queries import list_children from arkindex_export.queries import list_children
from arkindex_worker.cache import ( from arkindex_worker.cache import (
CachedClassification, CachedClassification,
...@@ -32,6 +32,7 @@ from arkindex_worker.models import Dataset ...@@ -32,6 +32,7 @@ from arkindex_worker.models import Dataset
from arkindex_worker.models import Element as WorkerElement from arkindex_worker.models import Element as WorkerElement
from arkindex_worker.utils import create_tar_zst_archive from arkindex_worker.utils import create_tar_zst_archive
from arkindex_worker.worker import DatasetWorker from arkindex_worker.worker import DatasetWorker
from peewee import CharField
from worker_generic_training_dataset.db import ( from worker_generic_training_dataset.db import (
list_classifications, list_classifications,
list_transcription_entities, list_transcription_entities,
...@@ -50,6 +51,10 @@ def _format_element(element: WorkerElement) -> Element: ...@@ -50,6 +51,10 @@ def _format_element(element: WorkerElement) -> Element:
return retrieve_element(element.id) return retrieve_element(element.id)
def get_object_id(instance: WorkerVersion | WorkerRun | None) -> CharField | None:
return instance.id if instance else None
class DatasetExtractor(DatasetWorker): class DatasetExtractor(DatasetWorker):
def configure(self) -> None: def configure(self) -> None:
self.args: Namespace = self.parser.parse_args() self.args: Namespace = self.parser.parse_args()
...@@ -147,9 +152,7 @@ class DatasetExtractor(DatasetWorker): ...@@ -147,9 +152,7 @@ class DatasetExtractor(DatasetWorker):
class_name=classification.class_name, class_name=classification.class_name,
confidence=classification.confidence, confidence=classification.confidence,
state=classification.state, state=classification.state,
worker_run_id=classification.worker_run.id worker_run_id=get_object_id(classification.worker_run),
if classification.worker_run
else None,
) )
for classification in list_classifications(element.id) for classification in list_classifications(element.id)
] ]
...@@ -172,12 +175,8 @@ class DatasetExtractor(DatasetWorker): ...@@ -172,12 +175,8 @@ class DatasetExtractor(DatasetWorker):
text=transcription.text, text=transcription.text,
confidence=transcription.confidence, confidence=transcription.confidence,
orientation=DEFAULT_TRANSCRIPTION_ORIENTATION, orientation=DEFAULT_TRANSCRIPTION_ORIENTATION,
worker_version_id=transcription.worker_version.id worker_version_id=get_object_id(transcription.worker_version),
if transcription.worker_version worker_run_id=get_object_id(transcription.worker_run),
else None,
worker_run_id=transcription.worker_run.id
if transcription.worker_run
else None,
) )
for transcription in list_transcriptions(element.id) for transcription in list_transcriptions(element.id)
] ]
...@@ -202,9 +201,7 @@ class DatasetExtractor(DatasetWorker): ...@@ -202,9 +201,7 @@ class DatasetExtractor(DatasetWorker):
name=transcription_entity.entity.name, name=transcription_entity.entity.name,
validated=transcription_entity.entity.validated, validated=transcription_entity.entity.validated,
metas=transcription_entity.entity.metas, metas=transcription_entity.entity.metas,
worker_run_id=transcription_entity.entity.worker_run.id worker_run_id=get_object_id(transcription_entity.entity.worker_run),
if transcription_entity.entity.worker_run
else None,
) )
entities.append(entity) entities.append(entity)
transcription_entities.append( transcription_entities.append(
...@@ -215,9 +212,7 @@ class DatasetExtractor(DatasetWorker): ...@@ -215,9 +212,7 @@ class DatasetExtractor(DatasetWorker):
offset=transcription_entity.offset, offset=transcription_entity.offset,
length=transcription_entity.length, length=transcription_entity.length,
confidence=transcription_entity.confidence, confidence=transcription_entity.confidence,
worker_run_id=transcription_entity.worker_run.id worker_run_id=get_object_id(transcription_entity.worker_run),
if transcription_entity.worker_run
else None,
) )
) )
if entities: if entities:
...@@ -289,10 +284,8 @@ class DatasetExtractor(DatasetWorker): ...@@ -289,10 +284,8 @@ class DatasetExtractor(DatasetWorker):
polygon=element.polygon, polygon=element.polygon,
rotation_angle=element.rotation_angle, rotation_angle=element.rotation_angle,
mirrored=element.mirrored, mirrored=element.mirrored,
worker_version_id=element.worker_version.id worker_version_id=get_object_id(element.worker_version),
if element.worker_version worker_run_id=get_object_id(element.worker_run),
else None,
worker_run_id=element.worker_run.id if element.worker_run else None,
confidence=element.confidence, confidence=element.confidence,
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment