forked from cpp-lln-lab/bidsMReye
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
79 lines (54 loc) · 2.18 KB
/
report.py
File metadata and controls
79 lines (54 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Compile outputs from all tasks, spaces, runs into a single HTML."""
import datetime
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, select_autoescape
from bidsmreye._version import __version__
from bidsmreye.logger import bidsmreye_log
log = bidsmreye_log(name="bidsmreye")
TEMPLATES_DIR = Path(__file__).parent / "templates"
def return_jinja_env(searchpath=None) -> Environment:
if searchpath is None:
searchpath = TEMPLATES_DIR / "report"
return Environment(
loader=FileSystemLoader(searchpath),
autoescape=select_autoescape(),
lstrip_blocks=True,
trim_blocks=True,
)
def generate_report(output_dir: Path, subject_label: str, action: str) -> None:
env = return_jinja_env()
template = env.get_template("base.html")
if action == "prepare":
input_files = sorted(output_dir.glob(f"sub-{subject_label}/**/*report.html"))
elif action == "generalize":
input_files = sorted(output_dir.glob(f"sub-{subject_label}/**/*eyetrack.html"))
files = []
for html_report in input_files:
with open(html_report) as f:
content = f.read()
name: str = html_report.stem
if action == "prepare":
name = name.replace("_desc-eye_report", "_desc-preproc_bold")
files.append({"name": name, "content": content, "path": html_report})
date = datetime.datetime.now().astimezone().replace(microsecond=0).isoformat()
report = template.render(
action=action,
files=files,
subject_label=subject_label,
date=date,
version=__version__,
)
report_filename = (
output_dir / f"sub-{subject_label}" / f"sub-{subject_label}_{action}.html"
)
with open(report_filename, "w") as f:
f.write(report)
log.info(f"Report saved at: '{report_filename}'.")
if __name__ == "__main__":
cwd = Path("/home/remi/github/cpp-lln-lab/bidsMReye")
output_dir = cwd / "outputs" / "moae_fmriprep" / "derivatives" / "bidsmreye"
subject = "01"
output_dir = Path("/home/remi/gin/CPP/yin/bidsmreye")
subject_label = "02"
action = "prepare"
generate_report(output_dir, subject_label, action)