def test_no_activity(self): f = Flywheel() start_waiting = datetime.datetime.now() second_count = f.wait_for_flywheel_to_stop(gui_q) finish_waiting = datetime.datetime.now() time_spent_waiting = timedelta_milliseconds(finish_waiting - start_waiting) self.assertAlmostEquals(time_spent_waiting / 1000, NUM_SECONDS_INACTIVITY_PERIOD, 0) self.assertEqual(second_count, NUM_SECONDS_INACTIVITY_PERIOD)
def add_n_spins_with_n_seconds_between_spins(self, num_spins, delay_between_spins): f = Flywheel() #start new thread that adds n flywheel spins with n seconds between spins try: thread.start_new_thread(flywheel_simulated_input, ( num_spins, delay_between_spins, )) except: print "Error: Unable to start thread" start_waiting = datetime.datetime.now() second_count = f.wait_for_flywheel_to_stop(gui_q) finish_waiting = datetime.datetime.now() time_spent_waiting = timedelta_milliseconds(finish_waiting - start_waiting) / 1000 reset_time = NUM_SECONDS_INACTIVITY_PERIOD + (num_spins * delay_between_spins) self.assertAlmostEquals(time_spent_waiting, reset_time, 1) self.assertEquals(second_count, NUM_SECONDS_INACTIVITY_PERIOD, 0)
import os from os.path import join as pjoin from subprocess import call, Popen, PIPE from flywheel import Flywheel import time import sys import pdb #sys.path.insert(0, '/oak/stanford/groups/menon/projects/chamblin') #from helper_funcs import print_out, split_path from studies_template import studies_template, studies_rules #log = open('../logs/fw_download_%s.log' % time.strftime('%m-%d-%Y'), 'w+') #Get flywheel credentials fw = Flywheel('lucascenter.flywheel.io:oglHDMF0DnDeKPmDnl') me = fw.get_current_user() #Generate a list of all scanids currently in rawdata_scsnl rawdata_scanids = [] rawdata_root = '/oak/stanford/groups/menon/rawdata/scsnl' pids = os.listdir(rawdata_root) for pid in pids: visits = os.listdir(pjoin(rawdata_root, pid)) for visit in visits: sessions = os.listdir(pjoin(rawdata_root, pid, visit)) for session in sessions: if session == 'assessments': continue sessnum = session[-1] visitnum = visit[-1] scanid = pid + '_' + visitnum + '_' + sessnum
from os.path import join as pjoin from subprocess import call, Popen, PIPE from flywheel import Flywheel import flywheel import time import sys #import pdb #sys.path.insert(0, '/oak/stanford/groups/menon/projects/chamblin') #from helper_funcs import print_out, split_path #from studies_template import studies_template, studies_rules #PARAMETERS SUBLIST = 'mathwhiz_subjects.txt' #Get flywheel credentials fw = Flywheel('lucascenter.flywheel.io:oglHDMF0DnDeKPmDnl') me = fw.get_current_user() #listify file of scanids study = SUBLIST.split('_subjects.txt')[0] file = open( pjoin( '/oak/stanford/groups/menon/scsnlscripts/utilities/dataOrganization/study_sublists', SUBLIST), 'r') scans = file.readlines() scans = [x.strip() for x in scans] #generate dictionary of project ids to study names projects_full = fw.get_all_projects() #print(fw_projects_full) projects_thin = {}
#Downloaded scanids (Set this!!!!) downloaded_scanids = [['8088', 'visit1', 'session1'], ['0059', 'visit2', 'session1'], ['7483', 'visit7', 'session1'], ['7943', 'visit3', 'session1'], ['0224', 'visit2', 'session1'], ['0224', 'visit2', 'session2'], ['0281', 'visit2', 'session1'], ['0098', 'visit2', 'session1'], ['8082', 'visit2', 'session1'], ['7863', 'visit2', 'session1'], ['0098', 'visit2', 'session2']] #Get flywheel credentials fw = Flywheel('lucascenter.flywheel.io:oglHDMF0DnDeKPmDnl') me = fw.get_current_user() projects_full = fw.get_all_projects() #print(fw_projects_full) projects_thin = {} for project in projects_full: projects_thin[project['_id']] = project['label'] #Generate a list of all scanids currently in rawdata_scsnl rawdata_scanids = [] rawdata_root = '/oak/stanford/groups/menon/rawdata/scsnl' pids = os.listdir(rawdata_root) for pid in pids: visits = os.listdir(pjoin(rawdata_root, pid)) for visit in visits:
if not re.match('^[a-zA-Z0-9][a-zA-Z0-9_-]+$', GroupTagsBy): print('Group By Tags is invalid.') print( 'Valid values are: blank, alphanumeric including dashes and underscores' ) sys.exit(1) else: GroupTagsBy = "" # Load Flywheel Python SDK print('Loading Python SDK') from flywheel import Flywheel # Get temporary API key api_key = str(config['inputs']['api_key']['key']) fw = Flywheel(api_key) # Get fileid fileid = config['inputs']['file']['hierarchy']['id'] # get project information from file acquisition = fw.get_acquisition(fileid) session = fw.get_session(acquisition['session']) project = fw.get_project(session['project']) projectid = project['_id'] projectname = project['label'] # read CSV into list print('Reading in CSV') csv_data = pd.read_csv(input_filepath) csv_columns = csv.columns
0, 0, tzinfo=tzutc()) end_date_dt = datetime.datetime(end_date[0], end_date[1], end_date[2], 23, 0, 0, 0, tzinfo=tzutc()) start_date_unix = time.mktime(start_date_dt.timetuple()) end_date_unix = time.mktime(end_date_dt.timetuple()) fw = Flywheel('lucascenter.flywheel.io:oglHDMF0DnDeKPmDnl') me = fw.get_current_user() #generate dictionary of project ids to study names projects_full = fw.get_all_projects() #print(fw_projects_full) projects_thin = {} for project in projects_full: projects_thin[project['label']] = project['_id'] projects_thin_inverted = dict([[v, k] for k, v in projects_thin.items()]) exams_full = fw.get_all_sessions() print('scanid,timestamp,project') for exam in exams_full: