当前位置: 首页>>代码示例>>Python>>正文


Python UtilFunc.parseDataFromFile方法代码示例

本文整理汇总了Python中UtilFunc.parseDataFromFile方法的典型用法代码示例。如果您正苦于以下问题:Python UtilFunc.parseDataFromFile方法的具体用法?Python UtilFunc.parseDataFromFile怎么用?Python UtilFunc.parseDataFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UtilFunc的用法示例。


在下文中一共展示了UtilFunc.parseDataFromFile方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getDataClass

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def getDataClass(fileInputs):
	dataClass = {}

	for key, fileName in fileInputs.iteritems():
		dataClass[key] = UtilFunc.parseDataFromFile(fileName)

	# print dataClass['Participation']
	return dataClass
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:10,代码来源:GenerateAnalysisReport.py

示例2: getNumberFromNameInFile

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def getNumberFromNameInFile(name, yearbookReferenceFilePath):
	nameSep = re.findall('[A-Z][^A-Z]*',name)
	# print '### name:{0} nameSep: {1}'.format(name, nameSep)
	nameDict = {'WrittenLast':''.join(nameSep[0:-1]),'WrittenFirst':nameSep[-1]}
	yearbookNames = UtilFunc.parseDataFromFile(yearbookReferenceFilePath)
	jaroMatchIndex = UtilFunc.matchName(nameDict, yearbookNames)['AlphaIndex']

	return jaroMatchIndex
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:10,代码来源:ClassmateBatch.py

示例3: pairDistance

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def pairDistance(fileInput, yearbookNamesFile):
#Input:
#		pathInput: path of DIRECTORY with indexed list .csv files
#		yearbookNamesFile: path to name reference FILE
#		pathOutput: name of .csv output file

#Ouput:		
#		Returns a 2D list of name pairs
#Steps:
#		1) open indexedList
#		2) n^2 iterate over the list of indexed values, updating the 2D list of nameValues
#			be careful not to inlude duplicate name-values and same name values

	classSizeConst = 184;  #need to make more general
	classSize = UtilFunc.fileLength(yearbookNamesFile) - 1 # -1 for headers
	if classSizeConst != classSize:
		print '\n\n\n'
		print 'WARNING WARNING: Class Size is {} which is not {}!!!! *****\n'.format(classSize,classSizeConst) * 3
		print '\n\n'

	# pairValues = [[0]*classSize]*classSize #initialize classSize x classSize list #makes an error, probably list copying :(
	pairValues = [[0 for i in range(classSize)] for j in range(classSize)]

	nameList = UtilFunc.parseDataFromFile(fileInput)
	# with open(fileInput, 'r') as fIn:
	# 	for index, line in enumerate(fIn):
	# 		#Skip the heading
	# 		if index > 0:
	# 			(l0,l1,l2,l3,l4,l5,l6,l7) = line.replace('\r','').replace('\n','').split(',')
	# 			nameList.append({'AlphaIndex':l0,'WrittenIndex':l1,'YearbookLast':l4,'YearbookFirst':l5})
		
	for index1, entry1 in enumerate(nameList):
		for index2, entry2 in enumerate(nameList):
			if index1 != index2:
				dim1 = entry1['AlphaIndex']
				if dim1 == 'VERIFY':
					continue
				dim1 = int(dim1)

				dim2 = entry2['AlphaIndex']
				if dim2 == 'VERIFY':
					continue
				dim2 = int(dim2)

				pos1 = entry1['WrittenIndex']
				pos2 = entry2['WrittenIndex']
				if pos1 == '-' or pos2 == '-':
					continue
				# if pos2 == '-':
					# pos2 = classSize
				pos1 = int(pos1)
				pos2 = int(pos2)

				pairValues[dim1][dim2] = 1/float(abs(pos1 - pos2))
				# pairValues[dim2][dim1] = pairValues[dim1][dim2] #redundancy for ease of use
			# print 'dim1: {}\tdim2: {}\tpairValues:{}'.format(dim1,dim2,pairValues[dim1][dim2])
	return {'pairValues':pairValues}
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:59,代码来源:GetPairDistanceIndividual.py

示例4: countListedNames

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def countListedNames(pathInput):
	
	fileListing = os.listdir(pathInput)
	participantCounts = {'TotalListed':{'count':[],'classSize':[]}, 
						 'Grad09Listed':{'count':[],'classSize':[]}}
	classSizeTotal = 0
	classSizeGrad09 = 0
	classSizeSet = False
	classmateIndexes = []
	for fileInput in fileListing:
		#sometimes there are hidden files that break the script
		if(fileInput[0] == '.'):
			continue

		fileData = UtilFunc.parseDataFromFile(os.path.join(pathInput,fileInput))
		counterTotal = 0
		counterGrad09 = 0
		for line in fileData:
			if line['WrittenIndex'] != '-':
				counterTotal += 1
				if line['GraduatedLLA09'] == 'Yes':
					counterGrad09 += 1
			if classSizeSet == False and line['AlphaIndex'] not in classmateIndexes:
				if line['GraduatedLLA09'] == 'Yes':
					classSizeGrad09 += 1
				classSizeTotal += 1
				classmateIndexes.append(line['AlphaIndex'])
		classSizeSet = True
		# with open(os.path.join(pathInput, fileInput), 'r') as fIn:
		# 	counterTotal = 0
		# 	counterGrad09 = 0
		# 	for index2, line in enumerate(fIn):
		# 		#Skip the heading
		# 		if index2 > 0:
		# 			(l0,l1,l2,l3,l4,l5,l6,l7) = line.replace('\r','').replace('\n','').split(',')
		# 			if l1 != '-':
		# 				counterTotal += 1
		# 				if l7 == 'Yes':
		# 					counterGrad09 += 1
		# 			if classSizeSet == False and int(l0) not in classmateIndexes:
		# 				if l7 == 'Yes':
		# 					classSizeGrad09 += 1
		# 				classSizeTotal += 1
		# 				classmateIndexes.append(int(l0))
		# 	classSizeSet = True
			# print 'index: ' + str(index1) + '\tcounter: ' + str(counter) + '\t' + fileInput 
			# print counterGrad09
		participantCounts['TotalListed']['count'].append(counterTotal)
		participantCounts['Grad09Listed']['count'].append(counterGrad09)
		participantCounts['TotalListed']['classSize'] = classSizeTotal
		participantCounts['Grad09Listed']['classSize'] = classSizeGrad09
				  
	return participantCounts
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:55,代码来源:CalculateParticipationStats.py

示例5: sumPairDistance

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def sumPairDistance(pathInput, yearbookNamesFile):
#Input:
#		pathInput: path of DIRECTORY with indexed list .csv files
#		yearbookNamesFile: path to name reference FILE
#		pathOutput: name of .csv output file

#Ouput:		
#		Returns a 2D list of name pairs
#Steps:
#		1) open indexedList
#		2) n^2 iterate over the list of indexed values, updating the 2D list of nameValues
#			be careful not to inlude duplicate name-values and same name values

	classSizeConst = 184;  #need to make more general
	classSize = UtilFunc.fileLength(yearbookNamesFile) - 1 # -1 for headers
	if classSizeConst != classSize:
		print '\n\n\n'
		print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
		print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
		print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
		print '\n\n\n'

	memValueSum = [{'score':0.0,'hits':0.0} for j in range(classSize)] #initialize values to zero

	indexListing = os.listdir(pathInput)
	participantCount = 0.0
	for fileInput in indexListing:
		if fileInput[0] == '.':
			continue
		else:
			participantCount += 1

		nameList = UtilFunc.parseDataFromFile(os.path.join(pathInput, fileInput))
			
		for index1, entry1 in enumerate(nameList):
			dim1 = entry1['AlphaIndex']
			if dim1 == 'VERIFY':
				continue
			dim1 = int(dim1)
			pos1 = entry1['WrittenIndex']
			if pos1 == '-':
				continue
			pos1 = int(pos1) + 1

			memValueSum[dim1]['score'] += 1/float(pos1)
			memValueSum[dim1]['hits'] += 1
	for index in range(len(memValueSum)):
		try:
			memValueSum[index]['score'] /= float(memValueSum[index]['hits'])
		except ZeroDivisionError:
			pass #if it's division by 0, then the score will be zero, but this is an assumption
	return {'memValueSum':memValueSum}
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:54,代码来源:FindMostMemorable.py

