Skip to content

Commit 8cc7af7

Browse files
committed
added QC logic, security fixes as well
1 parent 7d305ef commit 8cc7af7

17 files changed

+7823
-25
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ jobs:
3333
if [ -f code/requirements.txt ]; then pip install -r code/requirements.txt; fi
3434
3535
- name: Run Python script
36-
run: python code/main.py
36+
env:
37+
RC_TOKEN: ${{ secrets.RC_TOKEN }}
38+
run: |
39+
python code/main.py 1 "$RC_TOKEN"
3740
3841
- name: Commit and push changes to main
3942
run: |
@@ -43,7 +46,3 @@ jobs:
4346
git add .
4447
git commit -m "Automated changes from GitHub Actions"
4548
git push origin main
46-
47-
48-
49-

code/core/gg.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ def __init__(self, matched, intdir, obsdir):
1515
obsdir (str): Path to the observational directory.
1616
"""
1717
self.matched = matched
18-
self.INTDIR = intdir+'/'
19-
self.OBSDIR = obsdir+'/'
18+
self.INTDIR = intdir.rstrip('/') + '/'
19+
self.OBSDIR = obsdir.rstrip('/') + '/'
2020
self.DERIVATIVES = "/derivatives/GGIR-3.1.4" # Defined within the class
2121

2222
def run_gg(self):
2323
"""
2424
Run GGIR for both the internal and observational project directories.
25+
After each GGIR run, invoke the QC pipeline for that project.
2526
"""
27+
# Assume QC is available at this import path
28+
from utils.qc import QC
29+
2630
for project_dir in [self.INTDIR, self.OBSDIR]:
2731
command = f"Rscript core/acc.R --project_dir {project_dir} --deriv_dir {self.DERIVATIVES}"
2832

@@ -47,3 +51,30 @@ def run_gg(self):
4751

4852
if process.returncode != 0:
4953
raise subprocess.CalledProcessError(process.returncode, command)
54+
55+
print(f"GGIR completed successfully for {project_dir}.")
56+
57+
# Determine project type for QC ('int' for internal, 'obs' for observational)
58+
if project_dir.rstrip('/') == self.INTDIR.rstrip('/'):
59+
project_type = 'int'
60+
else:
61+
project_type = 'obs'
62+
63+
# Run QC for this project
64+
print(f"Starting QC pipeline for {project_type} project.")
65+
qc_runner = QC(project_type)
66+
qc_runner.qc()
67+
print(f"QC pipeline finished for {project_type} project.")
68+
69+
except subprocess.CalledProcessError as e:
70+
print(f"Error running GGIR for {project_dir}: {e}")
71+
# Optionally, continue to next project or break, depending on desired behavior
72+
except Exception as e:
73+
print(f"Unexpected error when processing {project_dir}: {e}")
74+
# Optionally, continue to next project or break
75+
76+
77+
# Example usage:
78+
# matched_dict = {...}
79+
# gg = GG(matched_dict, "/path/to/internal", "/path/to/observational")
80+
# gg.run_gg()

code/main.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,50 @@
88
RDSS_DIR = '/mnt/nfs/rdss/vosslab/Repositories/Accelerometer_Data'
99

1010
class pipe:
11-
def __init__(self, daysago=None):
11+
def __init__(self, token, daysago):
12+
self.token = token
1213
self.daysago = daysago
1314

1415
def run_pipe(self):
1516
self._create_syms()
16-
matched = Save(intdir=INT_DIR, obsdir=OBS_DIR, rdssdir=RDSS_DIR, daysago=self.daysago).save()
17+
matched = Save(
18+
intdir=INT_DIR,
19+
obsdir=OBS_DIR,
20+
rdssdir=RDSS_DIR,
21+
token=self.token,
22+
daysago=self.daysago
23+
).save()
24+
1725
with open('code/res/data.json', 'w') as file:
1826
file.write('{\n}')
1927
file.write(',\n'.join(f' "{key}": "{value}"' for key, value in matched.items()))
20-
#GG(matched=matched, intdir=INT_DIR, obsdir=OBS_DIR).run_gg()
28+
29+
# GG(matched=matched, intdir=INT_DIR, obsdir=OBS_DIR).run_gg()
2130
return None
2231

2332
def _create_syms(self):
2433
return create_symlinks('../mnt')
2534

2635

2736
if __name__ == '__main__':
28-
if len(sys.argv) > 1: # Ensure there's an argument
29-
try:
30-
daysago = int(sys.argv[1]) # Convert argument to integer
31-
except ValueError:
32-
print("Error: daysago must be an integer")
33-
sys.exit(1) # Exit script with error
34-
else:
35-
daysago = None # Default to None if no argument is provided
36-
37-
p = pipe(daysago=daysago)
37+
# Expect exactly 2 arguments: daysago (integer) and token (string)
38+
if len(sys.argv) != 3:
39+
print("Usage: python main.py <daysago> <token>")
40+
print(" <daysago> must be an integer, <token> must be a non-empty string.")
41+
sys.exit(1)
42+
43+
# Parse daysago
44+
try:
45+
daysago = int(sys.argv[1])
46+
except ValueError:
47+
print("Error: <daysago> must be an integer.")
48+
sys.exit(1)
49+
50+
# Parse token
51+
token = sys.argv[2]
52+
if not token:
53+
print("Error: <token> cannot be empty.")
54+
sys.exit(1)
55+
56+
p = pipe(token, daysago)
3857
p.run_pipe()

code/utils/comparison_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
class ID_COMPARISONS:
1111

12-
def __init__(self, mnt_dir, daysago=None) -> None:
13-
self.token = 'DE4E2DB72778DACA9B8848574107D2F5'
12+
def __init__(self, mnt_dir, token, daysago=None) -> None:
13+
self.token = token
1414
self.mnt_dir = mnt_dir
1515
self.INT_DIR = '/Volumes/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test'
1616
self.OBS_DIR = '/Volumes/vosslabhpc/Projects/BOOST/ObservationalStudy/3-experiment/data/act-obs-test'

0 commit comments

Comments
 (0)