Skip to content

Commit 861bb18

Browse files
author
DANDI Team
committed
Keep saving results across dandisets as they come in
1 parent afc4527 commit 861bb18

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sandbox/ndx-stats/ndx-stats.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ def analyze_extensions(
145145
# Convert to list for output
146146
return list(extension_stats.values())
147147

148+
def snapshot_result(result, output):
149+
out = json.dumps(result, indent=2, cls=EnhancedJSONEncoder)
150+
if output:
151+
with open(output, "w") as f:
152+
f.write(out)
153+
return out
148154

149155
def main():
150156
parser = argparse.ArgumentParser(description="Analyze NWB file extensions")
@@ -180,6 +186,7 @@ def main():
180186
urls = get_s3_urls_and_dandi_paths(dandiset_id=d)
181187
nwb_urls = [url for url, path in urls.items() if path.endswith(".nwb")]
182188
result[d] = analyze_extensions(nwb_urls, True)
189+
snapshot_result(result, args.output)
183190
else:
184191
if args.files:
185192
file_paths = args.files
@@ -197,12 +204,8 @@ def main():
197204
result = [asdict(stat) for stat in extension_stats]
198205

199206
# Output results
200-
out = json.dumps(result, indent=2, cls=EnhancedJSONEncoder)
201-
if args.output:
202-
with open(args.output, "w") as f:
203-
f.write(out)
204-
print(f"Results written to {args.output}")
205-
else:
207+
out = snapshot_result(result, args.output)
208+
if not args.output:
206209
print(out)
207210

208211

0 commit comments

Comments
 (0)