當前位置: 首頁>>代碼示例>>Python>>正文


Python UtilFunc.fileLength方法代碼示例

本文整理匯總了Python中UtilFunc.fileLength方法的典型用法代碼示例。如果您正苦於以下問題:Python UtilFunc.fileLength方法的具體用法?Python UtilFunc.fileLength怎麽用?Python UtilFunc.fileLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UtilFunc的用法示例。


在下文中一共展示了UtilFunc.fileLength方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pairDistance

# 需要導入模塊: import UtilFunc [as 別名]
# 或者: from UtilFunc import fileLength [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

示例2: sumPairDistance

# 需要導入模塊: import UtilFunc [as 別名]
# 或者: from UtilFunc import fileLength [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

示例3: test_fileLength_04

# 需要導入模塊: import UtilFunc [as 別名]
# 或者: from UtilFunc import fileLength [as 別名]
	def test_fileLength_04(self):
		self.assertEqual( UtilFunc.fileLength(os.path.join(sys.path[0],'TestFiles/UtilFunc/fileLength4.txt')) , 2 )
開發者ID:cdslug,項目名稱:ClassmateMemory,代碼行數:4,代碼來源:TestScript.py

示例4: test_fileLength_01

# 需要導入模塊: import UtilFunc [as 別名]
# 或者: from UtilFunc import fileLength [as 別名]
	def test_fileLength_01(self):
		###TODO: determine if ending a file with '\n' means the blank line counts towards the file length
		self.assertEqual( UtilFunc.fileLength(os.path.join(sys.path[0],'TestFiles/UtilFunc/fileLength1.txt')) , 5 )
開發者ID:cdslug,項目名稱:ClassmateMemory,代碼行數:5,代碼來源:TestScript.py


注:本文中的UtilFunc.fileLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。