Skip to content

Commit

Permalink
🚧 02_update_db.py: init, still missing db add
Browse files Browse the repository at this point in the history
  • Loading branch information
npac committed Nov 21, 2024
1 parent 425b954 commit dd3992d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 02_update_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""
Add newer scans to DB
"""
import os
import re
from glob import glob

import acq2sqlite
import dcmmeta2tsv


def is_project(pdir: str) -> bool:
"""
Is input a MR project dir?
should have subfolder like ``2024.06.27-09.19.11/``
:param pdir: directory to test
:return: True if is a project directory
#>>> is_project('/disk/mace2/scan_data/WPC-8620/')
#True
#>>> is_project('/disk/mace2/scan_data/7T/')
#False
"""
if not os.path.isdir(pdir):
return False
for sesdir in os.listdir(pdir):
if re.search("^2[0-9.-]{18}$", sesdir):
return True
return False


db = acq2sqlite.DBQuery()
for pdir in glob("/disk/mace2/scan_data/W*"):
if not is_project(pdir):
next
project = os.path.basename(pdir)
recent = db.most_recent("%" + project)
print(f"project:'{project}'; res='{recent}'")

0 comments on commit dd3992d

Please sign in to comment.