output csv
This commit is contained in:
parent
57945c1265
commit
dc3e951346
@ -2,60 +2,68 @@
|
|||||||
import csv
|
import csv
|
||||||
import os
|
import os
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
#Returns array of csv files in current directory
|
# Returns array of csv files in current directory
|
||||||
|
|
||||||
|
|
||||||
def getFiles():
|
def getFiles():
|
||||||
files = [f for f in os.listdir('.') if os.path.isfile(f)]
|
files = [f for f in os.listdir('.') if os.path.isfile(f)]
|
||||||
return[ f for f in files if f.endswith('.csv') ]
|
return[f for f in files if f.endswith('.csv')]
|
||||||
|
|
||||||
|
|
||||||
def processFile(fname):
|
def processFile(fname):
|
||||||
with open(fname,'r') as f:
|
with open(fname, 'r') as f:
|
||||||
lines=[]
|
lines = []
|
||||||
data=csv.reader(f)
|
data = csv.reader(f)
|
||||||
fields=next(data)
|
fields = next(data)
|
||||||
responseCodes={}
|
responseCodes = {}
|
||||||
responsePerSec={}
|
responsePerSec = {}
|
||||||
responseTimes=[]
|
responseTimes = []
|
||||||
for row in data:
|
for row in data:
|
||||||
items=zip(fields,row)
|
items = zip(fields, row)
|
||||||
item={}
|
item = {}
|
||||||
for(name,value) in items:
|
for(name, value) in items:
|
||||||
item[name]=value.strip()
|
item[name] = value.strip()
|
||||||
sec=int(item['offset'].split('.')[0])
|
sec = int(item['offset'].split('.')[0])
|
||||||
if sec not in responsePerSec:
|
if sec not in responsePerSec:
|
||||||
responsePerSec[sec]=[]
|
responsePerSec[sec] = []
|
||||||
else:
|
else:
|
||||||
responsePerSec[sec].append(item['response-time'])
|
responsePerSec[sec].append(item['response-time'])
|
||||||
code=item['status-code']
|
code = item['status-code']
|
||||||
if code not in responseCodes:
|
if code not in responseCodes:
|
||||||
responseCodes[code]=1
|
responseCodes[code] = 1
|
||||||
else:
|
else:
|
||||||
responseCodes[code]=responseCodes[code]+1
|
responseCodes[code] = responseCodes[code] + 1
|
||||||
responseTimes.append(item['response-time'])
|
responseTimes.append(item['response-time'])
|
||||||
if len(responseTimes)!=0:
|
if len(responseTimes) != 0:
|
||||||
maxResponse=max(responseTimes)
|
maxResponse = max(responseTimes)
|
||||||
minResponse=min(responseTimes)
|
minResponse = min(responseTimes)
|
||||||
print("Maximum response time was ",maxResponse)
|
#print("Maximum response time was ", maxResponse)
|
||||||
print("Minimum response time was ",minResponse)
|
#print("Minimum response time was ", minResponse)
|
||||||
else:
|
else:
|
||||||
print("csv is empty")
|
print("csv is empty")
|
||||||
pprint(responseCodes)
|
#pprint(responseCodes)
|
||||||
for sec in responsePerSec:
|
for sec in responsePerSec:
|
||||||
if len(responsePerSec[sec])!=0:
|
if len(responsePerSec[sec]) != 0:
|
||||||
print(sec, ":")
|
#print(sec, ":")
|
||||||
print(" Maximum:", max(responsePerSec[sec]))
|
#print(" Maximum:", max(responsePerSec[sec]))
|
||||||
print(" Minimum:", min(responsePerSec[sec]))
|
#print(" Minimum:", min(responsePerSec[sec]))
|
||||||
print(" Num of responses:", len(responsePerSec[sec]))
|
#print(" Num of responses:", len(responsePerSec[sec]))
|
||||||
else:
|
print(len(responsePerSec[sec]))
|
||||||
print(" empty")
|
#else:
|
||||||
|
#print(" empty")
|
||||||
|
|
||||||
|
|
||||||
|
def keychars(x):
|
||||||
|
return int(x.split('.')[1])
|
||||||
|
|
||||||
|
|
||||||
def processAllFiles():
|
def processAllFiles():
|
||||||
files=getFiles()
|
files = sorted(getFiles(), key=keychars)
|
||||||
for f in files:
|
for f in files:
|
||||||
print("Processing ", f)
|
#print("Processing ", f)
|
||||||
processFile(f)
|
processFile(f)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
processAllFiles()
|
processAllFiles()
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
numpy
|
|
||||||
matplotlib
|
|
Loading…
Reference in New Issue
Block a user