コード例 #1
0
    def __init__(self, model, view, filename, run_id_to_select):

        logger.verbose("Select run_id: {0}".format(run_id_to_select))
        super(ExecutionLogTreeController, self).__init__(model, view)

        self.run_id_to_select = run_id_to_select
        self.hist_items = shelve.open(filename, 'r')
        self.start, self.next_, self.concurrent, self.hierarchy, self.items = \
            log_helper.log_to_collapsed_structure(self.hist_items,
                                                  throw_on_pickle_error=False,
                                                  include_erroneous_data_ports=True)
        # create a TreeStore with one string column to use as the model
        self.tree_store = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        self.item_iter = {}
        view.tree_view.set_model(self.tree_store)
コード例 #2
0
def test_execution_log(caplog):
    try:
        testing_utils.initialize_environment_core(
            core_config={
                'EXECUTION_LOG_ENABLE':
                True,
                'EXECUTION_LOG_PATH':
                testing_utils.get_unique_temp_path() + '/test_execution_log'
            })

        state_machine = global_storage.load_state_machine_from_path(
            testing_utils.get_test_sm_path(
                os.path.join("unit_test_state_machines",
                             "execution_file_log_test")))

        rafcon.core.singleton.state_machine_manager.add_state_machine(
            state_machine)
        rafcon.core.singleton.state_machine_manager.active_state_machine_id = state_machine.state_machine_id
        rafcon.core.singleton.state_machine_execution_engine.start()
        rafcon.core.singleton.state_machine_execution_engine.join()

        import shelve
        import json
        ss = shelve.open(state_machine.get_last_execution_log_filename())

        assert len(ss) == 36

        start, next, concurrent, hierarchy, collapsed_items = log_helper.log_to_collapsed_structure(
            ss)

        prod1_id = [
            k for k, v in collapsed_items.items()
            if v['state_name'] == 'MakeProd1'
        ][0]
        prod1 = collapsed_items[prod1_id]
        assert prod1['scoped_data_ins']['product'] == 2
        assert prod1['scoped_data_outs']['product'] == 2
        assert prod1['outcome_name'] == 'success'

        prod2_id = [
            k for k, v in collapsed_items.items()
            if v['state_name'] == 'MakeProd2'
        ][0]
        prod2 = collapsed_items[prod2_id]
        assert prod2['data_ins']['input_1'] == 0
        assert prod2['data_outs']['output_1'] == 3
        assert prod2['scoped_data_ins']['product'] == 1
        assert prod2['scoped_data_outs']['product'] == 1

        start_states = [
            k for k, v in collapsed_items.items() if v['state_name'] == 'Start'
            and v['state_type'] == 'ExecutionState'
        ]
        assert len(
            start_states
        ) == 3  # Start state is executed three times until state machine is done
        start_id = start_states[0]
        start_item = collapsed_items[start_id]
        assert 'Starts the factory' in start_item['description']

        df = log_helper.log_to_DataFrame(ss)
        all_starts = df.groupby('state_name').get_group('Start')
        assert len(all_starts) == 3
        assert list(
            all_starts['outcome_name']) == ['success', 'success', 'done']

        rafcon.core.singleton.state_machine_manager.remove_state_machine(
            state_machine.state_machine_id)
    finally:
        testing_utils.shutdown_environment_only_core(caplog=caplog,
                                                     expected_warnings=0,
                                                     expected_errors=0)
