def check_for_plot(plt_type, data): """ Returns any errors found for this plot type and data. In other words, if it returns False, the plot was found correctly. """ if plt_type == 'plot': plt_type = 'line' type_found = False data_found = False for graph in compatibility.get_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 = True plt_type = GRAPH_TYPES.get(plt_type, plt_type) if type_found and data_found: return ( "You have created a {}, but it does not have the right data. That data appears to have been plotted " "in another graph.<br><br><i>(other_plt)<i>".format(plt_type)) elif type_found: return ("You have created a {}, but it does not have the right data." "<br><br><i>(wrong_plt_data)<i>".format(plt_type)) elif data_found: return ( "You have plotted the right data, but you appear to have not plotted it as a {}." "<br><br><i>(wrong_plt_type)<i>".format(plt_type)) else: return ("You have not created a {} with the proper data." "<br><br><i>(no_plt)<i>".format(plt_type))
def check_for_plot(plt_type, data): """ Returns any errors found for this plot type and data. In other words, if it returns False, the plot was found correctly. """ if plt_type == 'plot': plt_type = 'line' type_found = False data_found = False for graph in compatibility.get_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 = True plt_type = GRAPH_TYPES.get(plt_type, plt_type) if type_found and data_found: return ("You have created a {}, but it does not have the right data. That data appears to have been plotted " "in another graph.<br><br><i>(other_plt)<i>".format(plt_type)) elif type_found: return ("You have created a {}, but it does not have the right data." "<br><br><i>(wrong_plt_data)<i>".format(plt_type)) elif data_found: return ("You have plotted the right data, but you appear to have not plotted it as a {}." "<br><br><i>(wrong_plt_type)<i>".format(plt_type)) else: return ("You have not created a {} with the proper data." "<br><br><i>(no_plt)<i>".format(plt_type))
def test_matplotlib_compatibility(self): student_code = dedent(''' import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.title("My line plot") plt.show() plt.hist([1,2,3]) plt.show() ''') set_source(student_code) exception = compatibility.run_student() plt2 = compatibility.get_plots() self.assertEqual(len(plt2), 2)
def plot_group_error(output=None, plots=None): if output is None: output = get_output() if plots is None: plots = get_plots() if len(plots) > 1: explain_r('You should only be plotting one thing!', "print_one", "Multiple Calls to plot") return True elif len(plots) == 0: explain_r('The algorithm is plotting an empty list. Check your logic.', 'blank_plot', "Blank Plot") return True elif output: explain('You should be plotting, not printing!', 'printing', "Printing instead of Plotting") return True elif len(plots[0]['data']) != 1: explain('You should only be plotting one thing!', 'one_plot', "Too Many Plots") return True
def check_for_plot_r(plt_type, data): """ Returns any errors found for this plot type and data. In other words, if it returns False, the plot was found correctly. """ if plt_type == 'plot': plt_type = 'line' type_found = False data_found = False for graph in compatibility.get_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 = True plt_type = GRAPH_TYPES.get(plt_type, plt_type) if type_found and data_found: return {"message": "You have created a {}, but it does not have the right data. " "That data appears to have been plotted in another graph.".format(plt_type), "code": "other_plt", "label": "Plotting Another Graph"} elif type_found: return {"message": "You have created a {}, but it does not have the right data.".format(plt_type), "code": "wrong_plt_data", "label": "Plot Data Incorrect"} elif data_found: return {"message": "You have plotted the right data, but you appear to have not plotted it as a {}.".format(plt_type), "code": "wrong_plt_type", "label": "Wrong Plot Type" } else: return {"message": "You have not created a {} with the proper data.".format(plt_type), "code": "no_plt", "label": "Missing Plot"}
import sys from pedal.report import * from pedal.source import set_source set_source( """ import matplotlib.pyplot as plt print("Hello world") plt.hist([1,2,3]) plt.xlabel("Hello") plt.show() """, "answer.py") from pedal.sandbox.sandbox import Sandbox from pedal.sandbox import compatibility student = MAIN_REPORT['sandbox']['run'] = Sandbox() student.report_exceptions_mode = True compatibility.run_student(raise_exceptions=False) print(compatibility.get_output()) print(compatibility.get_plots()) from pedal.resolvers import simple SUCCESS, SCORE, CATEGORY, LABEL, MESSAGE, DATA, HIDE = simple.resolve() print(CATEGORY, LABEL, MESSAGE)