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


Python UtilFunc类代码示例

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


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

示例1: getNumberFromNameInFile

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,代码行数:8,代码来源:ClassmateBatch.py

示例2: pairDistance

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,代码行数:57,代码来源:GetPairDistanceIndividual.py

示例3: sumPairDistance

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,代码行数:52,代码来源:FindMostMemorable.py

示例4: setUp

	def setUp(self):
		UtilFunc.prepareDirectory(os.path.join(sys.path[0],'TestFiles/FixRawList'))
		UtilFunc.prepareDirectory(os.path.join(sys.path[0],'TestFiles/FixRawList/Input'))
		UtilFunc.prepareDirectory(os.path.join(sys.path[0],'TestFiles/FixRawList/InputComplete'))
		UtilFunc.prepareDirectory(os.path.join(sys.path[0],'TestFiles/FixRawList/Output'))

		self.inputFile = 		os.path.join(sys.path[0],'TestFiles/FixRawList/Input/fixRawList1_Input_MercerRyan_14.txt')
		self.inputCompleteFile = os.path.join(sys.path[0],'TestFiles/FixRawList/InputComplete/fixRawList1_Input_MercerRyan_14.txt')
		self.outputFile = 		os.path.join(sys.path[0],'TestFiles/FixRawList/Output/fixRawList1_Output_MercerRyan_14.txt')

		self.names = ['Ryan Mercer','Erik Scott Lunsford','Andrew Muinos','Yuki Chavez','Charles Eaton','Kunal Shah','Eric Crawford','Matthew MacDonald','Lisa']
		with open(self.inputFile, 'w') as f:
			###name1 is normal with a '\n' after
			###name2 has 3 parts
			###name3 has a ','
			###name4 has a ',' and '\n' after
			###name5 has a ',' (preparing for next)
			###name6 has a ' ' before and ',\n ' after
			###name7 is part of testing name6
			###name7-8 is blank
			###name8 has a '\r' after
			###name9 has only 1 part
			f.write('{}\n{}\n{},{},\n{}, {},\n {},\'\',{}\r{}'.format(	self.names[0],
																		self.names[1],
																		self.names[2],
																		self.names[3],
																		self.names[4],
																		self.names[5],
																		self.names[6],
																		self.names[7],
																		self.names[8]))
			FixRawList.fixRawList(self.inputFile,self.inputCompleteFile,self.outputFile)
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:32,代码来源:TestScript.py

示例5: getDataClass

def getDataClass(fileInputs):
	dataClass = {}

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

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

示例6: countListedNames

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,代码行数:53,代码来源:CalculateParticipationStats.py

示例7: writeToFile

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,代码行数:17,代码来源:FindMostMemorable.py

示例8: attachNames

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,代码行数:19,代码来源:BuildGroupsFromPairs.py

示例9: writeToFile

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,代码行数:21,代码来源:GetPairDistanceAll.py

示例10: test_parseNumberFromFile_03

	def test_parseNumberFromFile_03(self):
		self.assertEqual( UtilFunc.parseNumberFromFile('parentPath/Word_Input_LastFirst_-3.py') , '' )
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:2,代码来源:TestScript.py

示例11: test_parseNameFromFile_03

	def test_parseNameFromFile_03(self):
		self.assertEqual( UtilFunc.parseNameFromFile('parentPath/Word_Input_LastFirst.py') , 'LastFirst' )
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:2,代码来源:TestScript.py

示例12: test_fileLength_04

	def test_fileLength_04(self):
		self.assertEqual( UtilFunc.fileLength(os.path.join(sys.path[0],'TestFiles/UtilFunc/fileLength4.txt')) , 2 )
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:2,代码来源:TestScript.py

示例13: test_interpretString_03

	def test_interpretString_03(self):
		self.assertEqual( UtilFunc.interpretString('1.0'),1.0)
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:2,代码来源:TestScript.py

示例14: test_matchName_07

	def test_matchName_07(self):
		name = [{'WrittenLast':'Min','WrittenFirst':'Twins'},['Min','Nicolas'],None]
		returnValue = UtilFunc.matchName(name[0],self.refData,name[2])
		self.assertEqual([returnValue['YearbookLast'],returnValue['YearbookFirst']],name[1])
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:4,代码来源:TestScript.py

示例15: test_interpretString_01

	def test_interpretString_01(self):
		self.assertEqual( UtilFunc.interpretString(''),'')
开发者ID:cdslug,项目名称:ClassmateMemory,代码行数:2,代码来源:TestScript.py


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