Skip to content

Instantly share code, notes, and snippets.

@humanfactors
Created January 18, 2017 14:00
Show Gist options
  • Save humanfactors/2b9ad35be65400d2efc9fa86d4cbd0f1 to your computer and use it in GitHub Desktop.
Save humanfactors/2b9ad35be65400d2efc9fa86d4cbd0f1 to your computer and use it in GitHub Desktop.
import re
import os
import glob
import legacy_restimeinfo as legacyres
resumptiontimes = legacyres.getrestimes()
finaldict = {
'subjectid' : 'string',
'subjectdata' : {
'trial_1' : [],
'trial_2' : [],
'trial_3' : [],
'trial_4' : [],
'trial_5' : [],
'trial_6' : [],
'trial_7' : [],
'trial_8' : [],
'trial_9' : [],
'trial_10' : [],
'trial_11' : [],
'trial_12' : [],
'trial_13' : [],
'trial_14' : [],
'trial_15' : [],
}
}
def participantid(file):
id = re.search(r"(Participant)([0-9]{1,2})", file)
if id:
return id.group(2)
def taskid(line):
testid = re.search(r'<task_id>test([0-9]{1,2})</task_id>', line)
if testid:
return testid.group(1)
def find_interruption(line):
if re.search(r"<interruption_type>Interruption</interruption_type>", line):
return "Found"
def processinterruption(line):
interruption = re.search(r"(?<=<external_program>).*?(?=</external_program>)", line).group(0)
if interruption == "":
return "Blank"
if interruption and ".VBS" in interruption:
return "ATC"
def getinterruptiontime(line):
interruptiontime = re.search(r"<hpc_elapsed_time>([-+]?[0-9]*\.?[0-9]+)</hpc_elapsed_time>", line).group(1)
return float(interruptiontime)
def find_conflictline(line):
if re.search(r"<solution>level_variation", line):
interventiontime = re.search(r"<hpc_elapsed_time>([-+]?[0-9]*\.?[0-9]+)</hpc_elapsed_time>", line).group(1)
callsign = re.search(r"<call>([a-zA-Z0-9]*)</call>", line).group(1)
return {'interventiontime' : interventiontime, 'callsign': callsign}
def check_valid_conflict(trial, conflictid):
if conflictid in resumptiontimes[str(trial)]:
return True
else:
return False
def conflict_rt_calculation(trial, interruptiontime, interventiontime):
return float(interventiontime) - (27000 + float(interruptiontime))
def processfile(file):
with open(file, 'r') as openfile:
this_participantid = participantid(file)
for line in openfile:
if taskid(line):
if trial_tmp:
print("Russ you get the picture if you read this far. These loops keep going")
processfile(file="Final Raw Data/Participant Data 01/ATC2_Mike_Participant1.xml.log")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment