2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-12-25 12:41:39 +00:00

Remove use of tmp file in stats

This commit is contained in:
Jarrod Johnson 2019-04-25 13:59:15 -04:00
parent abfeef5a0a
commit 33c1137ccf

View File

@ -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)