-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RANO Annotation procedure (#577)
* Implement fix to annotation. Provide helper scripts for fixing issue * Ignore hidden files when listing subjects/timepoints * Increment medperf version * Set version to expected value by users * Start implementing tarball dialog * Remove watchdog for loading annotations. Use button instead * Fix scroll for Summary view * WIP fix annotated local RANO dataset script * finish annotated rano dataset fix script * [WIP] Implement fix for bugged annotated rano tarballs * Implement fix for annotated rano tarball * Print number of corrected cases * Remove fix dataset scripts to avoid misuse * fix linter issues * add destination path checks
- Loading branch information
1 parent
001d362
commit 48f1fb1
Showing
13 changed files
with
275 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.0" | ||
__version__ = "0.1.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import hashlib | ||
import os | ||
import yaml | ||
|
||
from medperf import config | ||
from medperf.init import initialize | ||
from typer import Option | ||
|
||
|
||
def sha256sum(filename): | ||
h = hashlib.sha256() | ||
b = bytearray(128 * 1024) | ||
mv = memoryview(b) | ||
with open(filename, "rb", buffering=0) as f: | ||
while n := f.readinto(mv): | ||
h.update(mv[:n]) | ||
return h.hexdigest() | ||
|
||
|
||
def generate_hash_dict(path): | ||
hash_dict = {} | ||
contents = os.listdir(path) | ||
|
||
for item in contents: | ||
item_path = os.path.join(path, item) | ||
if os.path.isdir(item_path): | ||
hash_dict[item] = generate_hash_dict(item_path) | ||
else: | ||
hash_dict[item] = sha256sum(item_path) | ||
|
||
return hash_dict | ||
|
||
|
||
def main( | ||
dataset_uid: str = Option(None, "-d", "--dataset"), | ||
output_file: str = Option("dataset_hashes.yaml", "-f", "--file"), | ||
): | ||
initialize() | ||
dset_path = os.path.join(config.datasets_folder, dataset_uid) | ||
|
||
# Get hashes of tree | ||
hash_dict = generate_hash_dict(dset_path) | ||
|
||
# Write results to a file | ||
with open(output_file, "w") as f: | ||
yaml.dump(hash_dict, f) | ||
|
||
|
||
if __name__ == "__main__": | ||
run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import tarfile | ||
import hashlib | ||
import shutil | ||
import os | ||
import yaml | ||
|
||
|
||
def sha256sum(filename): | ||
h = hashlib.sha256() | ||
b = bytearray(128 * 1024) | ||
mv = memoryview(b) | ||
with open(filename, "rb", buffering=0) as f: | ||
while n := f.readinto(mv): | ||
h.update(mv[:n]) | ||
return h.hexdigest() | ||
|
||
|
||
def generate_hash_dict(path): | ||
hash_dict = {} | ||
contents = os.listdir(path) | ||
|
||
for item in contents: | ||
item_path = os.path.join(path, item) | ||
if os.path.isdir(item_path): | ||
hash_dict[item] = generate_hash_dict(item_path) | ||
else: | ||
hash_dict[item] = sha256sum(item_path) | ||
|
||
return hash_dict | ||
|
||
|
||
def main(): | ||
dst = ".reviewed_cases_contents" | ||
hashes_file = "reviewed_cases_hashes.yaml" | ||
|
||
# Create destination folder | ||
shutil.rmtree(dst, ignore_errors=True) | ||
os.makedirs(dst, exist_ok=True) | ||
|
||
# Extract contents | ||
with tarfile.open("reviewed_cases.tar.gz") as file: | ||
file.extractall(dst) | ||
|
||
# Get hashes of tree | ||
hash_dict = generate_hash_dict(dst) | ||
|
||
# Write results to a file | ||
with open(hashes_file, "w") as f: | ||
yaml.dump(hash_dict, f) | ||
|
||
# Delete generated files and folders | ||
shutil.rmtree(dst, ignore_errors=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
from .invalid_handler import InvalidHandler | ||
from .prompt_handler import PromptHandler | ||
from .report_handler import ReportHandler, ReportState | ||
from .reviewed_handler import ReviewedHandler | ||
from .tarball_reviewed_watchdog import TarballReviewedHandler | ||
|
||
__all__ = [ | ||
InvalidHandler, | ||
PromptHandler, | ||
ReportHandler, | ||
ReportState, | ||
ReviewedHandler, | ||
TarballReviewedHandler, | ||
] |
115 changes: 0 additions & 115 deletions
115
scripts/monitor/rano_monitor/handlers/reviewed_handler.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.