def handcalc_decorator(func): # use innerscope to get the values of locals within the function scoped_func = innerscope.scoped_function(func) def wrapper(*args, **kwargs): line_args = {"override": override, "precision": precision} func_source = inspect.getsource(func) cell_source = _func_source_to_cell(func_source) scope = scoped_func(*args, **kwargs) calculated_results = scope.inner_scope renderer = LatexRenderer(cell_source, calculated_results, line_args) latex_code = renderer.render() if jupyter_display: try: from IPython.display import Latex, display except ModuleNotFoundError: ModuleNotFoundError( "jupyter_display option requires IPython.display to be installed." ) display(Latex(latex_code)) return calculated_results latex_code = latex_code.replace("\\[", "").replace("\\]", "") return (left + latex_code + right, calculated_results) return wrapper
def sample_size_equation(design): d = sys._getframe().f_back.f_locals calc = design_sample_size[design] func = scoped_function(calc, d) return func().return_value
def degree_freedom_equation(design): d = sys._getframe().f_back.f_locals calc = design_degree_freedom[design] func = scoped_function(calc, d) return func().return_value
def task(func): sf = scoped_function(func) if not sf.missing: return (func,) deps = tuple(sf.missing) return ((lambda *args: sf.bind(**dict(zip(deps, args)))().return_value),) + deps