not iterating twice, duh

This commit is contained in:
Torma Kristóf 2019-04-30 22:59:18 +02:00 committed by GitHub
parent 8296c923cd
commit 0382666e5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,30 +15,25 @@ def processFile(fname):
lines=[] lines=[]
data=csv.reader(f) data=csv.reader(f)
fields=next(data) fields=next(data)
responseCodes={}
responsePerSec={}
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()
lines.append(item) sec=int(item['offset'].split('.')[0])
return lines
def processor(lines):
responseCodes={}
responsePerSec={}
responseTimes=[]
for line in lines:
sec=int(line['offset'].split('.')[0])
if sec not in responsePerSec: if sec not in responsePerSec:
responsePerSec[sec]=1 responsePerSec[sec]=1
else: else:
responsePerSec[sec]=responsePerSec[sec]+1 responsePerSec[sec]=responsePerSec[sec]+1
code=line['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(line['response-time']) responseTimes.append(item['response-time'])
maxResponse=max(responseTimes) maxResponse=max(responseTimes)
minResponse=min(responseTimes) minResponse=min(responseTimes)
print("Maximum response time was ",maxResponse) print("Maximum response time was ",maxResponse)
@ -50,8 +45,7 @@ def processAllFiles():
files=getFiles() files=getFiles()
for f in files: for f in files:
print("Processing ", f) print("Processing ", f)
lines=processFile(f) processFile(f)
processor(lines)
if __name__ == "__main__": if __name__ == "__main__":
processAllFiles() processAllFiles()