all the figures

This commit is contained in:
2019-12-04 22:13:01 +01:00
parent 6b77b25dd7
commit d3d1a1cce5
4 changed files with 244 additions and 28 deletions

View File

@@ -10,6 +10,100 @@
\numberwithin{lstlisting}{section}
%\numberwithin{tabular}{section}
\section{Knative Autoscaler Napl\'o feldolgoz\'as\'at v\'egző k\'od}
\label{sec:log-analyze}
\begin{lstlisting}[label=code:log-analyze]
class LogAnalyzer(Analyzer):
def __init__(self):
super().__init__(typeof='.txt')
self.concurrencypersec = []
self.podpersec = []
self.start = datetime.datetime.now()
self.end = datetime.datetime.now()
def listtodict(self, inlist: list) -> dict:
it = iter(inlist)
res_dct = dict(zip(it, it))
return res_dct
def processfile(
self,
fname,
shouldprint: bool = False) -> dict:
dictofsecs = {}
if 'date' in fname:
return {}
with open(fname, 'r') as inputFile:
line = inputFile.readline()
while line:
try:
linedict = json.loads(line)
try:
currdate = linedict['ts'].split(
'.')[0].replace('T', ' ')
dateformatted = datetime.datetime.strptime(
currdate, '%Y-%m-%d %H:%M:%S')
if self.start < dateformatted < self.end:
message = linedict['msg']
messagelist = re.split('[ =]', message)
messagedict = self.listtodict(messagelist)
messagedict['ts'] = dateformatted
if 'ObservedStableValue' in messagedict:
if messagedict['ts'] not in dictofsecs:
dictofsecs[messagedict['ts']] = {
'pod': [], 'cc': []}
dictofsecs[messagedict['ts']]['pod'].append(
float(messagedict['PodCount']))
dictofsecs[messagedict['ts']]['cc'].append(
float(messagedict['ObservedStableValue']))
except Exception as exception:
print(exception)
except json.JSONDecodeError:
continue
finally:
line = inputFile.readline()
return dictofsecs
def readconfigdates(self, directory='.'):
dates = []
with open(directory + "/dates.txt", 'r') as inputFile:
line = inputFile.readline().rstrip()
currline = 0
while line:
dateformatted = datetime.datetime.strptime(
line, '%Y-%m-%d %H:%M:%S')
dates.append(dateformatted)
line = inputFile.readline().rstrip()
currline += 1
self.start = dates[0]
self.end = dates[1]
def averagepersec(
self,
dictoftimes: dict,
shouldprint: bool = False) -> None:
for key, value in dictoftimes.items():
pod = value['pod']
concurrency = value['cc']
avgpod = average(pod)
avgcc = average(concurrency)
self.podpersec.append(avgpod)
self.concurrencypersec.append(avgcc)
if shouldprint:
print(avgpod)
print(avgcc)
def work(self, directory: str = '.') -> None:
files = super().getfiles(directory)
self.readconfigdates(directory)
filelines = {}
for afile in files:
filelines.update(self.processfile(afile))
self.averagepersec(filelines, False)
\end{lstlisting}
%TODO Remove this shit
%----------------------------------------------------------------------------
\clearpage\section{Válasz az ,,Élet, a világmindenség, meg minden'' kérdésére}
%----------------------------------------------------------------------------