diff --git a/misc/stats b/misc/stats index d608831c..b685dbd5 100755 --- a/misc/stats +++ b/misc/stats @@ -1,5 +1,22 @@ #!/usr/bin/python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# Copyright 2019 Lenovo +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import io import numpy as np import matplotlib as mpl mpl.use('Agg') @@ -23,15 +40,9 @@ while data: data = sys.stdin.readline() n, bins, patches = plt.hist(plotdata, 20) plt.show() -path = tempfile.mkdtemp() -plt.savefig('{0}/histo.png'.format(path)) +tdata = io.BytesIO() +plt.savefig(tdata) writer = DumbWriter() -writer.draw('{0}/histo.png'.format(path)) +writer.draw(tdata) print('Min: {3} Median: {0} Mean: {1} Max: {4} Standard Deviation: {2} Samples: {5}'.format(np.median(plotdata), np.mean(plotdata), np.std(plotdata), np.min(plotdata), np.max(plotdata), len(plotdata))) -os.remove('{0}/histo.png'.format(path)) -os.rmdir(path) - - - -