Skip to content

Commit bd58bc2

Browse files
authored
Merge pull request #615 from superannotateai/1950_download_annotations
change download_annotations files path logic and remove postfixes
2 parents 4ef9a3e + b4d4c21 commit bd58bc2

File tree

9 files changed

+2979
-54
lines changed

9 files changed

+2979
-54
lines changed

src/superannotate/lib/core/serviceproviders.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ async def download_big_annotation(
345345
self,
346346
project: entities.ProjectEntity,
347347
download_path: str,
348-
postfix: str,
349348
item: entities.BaseItemEntity,
350349
callback: Callable = None,
351350
):
@@ -358,7 +357,6 @@ async def download_small_annotations(
358357
folder: entities.FolderEntity,
359358
reporter: Reporter,
360359
download_path: str,
361-
postfix: str,
362360
item_ids: List[int],
363361
callback: Callable = None,
364362
):

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import traceback
1212
import typing
1313
from dataclasses import dataclass
14-
from datetime import datetime
1514
from itertools import islice
1615
from operator import itemgetter
1716
from pathlib import Path
@@ -1637,13 +1636,6 @@ def validate_destination(self):
16371636
def destination(self) -> Path:
16381637
return Path(self._destination if self._destination else "")
16391638

1640-
def get_postfix(self):
1641-
if self._project.type == constants.ProjectType.VECTOR:
1642-
return "___objects.json"
1643-
elif self._project.type == constants.ProjectType.PIXEL.value:
1644-
return "___pixel.json"
1645-
return ".json"
1646-
16471639
def download_annotation_classes(self, path: str):
16481640
response = self._service_provider.annotation_classes.list(
16491641
Condition("project_id", self._project.id, EQ)
@@ -1678,12 +1670,10 @@ async def download_big_annotations(self, export_path):
16781670
item = await self._big_file_queue.get()
16791671
self._big_file_queue.task_done()
16801672
if item:
1681-
postfix = self.get_postfix()
16821673
await self._service_provider.annotations.download_big_annotation(
16831674
project=self._project,
16841675
item=item,
16851676
download_path=f"{export_path}{'/' + self._folder.name if not self._folder.is_root else ''}",
1686-
postfix=postfix,
16871677
callback=self._callback,
16881678
)
16891679
else:
@@ -1693,14 +1683,12 @@ async def download_big_annotations(self, export_path):
16931683
async def download_small_annotations(
16941684
self, item_ids: List[int], export_path, folder: FolderEntity
16951685
):
1696-
postfix = self.get_postfix()
16971686
await self._service_provider.annotations.download_small_annotations(
16981687
project=self._project,
16991688
folder=folder,
17001689
item_ids=item_ids,
17011690
reporter=self.reporter,
17021691
download_path=f"{export_path}{'/' + self._folder.name if not self._folder.is_root else ''}",
1703-
postfix=postfix,
17041692
callback=self._callback,
17051693
)
17061694

@@ -1738,12 +1726,7 @@ async def run_workers(
17381726

17391727
def execute(self):
17401728
if self.is_valid():
1741-
export_path = str(
1742-
self.destination
1743-
/ Path(
1744-
f"{self._project.name} {datetime.now().strftime('%B %d %Y %H_%M')}"
1745-
)
1746-
)
1729+
export_path = str(self.destination)
17471730
logger.info(
17481731
f"Downloading the annotations of the requested items to {export_path}\nThis might take a while…"
17491732
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ def execute(
10781078
response = None
10791079

10801080
unique_item_ids = list(set(self.item_ids))
1081-
processed_items = len(unique_item_ids) + len(self.results['skipped'])
1081+
processed_items = len(unique_item_ids) + len(self.results["skipped"])
10821082
if self._provided_item_count > processed_items:
10831083
self.reporter.log_info(
10841084
f"Dropping duplicates. Found {processed_items} / {self._provided_item_count} unique items."

src/superannotate/lib/infrastructure/services/annotation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ async def download_big_annotation(
177177
self,
178178
project: entities.ProjectEntity,
179179
download_path: str,
180-
postfix: str,
181180
item: entities.BaseItemEntity,
182181
callback: Callable = None,
183182
):
@@ -208,7 +207,7 @@ async def download_big_annotation(
208207
res = await start_response.json()
209208
Path(download_path).mkdir(exist_ok=True, parents=True)
210209

211-
dest_path = Path(download_path) / (item_name + postfix)
210+
dest_path = Path(download_path) / (item_name + ".json")
212211
with open(dest_path, "w") as fp:
213212
if callback:
214213
res = callback(res)
@@ -220,7 +219,6 @@ async def download_small_annotations(
220219
folder: entities.FolderEntity,
221220
reporter: Reporter,
222221
download_path: str,
223-
postfix: str,
224222
item_ids: List[int],
225223
callback: Callable = None,
226224
):
@@ -242,7 +240,6 @@ async def download_small_annotations(
242240
data=item_ids,
243241
params=query_params,
244242
download_path=download_path,
245-
postfix=postfix,
246243
)
247244

248245
async def upload_small_annotations(

src/superannotate/lib/infrastructure/stream_data_handler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ async def download_annotations(
9595
method: str,
9696
url: str,
9797
download_path,
98-
postfix,
9998
data: typing.List[int],
10099
params: dict = None,
101100
):
@@ -119,16 +118,15 @@ async def download_annotations(
119118
)
120119
self._store_annotation(
121120
download_path,
122-
postfix,
123121
annotation,
124122
self._callback,
125123
)
126124
self._items_downloaded += 1
127125

128126
@staticmethod
129-
def _store_annotation(path, postfix, annotation: dict, callback: Callable = None):
127+
def _store_annotation(path, annotation: dict, callback: Callable = None):
130128
os.makedirs(path, exist_ok=True)
131-
with open(f"{path}/{annotation['metadata']['name']}{postfix}", "w") as file:
129+
with open(f"{path}/{annotation['metadata']['name']}.json", "w") as file:
132130
annotation = callback(annotation) if callback else annotation
133131
json.dump(annotation, file)
134132

0 commit comments

Comments
 (0)