Avg changes

This commit is contained in:
HajarZaiz 2023-04-25 21:32:31 +00:00
parent e7c2807aca
commit 3fbda15272

View File

@ -83,9 +83,6 @@ class Visualizer:
return data return data
def averageRuns(self, data, runs): def averageRuns(self, data, runs):
'''Debugging'''
if not os.path.exists('debug'):
os.makedirs('debug')
"""Get the average of all runs for each key""" """Get the average of all runs for each key"""
newData = {} newData = {}
print("Getting the average of the runs...") print("Getting the average of the runs...")
@ -97,33 +94,37 @@ class Visualizer:
runExists = True runExists = True
break break
if runExists: if runExists:
ps = list(data[key].keys())
for item in key: for item in key:
"""Create a new key with the other items in the tuple""" """Create a new key with the other items in the tuple"""
if item.startswith('run_'): if item.startswith('run_'):
newKey = tuple([x for x in key if x != item]) newKey = tuple([x for x in key if x != item])
"""Average the similar key values""" """Average the similar key values"""
total = [0] * len(data[key]['ttas']) tta_sums = {}
with open('debug/debug.txt', 'a') as f: total = []
f.write('TTAs:\n') p0 = []
p1 = []
for i in range(runs): for i in range(runs):
key0 = (f'run_{i}',) + newKey key0 = (f'run_{i}',) + newKey
with open('debug/debug.txt', 'a') as f: #Create a dictionary to store the sums of ttas for each unique pair of values in subkeys
f.write(str(data[key0]['ttas']) + '\n') for i in range(len(data[key0][ps[0]])):
for cnt, tta in enumerate(data[key0]['ttas']): keyPair = (data[key0][ps[0]][i], data[key0][ps[1]][i])
total[cnt] += tta try:
tta_sums[keyPair] += data[key0]['ttas'][i]
except KeyError:
tta_sums[keyPair] = data[key0]['ttas'][i]
for k, tta in tta_sums.items():
p0.append(k[0])
p1.append(k[1])
total.append(tta)
for i in range(len(total)): for i in range(len(total)):
total[i] = total[i]/runs total[i] = total[i]/runs
if(total[i] == -1): if(total[i] == -1):
total[i] = self.maxTTA total[i] = self.maxTTA
with open('debug/debug.txt', 'a') as f:
f.write('Average:\n')
f.write(str(total)+ '\n')
averages = {} averages = {}
for subkey in data[key].keys(): averages[ps[0]] = p0
if subkey == 'ttas': averages[ps[1]] = p1
averages[subkey] = total averages['ttas'] = total
else:
averages[subkey] = data[key][subkey]
newData[newKey] = averages newData[newKey] = averages
return newData return newData