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


Python FormatingDataSets.getTotalLineNumbers方法代码示例

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


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

示例1: __init__

# 需要导入模块: from formating.FormatingDataSets import FormatingDataSets [as 别名]
# 或者: from formating.FormatingDataSets.FormatingDataSets import getTotalLineNumbers [as 别名]
 def __init__(self, preparedParameter, filepathNodesNotLinked, filepathResult, filePathOrdered, filepathMaxMinCalculated):
     print "Starting Calculating Nodes not linked", datetime.today()
     
     self.preparedParameter = preparedParameter
     self.filePathOrdered = Formating.get_abs_file_path(filePathOrdered)
     self.filepathMaxMinCalculated = Formating.get_abs_file_path(filepathMaxMinCalculated)
     self.filepathResult = Formating.get_abs_file_path(filepathResult)
     self.filepathNodesNotLinked = Formating.get_abs_file_path(filepathNodesNotLinked)
     #for each links that is not linked all the calculates is done.
     element = 0
     qtyofResults = FormatingDataSets.getTotalLineNumbers(self.filepathNodesNotLinked)
     fcontentNodesNotLinked = open(self.filepathNodesNotLinked, 'r')
     if os.path.exists(self.filepathResult):
         print "Calculate already done for this file, please delete if you want a new one.", datetime.today()
         self.reading_Max_min_file()
         return
     
     fcontentCalcResult = open(self.filepathResult, 'w')
     
     self.minValueCalculated = list(99999 for x in self.preparedParameter.featuresChoice)
     self.maxValueCalculated = list(0 for x in self.preparedParameter.featuresChoice)
     
     qtyFeatures = len(self.preparedParameter.featuresChoice)
     qtyNodesCalculated = 0
     partialResults = []
     for lineofFile in fcontentNodesNotLinked:
         element = element+1
         item = VariableSelection.getItemFromLine(lineofFile)
         qtyothernodenotlinked = len(item[1])
         newelement = 0
         for neighbor_node in item[1]:
             newelement = newelement +1
             qtyNodesCalculated = qtyNodesCalculated + 1
             self.printProgressofEvents(element, qtyofResults, "Calculating features for nodes not liked: ")
             self.printProgressofEventsWihoutPercent(newelement, qtyothernodenotlinked, "Calculating nodes: " + str(item[0])  + ":" +  str(neighbor_node) )
         
             item_result = []
             #executing the calculation for each features chosen at parameter
             for index_features in range(qtyFeatures):
                 self.preparedParameter.featuresChoice[index_features][0].parameter = preparedParameter
                 valueCalculated = self.preparedParameter.featuresChoice[index_features][0].execute(item[0],neighbor_node) * self.preparedParameter.featuresChoice[index_features][1]
                 if valueCalculated < self.minValueCalculated[index_features]:
                     self.minValueCalculated[index_features] = valueCalculated
                 if valueCalculated > self.maxValueCalculated[index_features]:
                     self.maxValueCalculated[index_features] = valueCalculated
                     
                 item_result.append(valueCalculated)
             
             lineContent = []    
             #generating a vetor with the name of the feature and the result of the calculate
             for indice in range(qtyFeatures):
                 lineContent.append(str({str(self.preparedParameter.featuresChoice[indice]):item_result[indice]}) )
             partialResults.append([lineContent, item[0], neighbor_node])
             
         if element % 10 == 0:
             for item in partialResults:
                 for calc in item[0]:
                     fcontentCalcResult.write(calc + '\t')
                 fcontentCalcResult.write(str(item[1]) + '\t' + str(item[2])  + '\n'  )
             partialResults = []
     
     for item in partialResults:
         for calc in item[0]:
             fcontentCalcResult.write(calc + '\t')
         fcontentCalcResult.write(str(item[1]) + '\t' + str(item[2])  + '\n'  )
             
     
     fcontentCalcResult.flush()
     fcontentCalcResult.close()
     fcontentNodesNotLinked.close()
     fcontentMaxMin = open(self.filepathMaxMinCalculated, 'w')
     fcontentMaxMin.write(str(qtyNodesCalculated) + '\t' + repr(self.minValueCalculated) + '\t' + repr(self.maxValueCalculated) )
     fcontentMaxMin.close()
     print "Calculating Nodes not linked finished", datetime.today()
     
     