示例6: writeToFile

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def writeToFile(memValueSum, yearbookNamesFile, fileOutput):

	#list of dictionaries
	yearbookNames = UtilFunc.parseDataFromFile(yearbookNamesFile)

	with open(fileOutput,'w') as fOut:
		fOut.write('AlphaIndex,MemerableScore,NumberOfLists,YearbookLast,YearbookFirst,GraduatedLLA09\n')
		for index1, entry1 in enumerate(yearbookNames):
			dim1 = int(entry1['AlphaIndex'])

			#TODO rename
			fOut.write('{},{},{},{},{},{}\n'.format(	dim1,
				   									memValueSum[dim1]['score'],
				   									memValueSum[dim1]['hits'],
				   									entry1['YearbookLast'],
				   									entry1['YearbookFirst'],
				   									entry1['GraduatedLLA09']))
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:19,代码来源:FindMostMemorable.py

示例7: attachNames

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def attachNames(groupData,yearbookNamesFile):

	yearbookNames = UtilFunc.parseDataFromFile(yearbookNamesFile)

	groupDataWithNames = []
	for groupMember in groupData:
		gn = int(groupMember['GroupNumber'])
		gs = float(groupMember['GroupScore'])
		ai = int(groupMember['AlphaIndex'])
		ln = yearbookNames[ai]['YearbookLast']
		fn = yearbookNames[ai]['YearbookFirst']
		entry = {	'GroupNumber':gn,
					'GroupScore':gs,
					'AlphaIndex':ai,
					'YearbookLast':ln,
					'YearbookFirst':fn}
		groupDataWithNames.append(entry)

	return groupDataWithNames
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:21,代码来源:BuildGroupsFromPairs.py

示例8: writeToFile

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def writeToFile(pairValueSum, yearbookNamesFile, fileOutput):

	#list of dictionaries
	yearbookNames = UtilFunc.parseDataFromFile(yearbookNamesFile)

	with open(fileOutput,'w') as fOut:
		fOut.write('AlphaIndex_1,AlphaIndex_2,PairScore,Last_1,First_1,Last_2,First_2\n')
		for index1, entry1 in enumerate(yearbookNames):
			for index2, entry2 in enumerate(yearbookNames):
				if index1 != index2:
					dim1 = int(entry1['AlphaIndex'])
					dim2 = int(entry2['AlphaIndex'])

					#TODO rename
					fOut.write('{},{},{},{},{},{},{}\n'.format(	dim1,
						   										dim2,
						   										pairValueSum[dim1][dim2],
						   										entry1['YearbookLast'],
						   										entry1['YearbookFirst'],
						   										entry2['YearbookLast'],
						   										entry2['YearbookFirst']))
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:23,代码来源:GetPairDistanceAll.py

示例9: sumPairDistance

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def sumPairDistance(pathInput, yearbookNamesFile):
#Input:
#		pathInput: path of DIRECTORY with indexed list .csv files
#		yearbookNamesFile: path to name reference FILE
#		pathOutput: name of .csv output file

