def plotDegreeDistribution(self,degreeList,GameCount,dataType, gameType): p = Preprocess() cachePath = '/home/yotoo/Project/comparison/' plotPath = '/home/yotoo/Project/logPlot/' # details about the data maximum = degreeList[len(degreeList)-1] dist = {} for d in degreeList: for i in range(1,maximum+1): if (d == i): if(dist.has_key(i)==False): dist[i] = 1 else: degree = dist[i] degree = degree + 1 dist[i] = degree else: continue print dist.items() # plot degree distribution degrees = dist.keys() players = dist.values() #details about this distribution sortedP = dist.values() sortedP.sort() sortedD = dist.keys() sortedD.sort() minimum = sortedP[0] sortedP.reverse() maximum = sortedP[0] playerCount = len(players) degreeCount = len(degrees) medianIndex = (minimum + degreeCount) / 2 Q1Index = (minimum + medianIndex) / 2 Q3Index = (medianIndex + degreeCount) / 2 median = sortedD[medianIndex] Q1 = sortedD[Q1Index] Q3 = sortedD[Q3Index] kurtosis = self.getKurtosisSkewness(degrees) plotText = 'Total Games: %d \nTotal Players: %d \nMaximum Degree: %d \nQ3 Degree: %d\nMedian Degree: %d \nQ1 Degree: %d \nMinimum Degree: %d \nKurtosis: %.2e' %(GameCount,playerCount,maximum,Q3,median,Q1,minimum,kurtosis) #dataType if (dataType == 'Real Data'): savePath = plotPath + 'real_data/' if (gameType == '19+ranked'): title = 'Degree Distribution(Border size: 19; Game Type: Ranked)' # # original plt.grid(True) plt.xlabel('Degree') plt.ylabel('Players') plt.title(title) plt.plot(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' original' + ".png") plt.show() # # log degree plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Players') plt.title(title) plt.semilogx(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' log x' + ".png") plt.show() # # log players plt.grid(True) plt.xlabel('Degree') plt.ylabel(' Log Players') plt.title(title) plt.semilogy(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' log y' + ".png") plt.show() # # log degrees and players plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Log Players') plt.title(title) plt.loglog(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' log x y' + ".png") plt.show() # # plot 4-up images for original, log x and y, log x, log y # original plt.subplot(221) plt.plot(degrees,players,'ro') plt.title('Original Plot') plt.grid(True) #log degrees plt.subplot(222) plt.semilogx(degrees,players,'ro') plt.title('Log Degrees') plt.grid(True) #log players plt.subplot(223) plt.semilogy(degrees,players,'ro') plt.title('Log Players') plt.grid(True) #log degrees and players plt.subplot(224) plt.loglog(degrees,players,'ro') plt.title('Log Degrees and Players') plt.grid(True) plt.savefig(savePath + "random_data_19_ranked_4_ups.png") plt.show() p.save(dist,cachePath+title+'.txt') elif (gameType == '19+free'): title = 'Degree Distribution(Border size: 19; Game Type: Free)' # # original plt.grid(True) plt.xlabel('Degree') plt.ylabel('Players') plt.title(title) plt.plot(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' original' + ".png") plt.show() # # log degree plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Players') plt.title(title) plt.semilogx(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' log x' + ".png") plt.show() # # log players plt.grid(True) plt.xlabel('Degree') plt.ylabel(' Log Players') plt.title(title) plt.semilogy(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' log y' + ".png") plt.show() # # log degrees and players plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Log Players') plt.title(title) plt.loglog(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' log x y' + ".png") plt.show() # # plot 4-up images for original, log x and y, log x, log y # original plt.subplot(221) plt.plot(degrees,players,'gs') plt.title('Original Plot') plt.grid(True) #log degrees plt.subplot(222) plt.semilogx(degrees,players,'gs') plt.title('Log Degrees') plt.grid(True) #log players plt.subplot(223) plt.semilogy(degrees,players,'sg') plt.title('Log Players') plt.grid(True) #log degrees and players plt.subplot(224) plt.loglog(degrees,players,'sg') plt.title('Log Degrees and Players') plt.grid(True) plt.savefig(savePath + "random_data_19_free_4_ups.png") plt.show() p.save(dist,cachePath+title+'.txt') elif (gameType == '9+free'): title = 'Degree Distribution(Border size: 9; Game Type: Free)' # # original plt.grid(True) plt.xlabel('Degree') plt.ylabel('Players') plt.title(title) plt.plot(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' original' + ".png") plt.show() # # log degree plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Players') plt.title(title) plt.semilogx(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' log x' + ".png") plt.show() # # log players plt.grid(True) plt.xlabel('Degree') plt.ylabel(' Log Players') plt.title(title) plt.semilogy(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' log y' + ".png") plt.show() # # log degrees and players plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Log Players') plt.title(title) plt.loglog(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' log x y' + ".png") plt.show() # # plot 4-up images for original, log x and y, log x, log y # original plt.subplot(221) plt.plot(degrees,players,'b^') plt.title('Original Plot') plt.grid(True) #log degrees plt.subplot(222) plt.semilogx(degrees,players,'b^') plt.title('Log Degrees') plt.grid(True) #log players plt.subplot(223) plt.semilogy(degrees,players,'b^') plt.title('Log Players') plt.grid(True) #log degrees and players plt.subplot(224) plt.loglog(degrees,players,'b^') plt.title('Log Degrees and Players') plt.grid(True) plt.savefig(savePath + "random_data_9_free_4_ups.png") plt.show() p.save(dist,cachePath+title+'.txt') elif (dataType == 'Random Data'): savePath = plotPath + '/random_data/' if (gameType == '19+ranked'): title = 'Degree Distribution(Border size: 19; Game Type: Ranked) *random ' # # original plt.grid(True) plt.xlabel('Degree') plt.ylabel('Players') plt.title(title) plt.plot(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' original' + ".png") plt.show() # # log degree plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Players') plt.title(title) plt.semilogx(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' log x' + ".png") plt.show() # # log players plt.grid(True) plt.xlabel('Degree') plt.ylabel(' Log Players') plt.title(title) plt.semilogy(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' log y' + ".png") plt.show() # # log degrees and players plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Log Players') plt.title(title) plt.loglog(degrees,players,'ro',label = plotText) plt.legend() plt.savefig(savePath + title+' log x y' + ".png") plt.show() # # plot 4-up images for original, log x and y, log x, log y # original plt.subplot(221) plt.plot(degrees,players,'ro') plt.title('Original Plot') plt.grid(True) #log degrees plt.subplot(222) plt.semilogx(degrees,players,'ro') plt.title('Log Degrees') plt.grid(True) #log players plt.subplot(223) plt.semilogy(degrees,players,'ro') plt.title('Log Players') plt.grid(True) #log degrees and players plt.subplot(224) plt.loglog(degrees,players,'ro') plt.title('Log Degrees and Players') plt.grid(True) plt.savefig(savePath + "random_data_19_ranked_4_ups.png") plt.show() p.save(dist,cachePath+title+'.txt') elif (gameType == '19+free'): title = 'Degree Distribution(Border size: 19; Game Type: Free) *random ' # # original plt.grid(True) plt.xlabel('Degree') plt.ylabel('Players') plt.title(title) plt.plot(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' original' + ".png") plt.show() # # log degree plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Players') plt.title(title) plt.semilogx(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' log x' + ".png") plt.show() # # log players plt.grid(True) plt.xlabel('Degree') plt.ylabel(' Log Players') plt.title(title) plt.semilogy(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' log y' + ".png") plt.show() # # log degrees and players plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Log Players') plt.title(title) plt.loglog(degrees,players,'gs',label = plotText) plt.legend() plt.savefig(savePath + title+' log x y' + ".png") plt.show() # # plot 4-up images for original, log x and y, log x, log y # original plt.subplot(221) plt.plot(degrees,players,'gs') plt.title('Original Plot') plt.grid(True) #log degrees plt.subplot(222) plt.semilogx(degrees,players,'gs') plt.title('Log Degrees') plt.grid(True) #log players plt.subplot(223) plt.semilogy(degrees,players,'sg') plt.title('Log Players') plt.grid(True) #log degrees and players plt.subplot(224) plt.loglog(degrees,players,'sg') plt.title('Log Degrees and Players') plt.grid(True) plt.savefig(savePath + "random_data_19_free_4_ups.png") plt.show() p.save(dist,cachePath+title+'.txt') elif (gameType == '9+free'): title = 'Degree Distribution(Border size: 9; Game Type: Free) *random ' # # original plt.grid(True) plt.xlabel('Degree') plt.ylabel('Players') plt.title(title) plt.plot(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' original' + ".png") plt.show() # # log degree plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Players') plt.title(title) plt.semilogx(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' log x' + ".png") plt.show() # # log players plt.grid(True) plt.xlabel('Degree') plt.ylabel(' Log Players') plt.title(title) plt.semilogy(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' log y' + ".png") plt.show() # # log degrees and players plt.grid(True) plt.xlabel('Log Degree') plt.ylabel('Log Players') plt.title(title) plt.loglog(degrees,players,'b^',label = plotText) plt.legend() plt.savefig(savePath + title+' log x y' + ".png") plt.show() # # plot 4-up images for original, log x and y, log x, log y # original plt.subplot(221) plt.plot(degrees,players,'b^') plt.title('Original Plot') plt.grid(True) #log degrees plt.subplot(222) plt.semilogx(degrees,players,'b^') plt.title('Log Degrees') plt.grid(True) #log players plt.subplot(223) plt.semilogy(degrees,players,'b^') plt.title('Log Players') plt.grid(True) #log degrees and players plt.subplot(224) plt.loglog(degrees,players,'b^') plt.title('Log Degrees and Players') plt.grid(True) plt.savefig(savePath + "random_data_9_free_4_ups.png") plt.show() p.save(dist,cachePath+title+'.txt')
def main(): ############################################################# # Real Code # # initialization startTime = time.time() process = Preprocess() relation = Relationship() comparison = Comparison() clustering = Clustering() #--------------------------------Preprocess Data----------------------------------------------------------- # data = P.load('cleandata.txt') # cleandata = P.preprocess(data,'19+ranked') # randomData = P.createRandomData(cleandata,50000) # P.save(cleandata,'prepro_data_19_ranked.txt') # cleandata = P.preprocess(data,'19+free') # P.save(cleandata,'prepro_data_19_free.txt') # cleandata = P.preprocess(data,'9+ranked') # P.save(cleandata,'prepro_data_9_ranked.txt') # cleandata = P.preprocess(data,'9+free') # P.save(cleandata,'prepro_data_9_free.txt') # # create random data # cleandata = P.load('prepro_data_19_ranked.txt') # randomData = P.getSubset(cleandata,50000,'Random') # P.save(randomData,'prepro_random_data_19_ranked.txt') # cleandata = P.load('prepro_data_19_free.txt') # randomData = P.getSubset(cleandata,50000,'Random') # P.save(randomData,'prepro_random_data_19_free.txt') # cleandata = P.load('prepro_data_9_free.txt') # randomData = P.getSubset(cleandata,50000,'Random') # P.save(randomData,'prepro_random_data_9_free.txt') #-----------------------------------Degree Distribution----------------------------------------------------------- # data = process.load('prepro_data_19_ranked.txt') # relationship = relation.findRelationship(data) # gameCount = len(data) # degreeList = relation.cleanRelationship(relationship,'DegreeDistribution') # relation.plotDegreeDistribution(degreeList,gameCount, 'Real Data', '19+ranked') # data = process.load('prepro_data_19_free.txt') # relationship = relation.findRelationship(data) # gameCount = len(data) # degreeList = relation.cleanRelationship(relationship,'DegreeDistribution') # relation.plotDegreeDistribution(degreeList,gameCount,'Real Data','19+free') # # can not find records match "border size: 9 & game type: free" # data = process.load('prepro_data_9_free.txt') # relationship = relation.findRelationship(data) # gameCount = len(data) # degreeList = relation.cleanRelationship(relationship,'DegreeDistribution') # relation.plotDegreeDistribution(degreeList,gameCount,'Real Data','9+free') # # # random data # data = process.load('prepro_random_data_19_ranked.txt') # relationship = relation.findRelationship(data) # gameCount = len(data) # degreeList = relation.cleanRelationship(relationship,'DegreeDistribution') # relation.plotDegreeDistribution(degreeList,gameCount,'Random Data','19+ranked') # data = process.load('prepro_random_data_19_free.txt') # relationship = relation.findRelationship(data) # gameCount = len(data) # degreeList = relation.cleanRelationship(relationship,'DegreeDistribution') # relation.plotDegreeDistribution(degreeList,gameCount,'Random Data','19+free') # # # can not find records match "border size: 9 & game type: free" # data = process.load('prepro_random_data_9_free.txt') # relationship = relation.findRelationship(data) # gameCount = len(data) # degreeList = relation.cleanRelationship(relationship,'DegreeDistribution') # relation.plotDegreeDistribution(degreeList,gameCount,'Random Data','9+free') #------------------------------------Shortest Path------------------------------------------------------------------- # data = P.load('prepro_data_19_ranked.txt') # relationship = R.findRelationship(data) # playerList = relationship.keys() # playerList.sort() # P.save(playerList,'playerList_19_ranked.txt') # pathMatrix = R.createPathMatrix(relationship,playerList) # print pathMatrix # data = P.load('prepro_data_19_free.txt') # relationship = R.findRelationship(data) # playerList = relationship.keys() # playerList.sort() # P.save(playerList,'playerList_19_free.txt') # pathMatrix = R.createPathMatrix(relationship,playerList) # print pathMatrix # data = P.load('prepro_data_9_free.txt') # relationship = R.findRelationship(data) # playerList = relationship.keys() # playerList.sort() # P.save(playerList,'playerList_9_free.txt') # pathMatrix = R.createPathMatrix(relationship,playerList) # print pathMatrix # # random data # data = P.load('prepro_random_data_19_ranked.txt') # relationship = R.findRelationship(data) # playerList = relationship.keys() # playerList.sort() # P.save(playerList,'playerList__random_19_ranked.txt') # pathMatrix = R.createPathMatrix(relationship,playerList) # print pathMatrix # P.save(pathMatrix,'pathMatrix_19_ranked.txt') # data = P.load('prepro_random_data_19_free.txt') # relationship = R.findRelationship(data) # playerList = relationship.keys() # playerList.sort() # P.save(playerList,'playerList_random_19_free.txt') # pathMatrix = R.createPathMatrix(relationship,playerList) # print pathMatrix # P.save(pathMatrix,'pathMatrix_19_free.txt') # data = P.load('prepro_random_data_9_free.txt') # relationship = R.findRelationship(data) # playerList = relationship.keys() # playerList.sort() # P.save(playerList,'playerList_random_9_free.txt') # pathMatrix = R.createPathMatrix(relationship,playerList) # print pathMatrix # P.save(pathMatrix,'pathMatrix_9_free.txt') #------------------------------------Clustering------------------------------------------------------------------- # data = P.load('prepro_random_data_19_ranked.txt') # relationship = R.findRelationship(data) # gameCount = len(data) # playerList = relationship.keys() # C = Clustering() # clusterDict = C.cluster(playerList,relationship) # P.save(clusterDict,'Clustering Result_random_data_19_ranked.txt') # data = P.load('prepro_random_data_19_free.txt') # relationship = R.findRelationship(data) # gameCount = len(data) # playerList = relationship.keys() # C = Clustering() # clusterDict = C.cluster(playerList,relationship) # P.save(clusterDict,'Clustering Result_random_data_19_free.txt') # data = P.load('prepro_random_data_9_free.txt') # relationship = R.findRelationship(data) # gameCount = len(data) # playerList = relationship.keys() # C = Clustering() # clusterDict = C.cluster(playerList,relationship) # P.save(clusterDict,'Clustering Result_random_data_9_free.txt') # data = P.load('test_data.txt') # relationship = R.findRelationship(data) # gameCount = len(data) # playerList = relationship.keys() # C = Clustering() # clusterDict = C.cluster(playerList,relationship) # print clusterDict # print type(clusterDict) # C.getIntelView(clusterDict) #------------------------------------Comparison------------------------------------------------------------------- # P.save(clusterDict,'Clustering Result_test_data.txt') # data = process.load('/home/yotoo/Project/comparison/Degree Distribution(Border size: 9; Game Type: Free).txt') data = process.load('/home/yotoo/Project/comparison/Degree Distribution(Border size: 19; Game Type: Ranked).txt') flag = '19 + Ranked' comparison.linearRegression(data,flag) data = process.load('/home/yotoo/Project/comparison/Degree Distribution(Border size: 19; Game Type: Free).txt') flag = '19 + Free' comparison.linearRegression(data,flag) data = process.load('/home/yotoo/Project/comparison/Degree Distribution(Border size: 9; Game Type: Free).txt') flag = '9 + Free' comparison.linearRegression(data,flag) endTime = time.time() print 'totally use ' + str(endTime-startTime) + ' seconds!'