diff --git a/unitgrade/__pycache__/unitgrade.cpython-38.pyc b/unitgrade/__pycache__/unitgrade.cpython-38.pyc index 79d28c2c207464f86831a1a24c58a1908f9fbb16..49ec789f81c61461975b3223eaa6b5b60596fd78 100644 Binary files a/unitgrade/__pycache__/unitgrade.cpython-38.pyc and b/unitgrade/__pycache__/unitgrade.cpython-38.pyc differ diff --git a/unitgrade/__pycache__/unitgrade_helpers.cpython-38.pyc b/unitgrade/__pycache__/unitgrade_helpers.cpython-38.pyc index bed82f87d21feaedd5ccb707a1ea1b71a1d99ad4..712bb3bb40300a849453141c82e5f9afc3bac086 100644 Binary files a/unitgrade/__pycache__/unitgrade_helpers.cpython-38.pyc and b/unitgrade/__pycache__/unitgrade_helpers.cpython-38.pyc differ diff --git a/unitgrade/__pycache__/version.cpython-38.pyc b/unitgrade/__pycache__/version.cpython-38.pyc index 8dc5bac8678643c646bd1057bdfb5299c1e65b24..74567f3b5e3d3f07730bb308aaec25f3d90a3ad9 100644 Binary files a/unitgrade/__pycache__/version.cpython-38.pyc and b/unitgrade/__pycache__/version.cpython-38.pyc differ diff --git a/unitgrade/unitgrade.py b/unitgrade/unitgrade.py index d4f69fc40025d0f2926aeb91538a5ad1bc5a5cea..f829f0a809d8dc743bfdf1ed848b8512b2ad4f28 100644 --- a/unitgrade/unitgrade.py +++ b/unitgrade/unitgrade.py @@ -100,6 +100,8 @@ class QItem(unittest.TestCase): diff = np.abs( (np.asarray(computed).flat- np.asarray(expected)).flat ) nrm = np.sqrt(np.sum( diff ** 2)) + self.error_computed = nrm + if nrm > tol: print(f"Not equal within tolerance {tol}; norm of difference was {nrm}") print(f"Element-wise differences {diff.tolist()}") @@ -109,6 +111,8 @@ class QItem(unittest.TestCase): if tol == None: tol = self.tol diff = np.abs( (np.asarray(computed) - np.asarray(expected)) ) + self.error_computed = np.max(diff) + if np.max(diff) > tol: print("Not equal within tolerance {tol}") print(f"Element-wise differences {diff.tolist()}") @@ -119,6 +123,7 @@ class QItem(unittest.TestCase): tol = self.tol diff = 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: print(f"Not equal within tolerance {tol}") print(f"Element-wise differences {diff.tolist()}") diff --git a/unitgrade/unitgrade_helpers.py b/unitgrade/unitgrade_helpers.py index 45adf1bb58ae5ba36542f59ce1601354c77d1ff0..f14c2b7332a44bd49881991c97b10b88bea71792 100644 --- a/unitgrade/unitgrade_helpers.py +++ b/unitgrade/unitgrade_helpers.py @@ -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, 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: print("Provisional evaluation") tabulate(table_data) @@ -161,7 +208,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa q.has_called_init_ = True 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) item.question = q # Set the parent question instance for later reference. @@ -186,7 +233,8 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa if not hidden: ss = "PASS" if current == possible else "*** FAILED" - ss += " ("+ str(tsecs) + " seconds)" + if tsecs >= 0.1: + ss += " ("+ str(tsecs) + " seconds)" print(ss) ws, possible, obtained = upack(q_) diff --git a/unitgrade/version.py b/unitgrade/version.py index 32efefd012eab099f696f3b7ef3cd301baeeaa94..283b03a075bdc493860ebb799f4b2f3ee2a72d87 100644 --- a/unitgrade/version.py +++ b/unitgrade/version.py @@ -1 +1 @@ -__version__ = "0.1.6" \ No newline at end of file +__version__ = "0.1.7" \ No newline at end of file