Skip to content

Commit 060273d

Browse files
committed
Initial changes
1 parent 3633bdc commit 060273d

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

superannotate/analytics/common.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def aggregate_annotations_as_df(
153153
include_classes_wo_annotations=False,
154154
include_comments=False,
155155
include_tags=False,
156-
verbose=True
156+
verbose=True,
157+
folder_names=None
157158
):
158159
"""Aggregate annotations as pandas dataframe from project root.
159160
@@ -166,14 +167,16 @@ def aggregate_annotations_as_df(
166167
:type include_comments: bool
167168
:param include_tags: enables inclusion of tags info as tag column
168169
:type include_tags: bool
170+
:param folder_names: Aggregate the specified folders from project_root. If None aggregate all folders in the project_root.
171+
:type folder_names: (list of str)
169172
170173
:return: DataFrame on annotations with columns: "imageName", "instanceId",
171174
"className", "attributeGroupName", "attributeName", "type", "error", "locked",
172175
"visible", "trackingId", "probability", "pointLabels",
173176
"meta" (geometry information as string), "commentResolved", "classColor",
174177
"groupId", "imageWidth", "imageHeight", "imageStatus", "imagePinned",
175178
"createdAt", "creatorRole", "creationType", "creatorEmail", "updatedAt",
176-
"updatorRole", "updatorEmail", "tag"
179+
"updatorRole", "updatorEmail", "tag", "folderName"
177180
:rtype: pandas DataFrame
178181
"""
179182

@@ -208,7 +211,8 @@ def aggregate_annotations_as_df(
208211
"creatorEmail": [],
209212
"updatedAt": [],
210213
"updatorRole": [],
211-
"updatorEmail": []
214+
"updatorEmail": [],
215+
"folderName": []
212216
}
213217

214218
if include_comments:
@@ -283,15 +287,25 @@ def __get_user_metadata(annotation):
283287

284288
annotations_paths = []
285289

286-
for path in Path(project_root).glob('*.json'):
287-
annotations_paths.append(path)
290+
if folder_names is None:
291+
project_dir_content = Path(project_root).glob('*.json')
292+
for entry in project_dir_content:
293+
if entry.is_file() and entry.suffix == '.json':
294+
annotations_paths.append(entry)
295+
elif entry.is_dir() and entry.name != "classes":
296+
annotations_paths.extend(list(entry.rglob('*.json')))
297+
else:
298+
for folder_name in folder_names:
299+
annotations_paths.extend(
300+
list((Path(project_root) / folder_name).rglob('*.json'))
301+
)
288302

289303
if not annotations_paths:
290304
logger.warning(
291305
"No annotations found in project export root %s", project_root
292306
)
293-
type_postfix = "___objects.json" if glob.glob(
294-
"{}/*___objects.json".format(project_root)
307+
type_postfix = "___objects.json" if annotations_paths[0].match(
308+
"*___objects.json"
295309
) else "___pixel.json"
296310
for annotation_path in annotations_paths:
297311
annotation_json = json.load(open(annotation_path))

0 commit comments

Comments
 (0)