Esempio n. 1
0
def parse_tests_hentz(kind,tests_sheet,question_set,subject_label=None):
	"""Parse a worksheet of tests to return subject and tests.""" 

	subjects = {}
	tests = []
	
	headers = tests_sheet.row_values(0)
	hd = {key:i for i,key in enumerate(headers)}
	for row_num in range(1,tests_sheet.nrows):
		row = tests_sheet.row_values(row_num)

		case_id = row[hd['shri_case_num']]
		if case_id not in subjects:
			subject = Subject(case_id)
			# Age is reported as an integer or as 100+.   
			expired_age = row[hd['deathage']]
			subject.expired_age = 100 if expired_age=='100+' else int(expired_age)
			# Gender is reported as 1 or 2.  
			subject.gender = row[hd['female']]
			if subject_label is not None:
				subject.label = subject_label
			subject.dementia = 2 in row[16:25]
			subject.stint = float(row[hd['stint']])
			subject.other = [int(_)>0 for _ in row[5:17]+row[19:25]]
			subject.label = 'ctrl' if int(row[hd['controlp']]) else 'other'
			subjects[case_id] = subject
		  
		responses = {}
		for q in range(1,41):
			choice_num = row[hd['smell_%d' % q]] 
			if type(choice_num) is float:
				choice_num = int(choice_num)-1 # Change to 0-indexed.  
			else:
				choice_num = None
			responses[q] = Response(question_set.questions[q],choice_num)
	  
		response_set = ResponseSet(responses,indices=responses.keys())
		test = Test(subjects[case_id],response_set,None)
		tests.append(test)    

	return subjects,tests
Esempio n. 2
0
def parse_tests_dugger(kind,tests_sheet,question_set,subject_label=None):
	"""Parse a worksheet of tests to return subject and tests.""" 

	subjects = {}
	tests = []
	
	headers = tests_sheet.row_values(0)
	hd = {key:i for i,key in enumerate(headers)}
	for row_num in range(1,tests_sheet.nrows):
		row = tests_sheet.row_values(row_num)

		case_id = row[hd['CaseID']]
		if case_id not in subjects:
			subject = Subject(case_id)
			# Age is reported as an integer or as 100+.   
			expired_age = row[hd['expired_age']]
			subject.expired_age = 100 if expired_age=='100+' else int(expired_age)
			# Gender is reported as 1 or 2.  
			subject.gender = row[hd['tbl_donors.gender']]-1
			if subject_label is not None:
				subject.label = subject_label
			subject.demented = row[hd['dementia_nos']] in [1,'yes']
			subjects[case_id] = subject
		  
		test_date = row[hd['smell_test_date']]
		test_date = datetime(1900,1,1) + timedelta(int(test_date)-2)

		responses = {}
		for q in range(1,41):
			choice_num = row[hd['smell_%d' % q]] 
			if type(choice_num) is float:
				choice_num = int(choice_num)-1 # Change to 0-indexed.  
			else:
				choice_num = None
			responses[q] = Response(question_set.questions[q],choice_num)
		
		response_set = ResponseSet(responses,indices=responses.keys())
		test = Test(subjects[case_id],response_set,test_date)
		tests.append(test)    

	return subjects,tests