netgen/tests/pytest/compare_results.py

126 lines
3.6 KiB
Python
Raw Normal View History

2019-10-24 21:22:25 +05:00
import json
import sys
import subprocess
import statistics
def readData(a, files):
amin=[]
amax=[]
amin1=[]
amax1=[]
bad=[]
ne1d=[]
ne2d=[]
ne3d=[]
file=[]
2019-10-24 21:22:25 +05:00
for f in files:
2024-03-12 01:10:56 +05:00
if f == 'cylinder.geo':
continue
2019-10-24 21:22:25 +05:00
for t in a[f]:
if t['ne1d']>0:
ne1d.append(t['ne1d'])
if t['ne2d']>0:
ne2d.append(t['ne2d'])
if t['ne3d']>0:
ne3d.append(t['ne3d'])
if t['total_badness']>0.0:
bad.append(t['total_badness'])
file.append(f)
2019-10-24 21:22:25 +05:00
if 'angles_tet' in t:
amin.append(t['angles_tet'][0])
amax.append(t['angles_tet'][1])
if 'angles_trig' in t:
amin1.append(t['angles_trig'][0])
amax1.append(t['angles_trig'][1])
return {
"min tet angle":amin,
"max tet angle" : amax,
"min trig angle":amin1,
"max trig angle" : amax1,
"badness" : bad,
"#edges" : ne1d,
"#trigs" : ne2d,
"#tets" : ne3d,
"file" : file,
2019-10-24 21:22:25 +05:00
}
import matplotlib.pyplot as plt
ref = 'master'
if len(sys.argv)>1:
ref = sys.argv[1]
res = subprocess.run(['git','show','{}:./results.json'.format(ref)], capture_output=True)
s = json.loads(res.stdout.decode())
if len(sys.argv) > 2:
ref2 = sys.argv[2]
res = subprocess.run(['git','show','{}:./results.json'.format(ref2)], capture_output=True)
s2 = res.stdout.decode()
else:
ref2 = 'current'
s2 = open('results.json','r').read()
s2 = json.loads(s2)
filenames = [f for f in s if f in s2]
data = readData(s, filenames)
data2 = readData(s2, filenames)
assert(len(data) == len(data2))
w = 90
GREEN = '\033[92m'
RED = '\033[91m'
RESET = '\033[0m'
for bad1,bad2, f1, f2 in zip(data['badness'], data2['badness'], data['file'], data2['file']):
assert f1==f2
diff = f"{100*(bad2-bad1)/bad1:+.2f}%"
if bad2>0 and bad2>1.2*bad1:
print(f"{RED}badness {f1} got worse: {bad1} -> {bad2}".ljust(w) + diff + RESET)
if bad2>0 and bad2<0.8*bad1:
print(f"{GREEN}badness {f1} got better: {bad1} -> {bad2}".ljust(w) + diff + RESET)
2021-11-30 23:43:32 +05:00
for bad1,bad2, f1, f2 in zip(data['#trigs'], data2['#trigs'], data['file'], data2['file']):
assert f1==f2
diff = f"{100*(bad2-bad1)/bad1:+.2f}%"
if bad2>0 and bad2>1.2*bad1:
print(f"{RED}ntrigs {f1} got worse: {bad1} -> {bad2}".ljust(w) + diff + RESET)
if bad2>0 and bad2<0.8*bad1:
print(f"{GREEN}ntrigs {f1} got better: {bad1} -> {bad2}".ljust(w) + diff + RESET)
n = len(data) + 1
fig, ax = plt.subplots(figsize=(15, 7)) # Adjust figsize as needed
plt.xticks([])
plt.yticks([])
ax.yaxis.grid(False)
ax.xaxis.grid(False)
for i, d in enumerate(['min trig angle', 'min tet angle', 'max trig angle', 'max tet angle']):
plt.subplot(2, 4, i + 1) # Remove ax =
2019-10-24 21:22:25 +05:00
plt.title(d)
# plt.xticks([1, 2])
if len(data[d]) == 0 or len(data2[d]) == 0:
2019-10-24 21:22:25 +05:00
continue
plt.violinplot([data[d], data2[d]], showmedians=True)
2019-10-24 21:22:25 +05:00
med = statistics.median(data[d])
plt.hlines(med, 1, 2, linestyle='dotted')
if d == 'badness':
plt.yscale('log')
plt.xticks([1, 2], [ref, ref2])
for i, d in enumerate(['badness', '#edges', '#trigs', '#tets']):
plt.xticks([])
plt.subplot(2, 4, 5 + i)
plt.title('difference ' + d + ' (in %)')
plt.boxplot([100.0 * (y - x) / x for x, y in zip(data[d], data2[d])])
plt.hlines(0.0, 0.5, 1.5, linestyle='dotted')
plt.tight_layout() # Adjust layout
2019-10-24 21:22:25 +05:00
# plt.savefig('comparison.png', dpi=100)
plt.show()