开发者ID:joaomarcosgris,项目名称:Predicao-de-Links,代码行数:76,代码来源:Calculate.py

示例2: __init__

# 需要导入模块: from formating.FormatingDataSets import FormatingDataSets [as 别名]
# 或者: from formating.FormatingDataSets.FormatingDataSets import getTotalLineNumbers [as 别名]
	def __init__(self, preparedParameter, filepathNodesNotLinked, filepathResult, filePathOrdered, filepathMaxMinCalculated):
		print "Starting Calculating Nodes not linked", datetime.today()
		
		self.preparedParameter = preparedParameter
		self.filePathOrdered = Formating.get_abs_file_path(filePathOrdered)
		self.filepathMaxMinCalculated = Formating.get_abs_file_path(filepathMaxMinCalculated)
		self.filepathResult = Formating.get_abs_file_path(filepathResult)
		self.filepathNodesNotLinked = Formating.get_abs_file_path(filepathNodesNotLinked)
		#for each links that is not linked all the calculates is done.
		element = 0
		qtyofResults = FormatingDataSets.getTotalLineNumbers(self.filepathNodesNotLinked)
		fcontentNodesNotLinked = open(self.filepathNodesNotLinked, 'r')
		if os.path.exists(self.filepathResult):
			print "Calculate already done for this file, please delete if you want a new one.", datetime.today()
			return
		
		fcontentCalcResult = open(self.filepathResult, 'w')
		
		self.minValueCalculated = list(99999 for x in self.preparedParameter.featuresChoice)
		self.maxValueCalculated = list(0 for x in self.preparedParameter.featuresChoice)
		
		qtyFeatures = len(self.preparedParameter.featuresChoice)
		self.qtyDataCalculated = 0
		
		out_q = multiprocessing.Queue()
		procs = []
		nprocs = 100
		for lineofFile in fcontentNodesNotLinked:
			element = element+1
			
			p = multiprocessing.Process(target=self.calculating_features, args=(lineofFile,element,qtyofResults  , preparedParameter, qtyFeatures , self.minValueCalculated, self.maxValueCalculated,  out_q))
			procs.append(p)
			p.start()
			
			
			if len(procs) >= nprocs:
				for i in range(len(procs)):
					result  = out_q.get()
					result = result.split('|')
					
					mini = eval(result[0])
					maxi = eval(result[1])
					
					self.qtyDataCalculated = self.qtyDataCalculated + int(result[2])
					fcontentCalcResult.write(result[3])
					for index_features in range(qtyFeatures):
						if   mini[index_features] < self.minValueCalculated[index_features]:
							self.minValueCalculated[index_features] = mini[index_features]
						if maxi[index_features] > self.maxValueCalculated[index_features]:
							self.maxValueCalculated[index_features] = maxi[index_features]
							
				for p in procs:
					p.join()
				procs = []
		
		for i in range(len(procs)):
			result  = out_q.get()
			result = result.split('|')
					
			mini = eval(result[0])
			maxi = eval(result[1])
			self.qtyDataCalculated = self.qtyDataCalculated + int(result[2])
			
			fcontentCalcResult.write(result[3])
			
			for index_features in range(qtyFeatures):
				if   mini[index_features] < self.minValueCalculated[index_features]:
					self.minValueCalculated[index_features] = mini[index_features]
				if maxi[index_features] > self.maxValueCalculated[index_features]:
					self.maxValueCalculated[index_features] = maxi[index_features]
			
		for p in procs:
			p.join()
				
		fcontentCalcResult.flush()
		fcontentCalcResult.close()
		fcontentNodesNotLinked.close()
		fcontentMaxMin = open(self.filepathMaxMinCalculated, 'w')
		fcontentMaxMin.write(str(self.qtyDataCalculated) + '\t' + repr(self.minValueCalculated) + '\t' + repr(self.maxValueCalculated) )
		fcontentMaxMin.close()
		print "Calculating Nodes not linked finished", datetime.today()
		
		
开发者ID:joaomarcosgris,项目名称:Predicao-de-Links,代码行数:83,代码来源:CalculateMultiProcessing.py


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