Skip to content

Commit 223550e

Browse files
committed
pushing for linux automation
1 parent 51ddcdf commit 223550e

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: Install R packages
2121
run: |
22-
Rscript -e 'install.packages(c("ggplot2", "plyr", "optparse", "tidyr", "GGIR"), repos="https://cloud.r-project.org")'
22+
Rscript -e 'install.packages(c("ggplot2", "plyr", "optparse", "tidyr", "GGIR"), repos="https://cloud.r-project.org", dependencies=TRUE)'
2323
2424
- name: Set up Python 3.10
2525
uses: actions/setup-python@v3

code/main.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from utils.mnt import create_symlinks
22
from utils.save import Save
33
from core.gg import GG
4+
import sys
45

56
INT_DIR = '/Volumes/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test'
67
OBS_DIR = '/Volumes/vosslabhpc/Projects/BOOST/ObservationalStudy/3-experiment/data/act-obs-test'
78
RDSS_DIR = '/Volumes/VossLab/Repositories/Accelerometer_Data'
89

910
class pipe:
10-
def __init__(self):
11-
self.funny = False # i happen to be pretty lame
11+
def __init__(self, daysago=None):
12+
self.daysago = daysago
1213

1314
def run_pipe(self):
1415
self._create_syms()
15-
matched = Save(intdir=INT_DIR, obsdir=OBS_DIR, rdssdir=RDSS_DIR).save()
16-
with open('res/data.json', 'w') as file:
16+
matched = Save(intdir=INT_DIR, obsdir=OBS_DIR, rdssdir=RDSS_DIR, daysago=self.daysago).save()
17+
with open('code/res/data.json', 'w') as file:
1718
file.write('{\n}')
1819
file.write(',\n'.join(f' "{key}": "{value}"' for key, value in matched.items()))
1920
#GG(matched=matched, intdir=INT_DIR, obsdir=OBS_DIR).run_gg()
@@ -24,5 +25,14 @@ def _create_syms(self):
2425

2526

2627
if __name__ == '__main__':
27-
p = pipe()
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)
2838
p.run_pipe()

code/res/data.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"8022": "[{'filename': '1023 (2022-06-15)RAW.csv', 'labID': '1023', 'date': '2022-06-15', 'run': 1, 'study': 'int', 'file_path': '/Volumes/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test/sub-8022/accel/sub-8022_ses-1_accel.csv'}]",
3-
"8002": "[{'filename': '1124 (2024-11-07)RAW.csv', 'labID': '1124', 'date': '2024-11-07', 'run': 1, 'study': 'int', 'file_path': '/Volumes/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test/sub-8002/accel/sub-8002_ses-1_accel.csv'}]",
4-
"8018": "[{'filename': '1167 (2025-01-22)RAW.csv', 'labID': '1167', 'date': '2025-01-22', 'run': 1, 'study': 'int', 'file_path': '/Volumes/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test/sub-8018/accel/sub-8018_ses-1_accel.csv'}]",
5-
"7043": "[{'filename': '1174 (2025-01-28)RAW.csv', 'labID': '1174', 'date': '2025-01-28', 'run': 1, 'study': 'obs', 'file_path': '/Volumes/vosslabhpc/Projects/BOOST/ObservationalStudy/3-experiment/data/act-obs-test/sub-7043/accel/sub-7043_ses-1_accel.csv'}]"
6-
}
2+
} "7069": "[{'filename': '1207 (2025-03-01)RAW.csv', 'labID': '1207', 'date': Timestamp('2025-03-01 00:00:00'), 'run': 1, 'study': 'obs', 'file_path': '/Volumes/vosslabhpc/Projects/BOOST/ObservationalStudy/3-experiment/data/act-obs-test/sub-7069/accel/sub-7069_ses-1_accel.csv'}]",
3+
"7073": "[{'filename': '1211 (2025-03-01)RAW.csv', 'labID': '1211', 'date': Timestamp('2025-03-01 00:00:00'), 'run': 1, 'study': 'obs', 'file_path': '/Volumes/vosslabhpc/Projects/BOOST/ObservationalStudy/3-experiment/data/act-obs-test/sub-7073/accel/sub-7073_ses-1_accel.csv'}]"

code/utils/comparison_utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
import logging
44
import pandas as pd
55
import requests
6+
from datetime import datetime, timedelta
67
from io import StringIO
78

89

910
class ID_COMPARISONS:
1011

11-
def __init__(self, mnt_dir) -> None:
12+
def __init__(self, mnt_dir, daysago=None) -> None:
1213
self.token = 'DE4E2DB72778DACA9B8848574107D2F5'
1314
self.mnt_dir = mnt_dir
1415
self.INT_DIR = '/Volumes/vosslabhpc/Projects/BOOST/InterventionStudy/3-experiment/data/act-int-test'
1516
self.OBS_DIR = '/Volumes/vosslabhpc/Projects/BOOST/ObservationalStudy/3-experiment/data/act-obs-test'
17+
self.daysago = daysago
1618
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
1719

1820
def compare_ids(self):
@@ -26,7 +28,7 @@ def compare_ids(self):
2628
# Retrieve the RedCap report and duplicates from report
2729
report, report_duplicates = self._return_report()
2830
# Retrieve the full RDSS file list and duplicate files merged with duplicates from report
29-
rdss, file_duplicates = self._rdss_file_list(report_duplicates)
31+
rdss, file_duplicates = self._rdss_file_list(report_duplicates, self.daysago)
3032

3133
# Initialize the result dictionary for normal (non-duplicate) matches
3234
result = {}
@@ -110,7 +112,7 @@ def _return_report(self):
110112

111113
return df_cleaned, duplicate_rows
112114

113-
def _rdss_file_list(self, duplicates):
115+
def _rdss_file_list(self, duplicates, daysago=None):
114116
"""
115117
Extracts the first string before the space and the date from filenames ending with .csv
116118
in the specified folder and stores them in a DataFrame.
@@ -138,7 +140,12 @@ def _rdss_file_list(self, duplicates):
138140

139141
if not df.empty:
140142
df['Date'] = pd.to_datetime(df['Date'], errors='coerce')
141-
df = df[df['Date'] >= '2024-08-05'] # Filter out rows before the threshold date
143+
144+
if daysago:
145+
cutoff_date = datetime.today() - timedelta(days=daysago)
146+
df = df[df['Date'] >= cutoff_date] # Filter files within the last `daysago` days
147+
else:
148+
df = df[df['Date'] >= '2024-08-05'] # Filter out rows before the threshold date
142149

143150
# Filter the file list to only include rows where ID is in the duplicate report (if any)
144151
if not duplicates.empty:

code/utils/save.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
class Save:
77

8-
def __init__(self, intdir, obsdir, rdssdir):
9-
results = ID_COMPARISONS('../mnt').compare_ids()
8+
def __init__(self, intdir, obsdir, rdssdir, daysago=None):
9+
results = ID_COMPARISONS('../mnt', daysago).compare_ids()
1010
self.matches = results['matches']
1111
self.dupes = results['duplicates']
1212
print(f"Type of Dupes: {type(self.dupes)}")
@@ -25,7 +25,7 @@ def save(self):
2525
matches = self._handle_and_merge_duplicates(self.dupes)
2626

2727
# Move the files based on the final matches.
28-
self._move_files(matches=matches)
28+
#self._move_files(matches=matches)
2929
return matches
3030

3131
def _move_files_test(self, matches):

0 commit comments

Comments
 (0)