-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotOutput.py
More file actions
executable file
·152 lines (110 loc) · 2.98 KB
/
plotOutput.py
File metadata and controls
executable file
·152 lines (110 loc) · 2.98 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/python
import os
import sys
import math
import re
from matplotlib import pyplot as plt
import sys
COLUMN = 11
SUM = False
FILTER = False
FilterText = ''
class File:
def __init__(self):
self.others = []
self.path = ''
self.scale = 1
def __repr__(self):
return '[P:'+self.path+'|S:'+str(self.scale)+'|O:'+str(len(self.others))+']';
def getDaily(self):
text = open(self.path).readlines()
pnls = map(lambda l: int(l.split()[COLUMN]),text)
return pnls
def scaleDaily(self):
text = []
if(self.path == '<STDIN>'):
text = sys.stdin.readlines()
else:
text = open(self.path).readlines()
if(FILTER):
tmp = []
for l in text:
if(l.find(FilterText) != -1):
tmp.append(l)
text = tmp
text = map(lambda s: s.strip(), text)
pnls = map(lambda l: self.scale*float(l.split(',')[COLUMN]),text)
return pnls
def sumDaily(self,pnls):
total = reduce(lambda l,v: (l.append(l[-1]+v) or l), pnls, [0])
return total
if(len(sys.argv) < 2):
print('Needs Path[:Scale,Path2:Scale,...] Path3\n')
print('Options')
print('-c <Num>\tColumn in data to plot')
print('-g <Text>\tFilters file by <Text> much like grep')
print('-a\tAggregate the data, default is off')
print('-s\tRead in from stdin. Useful for piping')
print
print('Examples:')
print('---------')
print('plotOutput.py Output <--- standard plot');
print('plotOutput.py Output:2 AlsoOutput:3 <-- plots 2 series scaled 2x and 3x');
print('plotOutput.py Output:2,AlsoOutput <-- plots 1 series, two outputs scaled then aggregated together');
sys.exit(1)
myfiles = []
def fileCriteria(path,arr):
file = File()
if(path.find('.err') == -1):
if(path.find(',') != -1):
fileCriteria(path[path.find(',')+1:],file.others);
path = path[:path.find(',')]
if(path.find(':') != -1):
offset = 1
for c in path[path.find(':')+1:]:
if not c.isdigit() and c != "." and c != '-':
break
offset = offset + 1
file.scale = float(path[path.find(':')+1:path.find(':')+offset])
path = path[:path.find(':')] + path[path.find(':')+offset:]
file.path = path;
arr.append(file);
args = sys.argv[1:]
for idx,path in enumerate(args):
if path == "-c":
if (1+idx) == len(args):
print("Need Column")
break;
COLUMN = int(args[idx+1])
del(args[idx+1])
elif path == '-g':
FILTER = True
FilterText = args[idx+1]
del(args[idx+1])
elif path == '-a':
SUM = True
elif path == '-s':
fileCriteria('<STDIN>',myfiles)
elif not os.path.isdir(path):
if(path.find('.err') == -1):
fileCriteria(path,myfiles)
else:
for root, dirs, files in os.walk(path):
for file in files:
if(file.find('.err') == -1):
fileCriteria(path,myfiles)
# First level only
break
#myfiles.sort()
for file in myfiles:
pnls = [file.scaleDaily()]
node = file.others
while node:
pnls.append(node[0].scaleDaily())
node = node[0].others
agg = map(sum,zip(*pnls))
total = agg
if(SUM):
total = file.sumDaily(agg);
plt.plot(range(0,len(total)),total)
plt.show()