Skip to content
Snippets Groups Projects
Commit dd740b6c authored by tuhe's avatar tuhe
Browse files

vesion 1.7: L2-Norm fixed plus minor improvement of progress display

parent 6527d52c
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -100,6 +100,8 @@ class QItem(unittest.TestCase): ...@@ -100,6 +100,8 @@ class QItem(unittest.TestCase):
diff = np.abs( (np.asarray(computed).flat- np.asarray(expected)).flat ) diff = np.abs( (np.asarray(computed).flat- np.asarray(expected)).flat )
nrm = np.sqrt(np.sum( diff ** 2)) nrm = np.sqrt(np.sum( diff ** 2))
self.error_computed = nrm
if nrm > tol: if nrm > tol:
print(f"Not equal within tolerance {tol}; norm of difference was {nrm}") print(f"Not equal within tolerance {tol}; norm of difference was {nrm}")
print(f"Element-wise differences {diff.tolist()}") print(f"Element-wise differences {diff.tolist()}")
...@@ -109,6 +111,8 @@ class QItem(unittest.TestCase): ...@@ -109,6 +111,8 @@ class QItem(unittest.TestCase):
if tol == None: if tol == None:
tol = self.tol tol = self.tol
diff = np.abs( (np.asarray(computed) - np.asarray(expected)) ) diff = np.abs( (np.asarray(computed) - np.asarray(expected)) )
self.error_computed = np.max(diff)
if np.max(diff) > tol: if np.max(diff) > tol:
print("Not equal within tolerance {tol}") print("Not equal within tolerance {tol}")
print(f"Element-wise differences {diff.tolist()}") print(f"Element-wise differences {diff.tolist()}")
...@@ -119,6 +123,7 @@ class QItem(unittest.TestCase): ...@@ -119,6 +123,7 @@ class QItem(unittest.TestCase):
tol = self.tol tol = self.tol
diff = np.abs( (np.asarray(computed) - np.asarray(expected)) ) diff = np.abs( (np.asarray(computed) - np.asarray(expected)) )
diff = diff / (1e-8 + np.abs( (np.asarray(computed) + np.asarray(expected)) ) ) diff = diff / (1e-8 + np.abs( (np.asarray(computed) + np.asarray(expected)) ) )
self.error_computed = np.max(np.abs(diff))
if np.sum(diff > tol) > 0: if np.sum(diff > tol) > 0:
print(f"Not equal within tolerance {tol}") print(f"Not equal within tolerance {tol}")
print(f"Element-wise differences {diff.tolist()}") print(f"Element-wise differences {diff.tolist()}")
......
...@@ -71,6 +71,53 @@ def evaluate_report_student(report, question=None, qitem=None, unmute=None, pass ...@@ -71,6 +71,53 @@ def evaluate_report_student(report, question=None, qitem=None, unmute=None, pass
results, table_data = evaluate_report(report, question=question, show_progress_bar=not unmute, qitem=qitem, verbose=False, passall=passall, show_expected=args.showexpected, show_computed=args.showcomputed,unmute=unmute, results, table_data = evaluate_report(report, question=question, show_progress_bar=not unmute, qitem=qitem, verbose=False, passall=passall, show_expected=args.showexpected, show_computed=args.showcomputed,unmute=unmute,
show_tol_err=show_tol_err) show_tol_err=show_tol_err)
try: # For registering stats.
import unitgrade_private
import irlc.lectures
import xlwings
from openpyxl import Workbook
import pandas as pd
from collections import defaultdict
dd = defaultdict(lambda: [])
error_computed = []
for k1, (q, _) in enumerate(report.questions):
for k2, (item, _) in enumerate(q.items):
dd['question_index'].append(k1)
dd['item_index'].append(k2)
dd['question'].append(q.name)
dd['item'].append(item.name)
dd['tol'].append(0 if not hasattr(item, 'tol') else item.tol)
error_computed.append(0 if not hasattr(item, 'error_computed') else item.error_computed)
qstats = report.wdir + "/" + report.name + ".xlsx"
if os.path.isfile(qstats):
d_read = pd.read_excel(qstats).to_dict()
else:
d_read = dict()
for k in range(1000):
key = 'run_'+str(k)
if key in d_read:
dd[key] = list(d_read['run_0'].values())
else:
dd[key] = error_computed
break
workbook = Workbook()
worksheet = workbook.active
for col, key in enumerate(dd.keys()):
worksheet.cell(row=1, column=col+1).value = key
for row, item in enumerate(dd[key]):
worksheet.cell(row=row+2, column=col+1).value = item
workbook.save(qstats)
workbook.close()
except ModuleNotFoundError as e:
s = 234
pass
if question is None: if question is None:
print("Provisional evaluation") print("Provisional evaluation")
tabulate(table_data) tabulate(table_data)
...@@ -161,7 +208,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -161,7 +208,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
q.has_called_init_ = True q.has_called_init_ = True
q_time =np.round( time.time()-start, 2) q_time =np.round( time.time()-start, 2)
print(" "* max(0,nL - len(q_title_print) ) + " (" + str(q_time) + " seconds)") # if q.name in report.payloads else "") print(" "* max(0,nL - len(q_title_print) ) + (" (" + str(q_time) + " seconds)" if q_time >= 0.1 else "") ) # if q.name in report.payloads else "")
print("=" * nL) print("=" * nL)
item.question = q # Set the parent question instance for later reference. item.question = q # Set the parent question instance for later reference.
...@@ -186,6 +233,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -186,6 +233,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
if not hidden: if not hidden:
ss = "PASS" if current == possible else "*** FAILED" ss = "PASS" if current == possible else "*** FAILED"
if tsecs >= 0.1:
ss += " ("+ str(tsecs) + " seconds)" ss += " ("+ str(tsecs) + " seconds)"
print(ss) print(ss)
......
__version__ = "0.1.6" __version__ = "0.1.7"
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment