Beispiel #1
0
def main(stdscr, model_path: str, num: int, result_logger: ResultLogger):
    terminal = Terminal(stdscr, create_char_map())
    terminal.init_window(FIELD_WIDTH, FIELD_ROW)
    program_set = SelectionsortProgramSet()
    Selectionsort_env = SelectionsortEnv(FIELD_ROW, FIELD_WIDTH, FIELD_DEPTH)

    questions = create_questions(num)
    if DEBUG_MODE:
        questions = questions[-num:]
    system = RuntimeSystem(terminal=terminal)
    npi_model = SelectionsortNPIModel(system, model_path, program_set)
    npi_runner = TerminalNPIRunner(terminal, npi_model, recording=False)
    npi_runner.verbose = DEBUG_MODE
    correct_count = wrong_count = 0
    for data in questions:
        Selectionsort_env.reset()
        try:
            run_npi(Selectionsort_env, npi_runner, program_set.SELECTIONSORT,
                    data)
            if data['correct']:
                correct_count += 1
            else:
                wrong_count += 1
        except StopIteration:
            wrong_count += 1
            pass
        result_logger.write(data)
        terminal.add_log(data)
    return correct_count, wrong_count
Beispiel #2
0
 def question_test(self, selectionsort_env, npi_runner, question):
     selectionsort_env.reset()
     self.reset()
     try:
         run_npi(selectionsort_env, npi_runner, self.program_set.SELECTIONSORT, question)
         if question['correct']:
             return True
     except StopIteration:
         pass
     return False
def main(stdscr, filename: str, num: int, result_logger: ResultLogger):
    terminal = Terminal(stdscr, create_char_map())
    terminal.init_window(FIELD_WIDTH, FIELD_ROW)
    program_set = SelectionsortProgramSet()
    selectionsort_env = SelectionsortEnv(FIELD_ROW, FIELD_WIDTH, FIELD_DEPTH)

    questions = create_questions(number=num)
    teacher = SelectionsortTeacher(program_set)
    npi_runner = TerminalNPIRunner(terminal, teacher)
    npi_runner.verbose = DEBUG_MODE
    steps_list = []
    f = open("debug_log.csv", "w")
    for data in questions:
        selectionsort_env.reset()
        q = copy(data)
        run_npi(selectionsort_env, npi_runner, program_set.SELECTIONSORT, data)
        steps_list.append({"q": q, "steps": npi_runner.step_list})
        for step in npi_runner.step_list:
            f.write("{},".format(step.input.env[0]))
            f.write("{},".format(step.input.env[1]))
            f.write("{},".format(step.input.env[2]))
            f.write("{},".format(step.input.env[3]))
            f.write("{},".format(step.input.env[4]))
            f.write("{},".format(step.input.env[5]))
            f.write("{},".format(step.input.arguments))
            f.write("{},".format(step.input.program))
            f.write("{},".format(step.output.program))
            f.write("{},".format(step.output.r))
            f.write("{},".format(step.output.arguments))
            f.write("{}\n".format(q))
        result_logger.write(data)
        terminal.add_log(data)
    f.close()

    if filename:
        with open(filename, 'wb') as f:
            pickle.dump(steps_list, f, protocol=pickle.HIGHEST_PROTOCOL)