#Ouput:		
#		Returns a 2D list of name pairs
#Steps:
#		1) open indexedList
#		2) n^2 iterate over the list of indexed values, updating the 2D list of nameValues
#			be careful not to inlude duplicate name-values and same name values

	classSizeConst = 184;  #need to make more general
	classSize = fileLength(yearbookNamesFile) - 1 # -1 for headers
	if classSizeConst != classSize:
		print '\n\n\n'
		print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
		print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
		print 'WARNING WARNING: Class Size is ' + str(classSize) + ' which is not 184!!!! *****'
		print '\n\n\n'

	# pairValueSum = [[0]*classSize]*classSize #initialize classSize x classSize list #bug in this
	pairValueSum = [[0 for i in range(classSize)] for j in range(classSize)]

	indexListing = os.listdir(pathInput)
	participantCount = 0.0
	for fileInput in indexListing:
		if fileInput[0] == '.':
			continue
		else:
			participantCount += 1

		print '#{}\t{}'.format(participantCount,fileInput)
		fileData = UtilFunc.parseDataFromFile(os.path.join(pathInput,fileInput))
		for p in fileData:
			pairValueSum[p['AlphaIndex_1']][p['AlphaIndex_2']] += float(p['PairScore'])
		# with open(os.path.join(pathInput, fileInput), 'r') as fIn:
		# 	for index, line in enumerate(fIn):
		# 		#Skip the heading
		# 		if index > 0:
		# 			(alphaIndex_1,alphaIndex_2,pairScore,last_1,first_1,last_2,first_2) = line.replace('\r','').replace('\n','').split(',')
		# 			pairValueSum[int(alphaIndex_1)][int(alphaIndex_2)] += float(pairScore)
		
	# print pairValueSum
	# print 'WHAT: {}'.format(float(participantCount))
	# print 'CHECKIT: {}'.format(pairValueSum[0][0]/float(participantCount))
	tempDict = {}
	for index1 in range(classSize):
		# if index1 == 0:
		# 	print 'only once'
		for index2 in range(classSize):
			# if (index1,index2) not in tempDict:
			# 	tempDict[(index1,index2)] = 0
			# else:
				# print 'REPeAT!!!'
			#normalize the pair value number by dividing it by the number of participants
			#TODO: add division by zero error handling
			pairValueSum[index1][index2] /= float(participantCount)
			# print pairValueSum[index1][index2]
	print pairValueSum[0][0]
	return {'pairValueSum':pairValueSum}
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:64,代码来源:GetPairDistanceAll.py

示例10: setUp

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
	def setUp(self):
		UtilFunc.prepareDirectory(os.path.join(sys.path[0],'TestFiles/UtilFunc'))
		
		self.refData = UtilFunc.parseDataFromFile('/Users/cdslug/Dropbox/Projects/Tech/Programming/Remembered Classmates/ReportingWork refactored/0_ReferenceFiles/IndexedYearbook.csv')
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:6,代码来源:TestScript.py

示例11: test_parseDataFromFile_01

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
	def test_parseDataFromFile_01(self):
		expectedResult = [{'one':1,'two':2,'three':3},{'one':4.0,'two':5.0,'three':6.0}]
		inputFile = os.path.join(sys.path[0],'TestFiles/UtilFunc/parseDataFromFile1.txt')
		self.assertEqual( UtilFunc.parseDataFromFile(inputFile) , expectedResult )
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:6,代码来源:TestScript.py