コード例 #3
0
def test_execution_log(caplog):
    try:
        testing_utils.initialize_environment_core(
            core_config={
                'IN_MEMORY_EXECUTION_HISTORY_ENABLE':
                True,
                'FILE_SYSTEM_EXECUTION_HISTORY_ENABLE':
                True,
                'EXECUTION_LOG_PATH':
                testing_utils.get_unique_temp_path() + '/test_execution_log'
            })

        state_machine = global_storage.load_state_machine_from_path(
            testing_utils.get_test_sm_path(
                os.path.join("unit_test_state_machines",
                             "execution_file_log_test")))

        rafcon.core.singleton.state_machine_manager.add_state_machine(
            state_machine)
        rafcon.core.singleton.state_machine_execution_engine.start(
            state_machine.state_machine_id)
        while not state_machine.root_state.final_outcome:
            time.sleep(0.1)
        rafcon.core.singleton.state_machine_execution_engine.join()

        import shelve
        import json
        ss = shelve.open(state_machine.get_last_execution_log_filename())

        target_dict = {}  # can be used for debugging
        for key, value in ss.items():
            # print(value)
            target_dict[int(key[-3:].lstrip("0"))] = value

        assert len(ss) == 36

        start, next, concurrent, hierarchy, collapsed_items = log_helper.log_to_collapsed_structure(
            ss)

        prod1_id = [
            k for k, v in collapsed_items.items()
            if v['state_name'] == 'MakeProd1'
        ][0]
        prod1 = collapsed_items[prod1_id]
        assert prod1['scoped_data_ins']['product'] == 2
        assert prod1['scoped_data_outs']['product'] == 2
        assert prod1['outcome_name'] == 'success'
        assert prod1['semantic_data']['test_key'] == 'TestValue'

        prod2_id = [
            k for k, v in collapsed_items.items()
            if v['state_name'] == 'MakeProd2'
        ][0]
        prod2 = collapsed_items[prod2_id]
        assert prod2['data_ins']['input_1'] == 0
        assert prod2['data_outs']['output_1'] == 3
        assert prod2['scoped_data_ins']['product'] == 1
        assert prod2['scoped_data_outs']['product'] == 1

        start_states = [
            k for k, v in collapsed_items.items() if v['state_name'] == 'Start'
            and v['state_type'] == 'ExecutionState'
        ]
        assert len(
            start_states
        ) == 3  # Start state is executed three times until state machine is done
        start_id = start_states[0]
        start_item = collapsed_items[start_id]
        assert 'Starts the factory' in start_item['description']

        df = log_helper.log_to_DataFrame(ss)
        all_starts = df.groupby('state_name').get_group('Start')
        assert len(all_starts) == 3
        assert list(
            all_starts['outcome_name']) == ['success', 'success', 'done']

        execution_history = state_machine.execution_histories[0]

        assert len(execution_history) == 32
        assert isinstance(execution_history[0], StateMachineStartItem)
        assert isinstance(execution_history[1], CallItem)
        assert isinstance(execution_history[2], CallItem)
        assert isinstance(execution_history[3], ReturnItem)

        rafcon.core.singleton.state_machine_manager.remove_state_machine(
            state_machine.state_machine_id)
    except ImportError:  # if pandas is not installed
        print("test_execution_log skipped as pandas is not installed")
    finally:
        testing_utils.shutdown_environment_only_core(caplog=caplog,
                                                     expected_warnings=0,
                                                     expected_errors=0)
コード例 #4
0
    def __init__(self, filename):
        self.hist_items = shelve.open(filename, 'r')
        self.start, self.next_, self.concurrent, self.hierarchy, self.items = \
            log_helper.log_to_collapsed_structure(self.hist_items,
                                                  throw_on_pickle_error=False,
                                                  include_erroneous_data_ports=True)

        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)

        self.window.set_title("Execution Log Viewer")

        self.window.set_default_size(1024, 786)

        self.window.connect("delete_event", self.delete_event)

        # Setting up the self.grid in which the elements are to be positioned
        self.paned = gtk.HPaned()
        self.window.add(self.paned)

        # setting up the layout, putting the treeview in a scrollwindow, and the buttons in a row
        self.scrollable_treelist = gtk.ScrolledWindow()
        # self.scrollable_treelist.set_vexpand(True)
        self.paned.add1(self.scrollable_treelist)

        # setting up text view
        self.scrollable_textview = gtk.ScrolledWindow()
        self.paned.add2(self.scrollable_textview)

        self.paned.set_position(300)

        self.textview = gtk.TextView(buffer=None)
        self.scrollable_textview.add(self.textview)

        # create a TreeStore with one string column to use as the model
        self.treestore = gtk.TreeStore(str, str)

        # we'll add some data now - 4 rows with 3 child rows each
        if not self.start:
            print 'WARNING: no start item found, just listing all items'
            elements = [(None, run_id) for run_id in self.items.keys()]
        else:
            elements = [(None, self.start['run_id'])]
        while True:
            new_elements = []
            for e in elements:
                new_elements.extend(self.add_collapsed_key(e[0], e[1]))
            if len(new_elements) == 0:
                break
            else:
                elements = new_elements


#        for parent in range(4):
#            piter = self.treestore.append(None, ['parent %i' % parent])
#            for child in range(3):
#                self.treestore.append(piter, ['child %i of parent %i' %
#                                              (child, parent)])

# create the TreeView using treestore
        self.treeview = gtk.TreeView(self.treestore)
        self.selection = self.treeview.get_selection()
        self.selection.connect('changed', self.on_treeview_selection_changed)
        self.scrollable_treelist.add(self.treeview)

        # create the TreeViewColumn to display the data
        self.tvcolumn = gtk.TreeViewColumn('Execution History')

        # add tvcolumn to treeview
        self.treeview.append_column(self.tvcolumn)

        # create a CellRendererText to render the data
        self.cell = gtk.CellRendererText()

        # add the cell to the tvcolumn and allow it to expand
        self.tvcolumn.pack_start(self.cell, True)

        # set the cell "text" attribute to column 0 - retrieve text
        # from that column in treestore
        self.tvcolumn.add_attribute(self.cell, 'text', 0)

        # make it searchable
        self.treeview.set_search_column(0)

        # Allow sorting on the column
        self.tvcolumn.set_sort_column_id(0)

        # Allow drag and drop reordering of rows
        self.treeview.set_reorderable(True)

        self.window.show_all()