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,43 +15,37 @@ 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 if sec not in responsePerSec:
responsePerSec[sec]=1
def processor(lines): else:
responseCodes={} responsePerSec[sec]=responsePerSec[sec]+1
responsePerSec={} code=item['status-code']
responseTimes=[] if code not in responseCodes:
for line in lines: responseCodes[code]=1
sec=int(line['offset'].split('.')[0]) else:
if sec not in responsePerSec: responseCodes[code]=responseCodes[code]+1
responsePerSec[sec]=1 responseTimes.append(item['response-time'])
else: maxResponse=max(responseTimes)
responsePerSec[sec]=responsePerSec[sec]+1 minResponse=min(responseTimes)
code=line['status-code'] print("Maximum response time was ",maxResponse)
if code not in responseCodes: print("Minimum response time was ",minResponse)
responseCodes[code]=1 pprint(responseCodes)
else: pprint(responsePerSec)
responseCodes[code]=responseCodes[code]+1
responseTimes.append(line['response-time'])
maxResponse=max(responseTimes)
minResponse=min(responseTimes)
print("Maximum response time was ",maxResponse)
print("Minimum response time was ",minResponse)
pprint(responseCodes)
pprint(responsePerSec)
def processAllFiles(): 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()