示例12: indexList

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def indexList(inputFilePath, inputCompleteFilePath, errorFilePath, yearbookReferenceFilePath, outputFilePath):

	names = []
	#list of dictionaries
	yearbookNames = UtilFunc.parseDataFromFile(yearbookReferenceFilePath)

	#list of dicitonaries
	namesOutput = []

	with open(inputFilePath, 'r') as fWN:
		for writtenIndex, line in enumerate(fWN):
			#could have been simpler, but sometimes last names are not included
			#may have to worry about only last name. Spell checker will reject that
			# lineSplit = line.replace('\n','').split(None,1)[::-1]
			lineSplit = line.replace('\n','').split(None,1)
			l0 = lineSplit[0]
			l1 = ''
			if len(lineSplit) > 1:
				l1 = lineSplit[1]
			else:
				l1 = '_'
			names.append({	'WrittenIndex':str(writtenIndex),
							'WrittenFirst':l0,
							'WrittenLast':l1})

	# with open(yearbookNamesFile, 'r') as fYBN:
	# 	for index, line in enumerate(fYBN):
	# 		#Skip the heading
	# 		if index > 0:
	# 			(l0,l1,l2,l3) = line.replace('\r','').replace('\n','').split(',')
	# 			yearbookNames.append({	'AlphaIndex':l0,
	# 									'YearbookLast':l1,
	# 									'YearbookFirst':l2,
	# 									'GraduatedLLA09':l3})


	namesOutput = []
	for name in names:
		jaroMatch = UtilFunc.matchName(name, yearbookNames)
		namesOutput.append(jaroMatch)

	# for n in namesOutput: #debugging
	# 	print(str(n) + '\n')

	#append missing names
	for ybn in yearbookNames:
		if ybn['AlphaIndex'] not in [no['AlphaIndex'] for no in namesOutput]:
			temp = ybn.copy()
			temp.update({	'WrittenIndex':'-',
							'WrittenLast':'',
							'WrittenFirst':'', 
							'Spelling':str(0)})
			namesOutput.append(temp)

	with open(outputFilePath,'w') as fOut:
		fOut.write('AlphaIndex,WrittenIndex,WrittenLast,WrittenFirst,YearbookLast,YearbookFirst,Spelling,GraduatedLLA09\n')
		for no in namesOutput:
			fOut.write('{},{},{},{},{},{},{},{}\n'.format(	no['AlphaIndex'],
				   											no['WrittenIndex'],
				   											no['WrittenLast'],
				   											no['WrittenFirst'],
				   											no['YearbookLast'],
				   											no['YearbookFirst'],
				   											no['Spelling'],
				   											no['GraduatedLLA09']))

	shutil.copy(inputFilePath,inputCompleteFilePath)
	os.remove(inputFilePath)
	return
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:71,代码来源:IndexList.py

