Skip to content

Commit fb2a1a6

Browse files
committed
fixing web export of filtered annotations
1 parent cd5fbdd commit fb2a1a6

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

server/dive_server/crud_dataset.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def makeAnnotationAndMedia(dsFolder: types.GirderModel):
263263

264264
def stream():
265265
z = ziputil.ZipGenerator()
266+
nestedExcludeBelowThreshold = excludeBelowThreshold
267+
nestedTypeFilter = typeFilter
268+
if nestedTypeFilter is None:
269+
nestedTypeFilter = set()
266270
for dsFolder in dsFolders:
267271
zip_path = f"./{dsFolder['name']}/"
268272
try:
@@ -291,25 +295,23 @@ def makeDiveJson():
291295
annotations = crud_annotation.get_annotations(dsFolder)
292296
tracks = annotations['tracks']
293297

294-
if excludeBelowThreshold:
298+
if nestedExcludeBelowThreshold:
295299
thresholds = fromMeta(dsFolder, "confidenceFilters", {})
296-
if thresholds is None:
297-
thresholds = {}
300+
if thresholds is None:
301+
thresholds = {}
298302

299-
updated_tracks = []
300-
if typeFilter is None:
301-
typeFilter = set()
303+
updated_tracks = {}
302304
for t in tracks:
303-
track = models.Track(**t)
304-
if (not excludeBelowThreshold) or track.exceeds_thresholds(thresholds):
305+
track = models.Track(**tracks[t])
306+
if (not nestedExcludeBelowThreshold) or track.exceeds_thresholds(thresholds):
305307
# filter by types if applicable
306-
if typeFilter:
307-
confidence_pairs = [item for item in track.confidencePairs if item[0] in typeFilter]
308+
if nestedTypeFilter:
309+
confidence_pairs = [item for item in track.confidencePairs if item[0] in nestedTypeFilter]
308310
# skip line if no confidence pairs
309311
if not confidence_pairs:
310312
continue
311-
updated_tracks.append[track]
312-
annotations['tracks'] = updated_tracks
313+
updated_tracks[t] = tracks[t]
314+
annotations['tracks'] = updated_tracks
313315
yield json.dumps(annotations)
314316

315317
for data in z.addFile(makeMetajson, Path(f'{zip_path}meta.json')):

server/dive_server/views_annotation.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from girder.exceptions import RestException
1010
from girder.models.folder import Folder
1111

12-
from dive_utils import constants, setContentDisposition
12+
from dive_utils import constants, setContentDisposition, models, fromMeta
1313

1414
from . import crud, crud_annotation
1515

@@ -152,6 +152,29 @@ def export(
152152
setContentDisposition(f'{folder["name"]}.dive.json', mime='application/json')
153153
setRawResponse()
154154
annotations = crud_annotation.get_annotations(folder, revision=revisionId)
155+
tracks = annotations['tracks']
156+
if excludeBelowThreshold:
157+
thresholds = fromMeta(folder, "confidenceFilters", {})
158+
if thresholds is None:
159+
thresholds = {}
160+
161+
updated_tracks = []
162+
if typeFilter is None:
163+
typeFilter = set()
164+
print(tracks)
165+
for t in tracks:
166+
print(t)
167+
print(tracks[t])
168+
track = models.Track(**tracks[t])
169+
if (not excludeBelowThreshold) or track.exceeds_thresholds(thresholds):
170+
# filter by types if applicable
171+
if typeFilter:
172+
confidence_pairs = [item for item in track.confidencePairs if item[0] in typeFilter]
173+
# skip line if no confidence pairs
174+
if not confidence_pairs:
175+
continue
176+
updated_tracks.append(tracks[t])
177+
annotations['tracks'] = updated_tracks
155178
return json.dumps(annotations).encode('utf-8')
156179
else:
157180
raise RestException(f'Format {format} is not a valid option.')

0 commit comments

Comments
 (0)