nagyon buta vagyok

This commit is contained in:
Torma Kristóf 2019-04-30 15:56:21 +02:00 committed by GitHub
parent 3f419dc926
commit ac1e2f1e93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import csv import csv
import os import os
import pprint from pprint import pprint
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@ -11,10 +11,10 @@ def getFiles():
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) as f: with open(fname,'r') as f:
lines=[] lines=[]
data=csv.reader(f) data=csv.reader(f)
fields=data.next() fields=next(data)
for row in data: for row in data:
items=zip(fields,row) items=zip(fields,row)
item={} item={}
@ -26,28 +26,29 @@ def processFile(fname):
def processor(lines): def processor(lines):
responseCodes={} responseCodes={}
responsePerSec={} responsePerSec={}
responesTimes=[line['response-time'] for line in lines] responseTimes=[line['response-time'] for line in lines]
maxResponse=max(responesTimes) maxResponse=max(responseTimes)
minResponse=min(responesTimes) minResponse=min(responseTimes)
for line in lines: for line in lines:
sec=line['response-time'] // 1 sec=line['offset'][0]
if responsePerSec[sec] == None: 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=line['status-code']
if responseCodes[code]==None: if code not in responseCodes:
responseCodes[code]=1 responseCodes[code]=1
else: else:
responseCodes[code]=responseCodes[code]+1 responseCodes[code]=responseCodes[code]+1
print("Maximum response time was ",maxResponse) print("Maximum response time was ",maxResponse)
print("Minimum response time was ",minResponse) print("Minimum response time was ",minResponse)
pprint(responseCodes) pprint(responseCodes)
pprint(responesTimes) pprint(responsePerSec)
def processAllFiles(): def processAllFiles():
files=getFiles() files=getFiles()
for f in files: for f in files:
print("Processing ", f)
lines=processFile(f) lines=processFile(f)
processor(lines) processor(lines)