示例13: generateReport

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def generateReport(inputFilePath, inputCompleteFilePath, errorFilePath, yearbookReferenceFilePath, outputFilePath):

	# if(inputFilePath[0] == '.'):
	# 	return -1

	name = inputFilePath.replace('.','_').split('_')[1]
	doc = BaseDocTemplate(outputFilePath,showBoundary=0)
	Elements = []

	#normal frame as for SimpleFlowDocument
	frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height+25, id='normal')

	#Two Columns
	frame1 = Frame(doc.leftMargin, doc.bottomMargin, doc.width/2-inch+20, doc.height, id='col1')
	frame2 = Frame(doc.leftMargin+doc.width/2-inch+12+20, doc.bottomMargin, doc.width/3,
				   doc.height, id='col2')
	frame3 = Frame(doc.leftMargin + doc.width/2+inch+20 +20, doc.bottomMargin, doc.width/3,
				   doc.height, id='col3')

	frameB = Frame(doc.leftMargin+doc.width-100, doc.bottomMargin, 130, 70, id='normal')

	Elements += writeIntro()

	indexedNamesDict = UtilFunc.parseDataFromFile(inputFilePath)
	# with open(inputFilePath, 'r') as pfi:
	# indexedNames = pfi.readlines()
	# indexedNamesDict = []
	# for line in indexedNames:
	# 	(l0,l1,l2,l3,l4,l5,l6,l7) = line.replace('\r','').replace('\n','').split(',')
	# #AlphaIndex,WrittenIndex,WrittenLast,WrittenFirst,YearbookLast,YearbookFirst,Spelling,GraduatedLLA09
	# 	indexedNamesDict.append({'AlphaIndex':l0,
	# 							'WrittenIndex':l1,
	# 							'WrittenLast':l2,
	# 							'WrittenFirst':l3,
	# 							'YearbookLast':l4,
	# 							'YearbookFirst':l5,
	# 							'Spelling':l6,
	# 							'GraduatedLLA09':l7})
	rememberedGrad = []
	forgottenGrad = []
	rememberedNonGrad = []
	forgottenNonGrad = []

	for entry in indexedNamesDict:
		if entry['GraduatedLLA09'].lower() == 'yes':
			if entry['WrittenIndex'] == '-':
				forgottenGrad.append(entry)
			else:
				rememberedGrad.append(entry)
		elif entry['GraduatedLLA09'].lower() == 'no':
			if entry['WrittenIndex'] == '-':
				forgottenNonGrad.append(entry)
			else:
				rememberedNonGrad.append(entry)

	rgCount = len(set([n['AlphaIndex'] for n in rememberedGrad]))
	fgCount = len(forgottenGrad)
	rngCount = len(set([n['AlphaIndex'] for n in rememberedNonGrad]))
	fngCount = len(forgottenNonGrad)
	Elements += constructSingleColumnParagraphs(['<br/><b>{}</b> students graduated in \'09 and <br/>'.format(rgCount + fgCount) +
												 '<b>{}</b> additional students attended in either \'06, \'07, or \'08.'.format(rngCount + fngCount)])
	

	drawing = MyDrawing()
	newData = [(fgCount,'{} classmates were not remembered (\'09)'.format(fgCount)),
			   (rgCount,'{} classmates were remembered (\'09)'.format(rgCount)),
			   (fngCount,'{} classmates were not remembered (other)'.format(fngCount)),
			   (rngCount,'{} classmates were remembered (other)'.format(rngCount))]

	drawing.setNewData(newData)
	Elements.append(drawing)

	Elements += writeColumnExplanation()

	rememberedGradString = [(n['WrittenFirst'] + ' ' + n['WrittenLast'])
						   for n in rememberedGrad]
	rememberedGradStringSp = [(n['YearbookFirst'] + ' ' + n['YearbookLast'])
						     if n['Spelling'] != 1
						     else ''
						     for n in rememberedGrad]
	forgottenGradString = [n['YearbookFirst'] + ' ' + n['YearbookLast'] for n in forgottenGrad]
	
	rememberedNonGradString = [(n['WrittenFirst'] + ' ' + n['WrittenLast'])
							  for n in rememberedNonGrad]
	rememberedNonGradStringSp = [(n['YearbookFirst'] + ' ' + n['YearbookLast'])
						        if n['Spelling'] != 1
						        else ''
						        for n in rememberedNonGrad]						  
	forgottenNonGradString = [n['YearbookFirst'] + ' ' + n['YearbookLast'] for n in forgottenNonGrad]


	listTitles09 = ['Not Remembered in 09','Remembered in 09', 'Yearbook Spelling']
	listTitlesOther = ['Not Remembered in 06, 07, or 08', 'Remembered in 06, 07, or 08', 'Yearbook Spelling']
	Elements += constructTrippleColumns(forgottenGradString,rememberedGradString, rememberedGradStringSp, listTitles09)
	Elements += constructTrippleColumns(forgottenNonGradString,rememberedNonGradString, rememberedNonGradStringSp, listTitlesOther)


	Elements += writeEndingCredit()

	doc.addPageTemplates([PageTemplate(id='OneCol',frames=frameT,onPage=foot2),
#.........这里部分代码省略.........
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:103,代码来源:GenerateReport.py

示例14: buildGroups

# 需要导入模块: import UtilFunc [as 别名]
# 或者: from UtilFunc import parseDataFromFile [as 别名]
def buildGroups(fileInput):

	pairList = UtilFunc.parseDataFromFile(fileInput)
	
	# with open(fileInput, 'r') as fIn:
	# 	for index, line in enumerate(fIn):
	# 		#Skip the heading
	# 		if index > 0:
	# 			(l0,l1,l2,l3,l4,l5,l6) = line.replace('\r','').replace('\n','').split(',')
	# 			pairList.append({	'AlphaIndex_1':int(l0),
	# 								'AlphaIndex_2':int(l1),
	# 								'PairScore':float(l2),
	# 								'Last_1':l3,
	# 								'First_1':l4,
	# 								'Last_2':l5,
	# 								'First_2':l6})

	classSize = int(math.ceil(math.sqrt(len(pairList)))) #fancy because of ignorning when index = index
	pairMatrix = [[0 for i in range(classSize)] for j in range(classSize)]
	for pair in pairList:
		index1 = pair['AlphaIndex_1']
		index2 = pair['AlphaIndex_2']
		pairMatrix[index1][index2] = pair['PairScore']
		pairMatrix[index2][index1] = pair['PairScore']

	sortedPairList = sorted(pairList, key=lambda pairs: pairs['PairScore'])[::-1]

	groupNumber = 0
	groupScoreOld = 0;
	groupScoreNew = 0;
	groupData = []
	scoreHistory = [{'Score':0,'AlphaIndex':-1}] #contains dict of score and one member alphIndex
#0A) Divide classmates into groups of 2
#1) Iterate over people until there are very few members changing
#	It might help to randomly choose members for each iteration, or go back and forth
#	Maybe I should keep track of the classmates that keep jumping back and forth
#2) keep a global list of groups that can change
#	need to figure out how to access/store/change group numbers and members
#3) For a classmate, check to see which group he/she has the strongest average pair score with
#	
#Info 1) keep of a list of groups to members and members to groups


	groupNumber = 0
	initialGroupSize = 1
	groups2Members = [[] for l in range((classSize//initialGroupSize) + 1)] #initialize empty lists
	members2Groups = [[] for l in range(classSize)]

	order = [x for x in range(classSize)]
	random.shuffle(order)
	for pos,randomMember in enumerate(order):
		groups2Members[pos//initialGroupSize].append(randomMember)
		members2Groups[randomMember] = pos//initialGroupSize

	#print 'order: ' + str(order)
	#print 'groups2Members' + str(groups2Members)
	numberGroupChanges = classSize
	n = 0
	print 'ClassSize: {}'.format(classSize)
	# while numberGroupChanges > classSize * 0.01:
	for r in range(len(order)//3): #range was found by observation of data
		numberGroupChanges = 0
		random.shuffle(order)
		groups2MembersTemp = groups2Members
		for randomMember in order:
			bg = bestGroup(randomMember, groups2Members, members2Groups, pairMatrix)
			if bg != members2Groups[randomMember] and bg != -1:
				#print 'OLD'
				groupScoreOld = getGroupScore(groups2Members[bg], pairMatrix)
				#print 'NEW'
				#print groups2Members[bg] + [randomMember]
				groupScoreNew = getGroupScore(groups2Members[bg] + [randomMember], pairMatrix)
				#print 'groupScoreNew' + str(groupScoreNew)

				#print 'old score: ' + str(groupScoreOld) + ', new score: ' + str(groupScoreNew)
			#if ratioNew > ratioOld: # try with exponents now that the score is updated correctly
				powerFilter = 1.5
				if True or groupScoreNew / (float(len(groups2Members[bg]) + 1)**powerFilter) > groupScoreOld / (float(len(groups2Members[bg]))**powerFilter) and \
				   len(groups2Members[bg]) < 50:
					groups2Members[members2Groups[randomMember]].remove(randomMember)
					#if len(groups2Members[members2Groups[randomMember]]) == 0:
						#print '000 Group Shrunk to Zero! 000'
					groups2Members[bg].append(randomMember)
					#print 'Classmate Changed Groups  ' + str(randomMember)
					members2Groups[randomMember] = bg
					numberGroupChanges += 1
		n = n+1
		print 'iteration #{}, numberGroupChanges: {}'.format(n,numberGroupChanges)

	#print 'groups2Members' + str(groups2Members)

	for memberNumber,groupNumber in enumerate(members2Groups):
		groupScore = groups2Members[groupNumber]
		groupData.append({	'GroupNumber':groupNumber,
							'GroupScore':getGroupScore(groupScore,pairMatrix),
							'AlphaIndex':memberNumber})
	return sorted(groupData, key=lambda gd: gd['GroupNumber'])
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:99,代码来源:BuildGroupsFromPairs.py


注:本文中的UtilFunc.parseDataFromFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。