2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 11:01:09 +00:00
confluent/confluent_client/bin/stats

67 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
2019-04-25 17:59:15 +00:00
# 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.
2019-04-25 18:45:47 +00:00
import argparse
2019-04-25 17:59:15 +00:00
import io
import numpy as np
2019-04-25 18:45:47 +00:00
import os
import sixel
import subprocess
import sys
import tempfile
class DumbWriter(sixel.SixelWriter):
def restore_position(self, output):
return
2019-04-25 18:45:47 +00:00
def plot(gui, output, plotdata):
import matplotlib as mpl
if not gui:
mpl.use('Agg')
import matplotlib.pyplot as plt
n, bins, patches = plt.hist(plotdata, 20)
plt.show()
if not gui:
if output:
tdata = output
else:
tdata = io.BytesIO()
plt.savefig(tdata)
if not gui and not output:
writer = DumbWriter()
writer.draw(tdata)
histogram = False
aparser = argparse.ArgumentParser(description='Quick access to common statistics')
aparser.add_argument('-c', type=int, default=0, help='Column number to analyze')
aparser.add_argument('-s', default=False, action='store_true', help='Output histogram in sixel format')
aparser.add_argument('-g', default=False, action='store_true', help='Open histogram in separate graphical window')
aparser.add_argument('-o', default=None, help='Output histogram to the specified filename in PNG format')
args = aparser.parse_args(sys.argv[1:])
plotdata = []
data = sys.stdin.readline()
while data:
2019-04-25 18:45:47 +00:00
datum = float(data.split()[args.c - 1])
plotdata.append(datum)
data = sys.stdin.readline()
2019-04-25 18:45:47 +00:00
if args.g or args.o or args.s:
plot(args.g, args.o, plotdata)
print('Samples: {5} Min: {3} Median: {0} Mean: {1} Max: {4} StandardDeviation: {2}'.format(np.median(plotdata), np.mean(plotdata), np.std(plotdata), np.min(plotdata), np.max(plotdata), len(plotdata)))