예제 #1
0
    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
0
    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()
예제 #3
0
 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()
     
     
	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()