def export(self, function_name=None, inputs=None, outputs=None, user_directory=None): """ Exports the table as python code :param function_name: string name of the function to be created :param inputs: list of column names that are input to the function :param outputs: list of columns that are output from the function :param user_directory: directory where user functions are located :return: error - string from the file export :sideeffects: (a) creates function file (<function_name>.py) in user_directory, (b) creates test file (test_<function_name>.py) in user_directory Notes: (1) Cannot put "exec" in another method since the objects created won't be accessible (2) Iterates N (#formulas) times to handle dependencies between formulas """ # Initializations if inputs is None: inputs = [] if outputs is None: outputs = [] if function_name is None: function_name = DEFAULT_FUNCTION_NAME # Construct the function program generator = ProgramGenerator(self._table, user_directory) function_program = generator.makeFunctionProgram(function_name, inputs, outputs) # Write the function file runner = ProgramRunner(function_program, self._table, user_directory=user_directory, program_filename=function_name) error = runner.writeFiles() if error is not None: return "Error constructing %s: %s" % (function_filepath, error) # Create the test file test_filename = "test_%s" % function_name test_program = generator.makeTestProgram(function_name, inputs, outputs) test_runner = ProgramRunner(test_program, self._table, user_directory=user_directory, program_filename=test_filename) error = test_runner.writeFiles(write_table=False) if error is not None: return "Error constructing %s: %s" % (test_filepath, error) return None
def evaluate(self, user_directory=DEFAULT_USER_DIRECTORY): """ Evaluates the formulas in a Table and assigns the results :param user_directory: path to user exported codes :param table_filepath: path to table file :return: errors from execution or None Notes: (1) Cannot put "exec" in another method since the objects created won't be accessible (2) Iterate N (#formulas) times to handle dependencies between formulas """ # Create the script program generator = ProgramGenerator(self._table, user_directory) program = generator.makeEvaluationScriptProgram() # Run the statements from a file runner = ProgramRunner(program, self._table, user_directory=user_directory, program_filename=GENERATED_FILE, debug=self.debug) runner.writeFiles() return runner.execute(create_API_object=True)