本文整理匯總了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()
示例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()