def get_plots(report=MAIN_REPORT): """ Retrieves any plots made by the user. The general structure is as follows: .. code-block::python plots = [ { 'title': str, 'xlabel': str, 'ylabel': str, 'legend': bool 'data': { 'type': str # either 'line' or 'scatter' or 'hist' 'label': str # If 'hist' type 'values': list[float] # If 'scatter' or 'line' type 'x': list[float], 'y': list[float] } } # ... ] """ return get_sandbox(report=report).modules.plotting.plots
def __enter__(self): clear_report(report=self.report) contextualize_report(self.code, report=self.report) verify(report=self.report) if self.run_tifa: tifa_analysis(report=self.report) # TODO: Clean this up self.student = get_sandbox(self.report) self.report['sandbox']['sandbox'].tracer_style = self.tracer_style commands.run() return self
def assert_plot(plt_type, data, **kwargs): """ Check whether a plot with the given ``plt_type`` and ``data`` exists. If the plot was found successfully, returns False. Otherwise, returns the feedback that was detected. Args: plt_type (str): Either 'line', 'hist', or 'scatter' data (list): The expected data to check in the plots. Could be a single list of numbers, or a pair of two lists (for scatter/line plots). """ report = kwargs.get("report", MAIN_REPORT) # Allow instructor to use "plot" instead of "line" as type if plt_type == 'plot': plt_type = 'line' # Check the plots to see if there is a plot with the data type_found = False data_found = False plots = get_sandbox(report=report).modules.plotting.plots for graph in plots: for a_plot in graph['data']: data_found_here = compare_data(plt_type, data, a_plot) if a_plot['type'] == plt_type and data_found_here: return False if a_plot['type'] == plt_type: type_found = True if data_found_here: data_found = data_found_here # Figure out what kind of mistake was made. plt_type = GRAPH_TYPES.get(plt_type, plt_type) if type_found and data_found: return other_plt(plt_type, data, data_found) elif type_found: return wrong_plt_data(plt_type, data, data_found) elif data_found: return wrong_plt_type(plt_type, data, data_found) else: return no_plt(plt_type, data, data_found)
""" self.success = False def check_case(function, case, student_function): """ :param function: :param case: :param student_function: :return: status, arg, input, error, output, return, message """ function_name = function['name'] test_case = TestCase(function_name, case.get('name')) # Get callable sandbox = get_sandbox(MAIN_REPORT) sandbox.clear_output() # Potential bonus message if 'message' in case: test_case.add_message(case['message']) # Queue up the the inputs if 'inputs' in case: test_case.add_inputs(case['inputs']) sandbox.set_input(test_case.inputs) else: sandbox.clear_input() # Pass in the arguments and call the function if 'arguments' in case: test_case.add_arguments(case['arguments']) result = sandbox.call(function_name, *test_case.arguments) # Store actual values