6import matplotlib.pyplot
as plt
26if __name__ ==
"__main__":
29 Script to postprocess statistics outcomes
31 This script can produce two types of data: a CSV file which contains only
32 specific data (it then serves as a filter to a bigger CSV file), or a plot
33 of specific data. For the plot, we can either dump data as scatter plot,
34 or we can use historic data. After all, all data are time series, so we
35 end up with some kind of step function plot for the latter.
39 parser = argparse.ArgumentParser(description=
"""
40Peano 4 statistics postprocessing
42Plotter for statistics over time. The plotter works only for numerical
43data dumped as four tuple over time. Use inspect-statistics.py first
44to see what the indices of the individual column are and what semantics
48 parser.add_argument(
"file", help=
"filename of examine")
49 parser.add_argument(
"-c",
52 help=
"comma-separated list of columns to read (0 equals time stamps and is read always)",
54 parser.add_argument(
"-o",
57 help=
"Pick plot variant",
58 choices=[
"pdf",
"png",
"csv" ],
60 parser.add_argument(
"-pt",
63 help=
"Pick plot variant (ignored for csv)",
64 choices=[
"scatter",
"step" ],
66 parser.add_argument(
"-minmax",
71 help=
"Write min-max bars" )
72 parser.add_argument(
"-v",
78 args = parser.parse_args()
80 columns = [ int(x)
for x
in args.columns.split(
",") ]
81 print(
"Extract columns {}".format(columns) )
83 if args.output==
"pdf" or args.output==
"png":
86 for column
in columns:
102 input_file = open( args.file,
"r" )
104 for line
in input_file:
109 metric = line.split(
"," )[column]
110 print(
"parse metric {}".format(metric) )
111 elif line.strip()!=
"":
112 time_stamp = float(line.split(
"," )[0])
113 token = line.split(
"," )[column].strip()
114 if len(timestamps)>0
and time_stamp<timestamps[-1]:
115 print(
"data consistency error for data at {}, as last time stamp had been {}".format(time_stamp,timestamps[-1]) )
117 timestamps.append(time_stamp )
118 value = float( token.split(
"(")[1].split(
"/")[0])
119 values.append( value )
120 min_values.append( float( token.split(
"/")[1]) )
121 max_values.append( float( token.split(
"/")[2]) )
122 samples.append( float( token.split(
"/#")[1].split(
")")[0]) )
123 elif args.plot_type==
"step" and len(timestamps)>0:
124 timestamps.append(time_stamp )
125 values.append( values[-1] )
126 min_values.append( min_values[-1] )
127 max_values.append( max_values[-1] )
128 samples.append( samples[-1] )
134 print(
"dump {} data points for label {}".format(len(timestamps),metric) )
135 if args.output==
"csv":
136 output_file = open( args.file +
"-column-" + str(column) +
".csv",
"w" )
137 output_file.write(
"time, value, min, max, count\n" )
138 for data
in zip(timestamps,values,min_values,max_values,samples):
140 for i
in range(0,entries_per_row-1):
141 output_file.write( str(data[i]) )
142 output_file.write(
"," )
143 output_file.write( str(data[entries_per_row-1]) )
144 output_file.write(
"\n" )
145 if (args.output==
"pdf" or args.output==
"png")
and args.plot_type==
"step":
146 assert len(timestamps)==len(values)
147 colour = columns.index(column) % len(Colours)
149 for i
in zip(timestamps,min_values,max_values):
150 plt.plot( [i[0],i[0]], [i[1],i[2]], color=Colours[colour] )
151 plt.plot( timestamps, values, color=Colours[colour], alpha=0.5, label=metric )
152 if (args.output==
"pdf" or args.output==
"png")
and args.plot_type==
"scatter":
153 assert len(timestamps)==len(values)
154 colour = columns.index(column) % len(Colours)
156 for i
in zip(timestamps,min_values,max_values):
157 plt.plot( [i[0],i[0]], [i[1],i[2]], color=Colours[colour] )
158 plt.scatter( timestamps, values, marker=Markers[colour], color=Colours[colour], alpha=0.5, label=metric )
160 plt.rc(
'legend', fontsize = 6)
162 if args.output==
"pdf":
164 plt.savefig( args.file +
".pdf" )
165 if args.output==
"png":
167 plt.savefig( args.file +
".png" )