forked from pratiknarang/peershark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotGraphs.py
62 lines (52 loc) · 1.46 KB
/
plotGraphs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import pylab
import os
import multiprocessing as MP
from P2P_CONSTANTS import *
def plotGraph(x, y, z, filename):
v = [0,5000,0,200]
plt.axis(v)
plt.scatter(x, y, alpha = 0.10, cmap=plt.cm.cool, edgecolors='None')
# plt.colorbar()
pylab.savefig(filename, bbox_inches = 0)
plt.clf()
#scale input data and plot graphs
def processFile(filename):
sem.acquire()
x1 = []
# x2 = []
y = []
z = []
inputfile = open(filename)
for line in inputfile:
fields = line.strip().split(',')
x1.append(float(fields[3]) / 1000)
# x2.append(float(fields[3]) / (1000 * int(fields[2])))
y.append(float(fields[-1]) / 1000)
z.append(float(fields[4]) / 1000)
inputfile.close()
filename = filename.split('/')
outputdir = NEWDIR + filename[-2] + '/'
if not os.path.exists(outputdir):
os.makedirs(outputdir)
plotGraph(x1, y, z, outputdir + filename[-1] + '.png')
# plotGraph(x2, y, z, filename + 'modified.png')
print 'Completed plotting ' + '/'.join(filename)
sem.release()
NEWDIR = SUPERFLOWDATADIR + 'alphachanged/'
if not os.path.exists(NEWDIR):
os.makedirs(NEWDIR)
folders = os.listdir(SUPERFLOWDATADIR)
csvfiles = []
for eachname in folders:
name = SUPERFLOWDATADIR + eachname +'/'
if os.path.isdir(name):
csvfiles += getCSVFiles(name)
print csvfiles
sem = MP.Semaphore(THREADLIMIT)
for eachfile in csvfiles:
task = MP.Process(target = processFile, args = (eachfile,))
task.start()