Skip to content

Instantly share code, notes, and snippets.

@linuxkidd
Last active August 29, 2015 14:16
Show Gist options
  • Save linuxkidd/8640962e83266b512d6d to your computer and use it in GitHub Desktop.
Save linuxkidd/8640962e83266b512d6d to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import csv
debug=False
stats={}
files=sys.argv
for csvFile in files:
fh = open(csvFile)
csv_fh = csv.reader(fh)
rowCount=0
for row in csv_fh:
if len(row)>0:
if rowCount==0:
headers={}
for i in range(3,len(row)):
headers[row[i]]=i
else:
for col in headers.keys():
if debug: print str(rowCount)+" "+row[0]
if row[0] not in stats:
if debug: print "Creating stats["+row[0]+"]"
stats[row[0]]={}
if row[1] not in stats[row[0]]:
if debug: print "Creating stats["+row[0]+"]["+row[1]+"]"
stats[row[0]][row[1]]={};
if row[2] not in stats[row[0]][row[1]]:
if debug: print "Creating stats["+row[0]+"]["+row[1]+"]["+row[2]+"]"
stats[row[0]][row[1]][row[2]]={}
if col not in stats[row[0]][row[1]][row[2]]:
if debug: print "Creating stats["+row[0]+"]["+row[1]+"]["+row[2]+"]["+col+"]"
stats[row[0]][row[1]][row[2]][col]=[]
stats[row[0]][row[1]][row[2]][col].append(float(row[headers[col]]))
rowCount+=1
headerLine="host,osd"
outLineCount=0
for host in stats.keys():
for osd in stats[host].keys():
outline=host+","+osd
for opsize in stats[host][osd]:
headerLine+=","+opsize+" "+",{opsize} ".format(opsize=opsize).join(x for x in headers.keys())
for col in headers.keys():
avg=float(sum(stats[host][osd][opsize][col]))/float(len(stats[host][osd][opsize][col]))
outline+=",{0:0.2f}".format(avg)
if outLineCount==0:
print headerLine
print outline
outLineCount+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment