Commit 2fcc1e5e authored by Martin Beseda's avatar Martin Beseda

TMP: Added part of recursion in

parent f87eedab
......@@ -1077,22 +1077,47 @@ def getYLabelVals(valuesLst, yLabelCat, yLabelArg, summate=True):
def getElFromDic(d, i):
return {k: d[k][i] for k in d}
# Fce pro ziskani objektu ze stromu slovniku,
# kde cesta je zadana listem klicu
def getObjFromPath(pathLst, dic):
tmp = dic
for key in pathLst:
tmp = tmp[key]
return tmp
# @info construction of the sumarySources structure
# @param items (dictionary) dictioray of results for this settings, key funcLabel with a list of results as a value of the key
# @param path (list) list of keys, that must be added as a path to this settings in final structure
# @return (void)
# @note edits global structure summarySources
def func(items, path):
def constructSummarySources(items, path, slideshowCreator, summarySources, conf):
for cat in ('vals', 'inds'):
for dic in summarySources.values():
tmp = dict()
dic[cat][conf] = tmp
for key in path:
tmp2 = dict()
tmp[key] = tmp2
tmp = tmp2
for funcLabel, val in items:
tmp[funcLabel] = {'singleProgramStarts': list(),
'avgProgramStart': list()}
print(path)
dummy = 1
for funcLabel, val in items:
for cat in ('avg', 'full', 'min', 'max'):
for c in ('vals', 'inds'):
summarySources[cat][c][conf][funcLabel] = {'singleProgramStarts': list(),
'avgProgramStart': list()}
#for c in ('vals', 'inds'):
#summarySources[cat][c][conf][funcLabel] = {'singleProgramStarts': list(),
# 'avgProgramStart': list()}
# Zapisu do listu data pro danou konfiguraci - pro vypocty procent atd.
# 1 polozka listu = 1 volani programu (init)
for dic in val:
summarySources[cat]['vals'][conf][funcLabel]['singleProgramStarts'].append(dic[cat])
summarySourcesTmp = getObjFromPath(path, summarySources[cat]['vals'][conf])
summarySourcesTmp[funcLabel]['singleProgramStarts'].append(dic[cat])
#########################################################################
# Zapisu zdroje pro vykreslovani grafu - prumer, minimum, maximum, full #
......@@ -1107,7 +1132,7 @@ def func(items, path):
# - do nej se budou ukladat indexy dat za
# jednotlive iterace v jednom startu programu
oneProgStartIndices = list()
summarySources['full']['inds'][conf][funcLabel]['singleProgramStarts']\
getObjFromPath(path, summarySources['full']['inds'][conf])[funcLabel]['singleProgramStarts']\
.append(oneProgStartIndices)
# Vytvarim list tuplu za kazdou iteraci
......@@ -1128,7 +1153,8 @@ def func(items, path):
oneProgStartIndices.append(slideshowCreator.getNumOfDataSources())
slideshowCreator.createAndAddDataSourcesTexCode([sorted(nthIterData)], 0, False, 0, 1)
else:
summarySources[cat]['inds'][conf][funcLabel]['singleProgramStarts']\
summarySourcesTmp = getObjFromPath(path, summarySources[cat]['inds'][conf])
summarySourcesTmp[funcLabel]['singleProgramStarts']\
.append(slideshowCreator.getIndOfLastDataSource())
slideshowCreator.createAndAddDataSourcesTexCode([sorted(dic[cat])], 0, False, 0, 1)
......@@ -1139,7 +1165,8 @@ def func(items, path):
# Ziskam maximalni pocet iteraci za jedno volani
# fce - jen pro 'full'!
maxNumOfItersPerStart = 1
for singleProgramStart in summarySources[cat]['vals'][conf][funcLabel]['singleProgramStarts']:
for singleProgramStart in getObjFromPath(path, summarySources[cat]['vals'][conf])\
[funcLabel]['singleProgramStarts']:
for XYvals in singleProgramStart:
if cat == 'full':
......@@ -1158,7 +1185,9 @@ def func(items, path):
# ze vsech volani
avgValFromAllStartsPerOneXLabelKey = list()
for singleProgramStart in summarySources[cat]['vals'][conf][funcLabel]['singleProgramStarts']:
for singleProgramStart in getObjFromPath(path, summarySources[cat]['vals'][conf])\
[funcLabel]['singleProgramStarts']:
if cat == 'full':
xyVal = [None for i in range(maxNumOfItersPerStart)]
for XYvals in singleProgramStart:
......@@ -1182,48 +1211,54 @@ def func(items, path):
avgValFromAllStartsPerOneXLabelKey.append(xyVal)
# Z hodnot za vsechna volani ziskam prumernou hodnotu
if cat == 'full':
valsTmp = [[e[i] for e in avgValFromAllStartsPerOneXLabelKey if e[i] is not None]
for i in range(maxNumOfItersPerStart)]
if valsTmp:
summarySources[cat]['vals'][conf][funcLabel]['avgProgramStart']\
getObjFromPath(path, summarySources[cat]['vals'][conf])[funcLabel]['avgProgramStart']\
.append((xLabelKey, [numpy.mean(e) if e else None for e in valsTmp]))
else:
valsTmp = [e for e in avgValFromAllStartsPerOneXLabelKey if e is not None]
if valsTmp:
summarySources[cat]['vals'][conf][funcLabel]['avgProgramStart']\
getObjFromPath(path, summarySources[cat]['vals'][conf])[funcLabel]['avgProgramStart']\
.append((xLabelKey, numpy.mean(valsTmp)))
# Zapisu data za prumerny start programu jako zdroj pro graf
if cat != 'full':
summarySources[cat]['inds'][conf][funcLabel]['avgProgramStart']\
getObjFromPath(path, summarySources[cat]['inds'][conf])[funcLabel]['avgProgramStart']\
.append(slideshowCreator.getIndOfLastDataSource())
slideshowCreator.createAndAddDataSourcesTexCode(
[sorted(summarySources[cat]['vals'][conf][funcLabel]['avgProgramStart'])],
[sorted(getObjFromPath(path, summarySources[cat]['vals'][conf])[funcLabel]['avgProgramStart'])],
0, False, 0, 1)
else:
plotDataTmp = [[(e[0], e[1][i])
for e in summarySources[cat]['vals'][conf][funcLabel]['avgProgramStart']
for e in getObjFromPath(path, summarySources[cat]['vals'][conf])[funcLabel]['avgProgramStart']
if e[1][i] is not None]
for i in range(maxNumOfItersPerStart)]
for i in range(maxNumOfItersPerStart):
summarySources[cat]['inds'][conf][funcLabel]['avgProgramStart']\
getObjFromPath(path, summarySources[cat]['inds'][conf])[funcLabel]['avgProgramStart']\
.append(slideshowCreator.getIndOfLastDataSource())
slideshowCreator.createAndAddDataSourcesTexCode(
[sorted(plotDataTmp[i])],
0, False, 0, 1)
dummy = 2
# @info recursively goes through the dict until it reaches its last dict the results
# @param nested (dict) dictionary with another key or results
# @param path (list) path of previous keys
# @return (void)
def a(nested,path):
for item in nested:
if type(nested[item]) is dict: #
a(nested[item], path.append(item))
def processKeys(nested, path, slideshowCreator, summarySources, conf):
for ind, item in enumerate(nested):
if type(nested[item]) is dict:
path.append(item)
processKeys(nested[item], path, slideshowCreator, summarySources, conf)
else:
func(sorted(nested.items()), path) #sorted(vals.items())
constructSummarySources(sorted(nested.items()), path, slideshowCreator, summarySources, conf)
if path and ind == len(nested)-1:
path.pop(0)
def getAllDataClassifiedFromFolder(measuredFuncFolderArg,
yLabelCategory,
......@@ -1443,13 +1478,15 @@ def getAllDataClassifiedFromFolder(measuredFuncFolderArg,
for conf, vals in sorted(folderDataGroups.items()):
# Pridam do summarySources list na konkretni konfiguraci.
# V listu budou vysledky za jednotliva spusteni programu.
for cat in ('vals', 'inds'):
for dic in summarySources.values():
dic[cat][conf] = dict()
#for cat in ('vals', 'inds'):
# for dic in summarySources.values():
# dic[cat][conf] = dict()
# TODO OV
func(sorted(vals.items()))
#a(vals, []) #?
#func(sorted(vals.items()))
print(conf)
processKeys(vals, [], slideshowCreator, summarySources, conf)
# Kontrola, jestli se nacetla nejaka data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment