Skip to content

Commit 2e67496

Browse files
authored
Merge pull request #259 from superannotateai/fix-tag-delay
Fix tag delay
2 parents 41f07b7 + 6b2514a commit 2e67496

File tree

5 files changed

+29
-41
lines changed

5 files changed

+29
-41
lines changed

src/superannotate/lib/core/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ def map_annotation_classes_name(annotation_classes, reporter: Reporter) -> dict:
4545
return classes_data
4646

4747

48+
def fill_document_tags(
49+
annotations: dict,
50+
annotation_classes: dict,
51+
):
52+
new_tags = []
53+
for tag in annotations['tags']:
54+
if annotation_classes.get(tag):
55+
new_tags.append(annotation_classes[tag]['id'])
56+
annotations['tags'] = new_tags
57+
58+
4859
def fill_annotation_ids(
4960
annotations: dict,
5061
annotation_classes_name_maps: dict,

src/superannotate/lib/core/usecases/annotations.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from lib.core.exceptions import AppException
1616
from lib.core.helpers import convert_to_video_editor_json
1717
from lib.core.helpers import fill_annotation_ids
18+
from lib.core.helpers import fill_document_tags
1819
from lib.core.helpers import map_annotation_classes_name
1920
from lib.core.reporter import Reporter
2021
from lib.core.service_types import UploadAnnotationAuthData
@@ -361,22 +362,28 @@ def prepare_annotations(
361362
templates: List[dict],
362363
reporter: Reporter,
363364
) -> dict:
365+
annotation_classes_name_maps = map_annotation_classes_name(
366+
annotation_classes, reporter
367+
)
364368
if project_type in (
365369
constances.ProjectType.VECTOR.value,
366370
constances.ProjectType.PIXEL.value,
367-
constances.ProjectType.DOCUMENT.value,
371+
constances.ProjectType.DOCUMENT.value
368372
):
369373
fill_annotation_ids(
370374
annotations=annotations,
371-
annotation_classes_name_maps=map_annotation_classes_name(
372-
annotation_classes, reporter
373-
),
375+
annotation_classes_name_maps=annotation_classes_name_maps,
374376
templates=templates,
375377
reporter=reporter,
376378
)
377379
elif project_type == constances.ProjectType.VIDEO.value:
378380
annotations = convert_to_video_editor_json(
379-
annotations, map_annotation_classes_name(annotation_classes, reporter), reporter
381+
annotations, annotation_classes_name_maps, reporter
382+
)
383+
if project_type == constances.ProjectType.DOCUMENT.value:
384+
fill_document_tags(
385+
annotations=annotations,
386+
annotation_classes=annotation_classes_name_maps,
380387
)
381388
return annotations
382389

src/superannotate/lib/infrastructure/services.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from contextlib import contextmanager
23
from datetime import datetime
34
from typing import Dict
@@ -653,6 +654,7 @@ def get_bulk_images(
653654
self, project_id: int, team_id: int, folder_id: int, images: List[str]
654655
) -> List[dict]:
655656
bulk_get_images_url = urljoin(self.api_url, self.URL_BULK_GET_IMAGES)
657+
time.sleep(1)
656658

657659
res = self._request(
658660
bulk_get_images_url,
Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1 @@
1-
{
2-
"metadata": {
3-
"name": "text_file_example_1",
4-
"status": "Completed",
5-
"url": "https://sa-public-files.s3.us-west-2.amazonaws.com/Text+project/text_file_example_1.txt",
6-
"projectId": 160158,
7-
"annotatorEmail": null,
8-
"qaEmail": null,
9-
"lastAction": {
10-
"email": "shab.prog@gmail.com",
11-
"timestamp": 1634899229953
12-
}
13-
},
14-
"instances": [
15-
{
16-
"start": 253,
17-
"end": 593,
18-
"classId": 873208,
19-
"createdAt": "2021-10-22T10:40:26.151Z",
20-
"createdBy": {
21-
"email": "shab.prog@gmail.com",
22-
"role": "Admin"
23-
},
24-
"updatedAt": "2021-10-22T10:40:29.953Z",
25-
"updatedBy": {
26-
"email": "shab.prog@gmail.com",
27-
"role": "Admin"
28-
},
29-
"attributes": [],
30-
"creationType": "Manual",
31-
"className": "vid"
32-
}
33-
],
34-
"tags": [],
35-
"freeText": ""
36-
}
1+
{"metadata":{"name":"text_file_example_1","status":"Completed","url":"https://sa-public-files.s3.us-west-2.amazonaws.com/Text+project/text_file_example_1.txt","projectId":160158,"annotatorEmail":null,"qaEmail":null,"lastAction":{"email":"shab.prog@gmail.com","timestamp":1634899229953}},"instances":[{"start":253,"end":593,"classId":873208,"createdAt":"2021-10-22T10:40:26.151Z","createdBy":{"email":"shab.prog@gmail.com","role":"Admin"},"updatedAt":"2021-10-22T10:40:29.953Z","updatedBy":{"email":"shab.prog@gmail.com","role":"Admin"},"attributes":[],"creationType":"Manual","className":"vid"}],"tags":["vid"],"freeText":""}

tests/integration/annotations/test_text_annotation_upload.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
import src.superannotate as sa
77
from tests.integration.base import BaseTestCase
8+
from src.superannotate.lib.core.helpers import fill_document_tags
89

910

1011
class TestUploadTextAnnotation(BaseTestCase):
@@ -72,3 +73,5 @@ def test_text_annotation_upload(self):
7273
downloaded_annotation = json.loads(open(f"{output_path}/text_file_example_1.json").read())
7374
instance = downloaded_annotation['instances'][0]
7475
self.assertEqual(instance['classId'], classes[0]['id'])
76+
self.assertEqual(downloaded_annotation['tags'][0], "vid")
77+

0 commit comments

Comments
 (0)