code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
logger.debug("Executing backward step ...") self.run_to_states = [] self.set_execution_mode(StateMachineExecutionStatus.BACKWARD)
def backward_step(self)
Take a backward step for all active states in the state machine
15.652809
12.977975
1.206106
logger.debug("Activate step mode") if state_machine_id is not None: self.state_machine_manager.active_state_machine_id = state_machine_id self.run_to_states = [] if self.finished_or_stopped(): self.set_execution_mode(StateMachineExecutionStatus.STEP_MOD...
def step_mode(self, state_machine_id=None)
Set the execution mode to stepping mode. Transitions are only triggered if a new step is triggered
4.107598
4.012408
1.023724
logger.debug("Execution step into ...") self.run_to_states = [] if self.finished_or_stopped(): self.set_execution_mode(StateMachineExecutionStatus.FORWARD_INTO) self._run_active_state_machine() else: self.set_execution_mode(StateMachineExecuti...
def step_into(self)
Take a forward step (into) for all active states in the state machine
7.769207
6.453086
1.203952
logger.debug("Execution step over ...") self.run_to_states = [] if self.finished_or_stopped(): self.set_execution_mode(StateMachineExecutionStatus.FORWARD_OVER) self._run_active_state_machine() else: self.set_execution_mode(StateMachineExecuti...
def step_over(self)
Take a forward step (over) for all active states in the state machine
8.427443
6.781523
1.242706
logger.debug("Execution step out ...") self.run_to_states = [] if self.finished_or_stopped(): self.set_execution_mode(StateMachineExecutionStatus.FORWARD_OUT) self._run_active_state_machine() else: self.set_execution_mode(StateMachineExecution...
def step_out(self)
Take a forward step (out) for all active states in the state machine
8.58211
6.962222
1.232668
if self.state_machine_manager.get_active_state_machine() is not None: self.state_machine_manager.get_active_state_machine().root_state.recursively_resume_states() if not self.finished_or_stopped(): logger.debug("Resume execution engine and run to selected state!") ...
def run_to_selected_state(self, path, state_machine_id=None)
Execute the state machine until a specific state. This state won't be executed. This is an asynchronous task
2.878138
2.958273
0.972912
while (self._status.execution_mode is StateMachineExecutionStatus.PAUSED) \ or (self._status.execution_mode is StateMachineExecutionStatus.STEP_MODE): try: self._status.execution_condition_variable.acquire() self.synchronization_counter += 1 ...
def _wait_while_in_pause_or_in_step_mode(self)
Waits as long as the execution_mode is in paused or step_mode
3.81362
3.345622
1.139884
wait = True # if there is a state in self.run_to_states then RAFCON was commanded # a) a step_over # b) a step_out # c) a run_until for state_path in copy.deepcopy(self.run_to_states): next_child_state_path = None # can be None in...
def _wait_if_required(self, container_state, next_child_state_to_execute, woke_up_from_pause_or_step_mode)
Calls a blocking wait for the calling thread, depending on the execution mode. :param container_state: the current hierarhcy state to handle the execution mode for :param next_child_state_to_execute: the next child state for :param container_state to be executed :param woke_up_from_pause_or_ste...
6.293919
6.236451
1.009215
self.state_counter_lock.acquire() self.state_counter += 1 # logger.verbose("Increase state_counter!" + str(self.state_counter)) self.state_counter_lock.release() woke_up_from_pause_or_step_mode = False if (self._status.execution_mode is StateMachineExecutionSta...
def handle_execution_mode(self, container_state, next_child_state_to_execute=None)
Checks the current execution status and returns it. Depending on the execution state, the calling thread (currently only hierarchy states) waits for the execution to continue. If the execution mode is any of the step modes, a condition variable stops the current execution, until it get...
4.272856
4.084633
1.046081
if self._status.execution_mode is StateMachineExecutionStatus.FORWARD_OVER or \ self._status.execution_mode is StateMachineExecutionStatus.FORWARD_OUT: for state_path in copy.deepcopy(self.run_to_states): if state_path == state.get_path(): ...
def _modify_run_to_states(self, state)
This is a special case. Inside a hierarchy state a step_over is triggered and affects the last child. In this case the self.run_to_states has to be modified in order to contain the parent of the hierarchy state. Otherwise the execution won't respect the step_over any more and run until the end of the st...
3.76235
3.138119
1.198919
import rafcon.core.singleton from rafcon.core.storage import storage rafcon.core.singleton.library_manager.initialize() if not state_machine: state_machine = storage.load_state_machine_from_path(path) rafcon.core.singleton.state_machine_manager.add_state...
def execute_state_machine_from_path(self, state_machine=None, path=None, start_state_path=None, wait_for_execution_finished=True)
A helper function to start an arbitrary state machine at a given path. :param path: The path where the state machine resides :param start_state_path: The path to the state from which the execution will start :return: a reference to the created state machine
3.034339
3.184854
0.95274
if not isinstance(execution_mode, StateMachineExecutionStatus): raise TypeError("status must be of type StateMachineExecutionStatus") self._status.execution_mode = execution_mode if notify: self._status.execution_condition_variable.acquire() self._sta...
def set_execution_mode(self, execution_mode, notify=True)
An observed setter for the execution mode of the state machine status. This is necessary for the monitoring client to update the local state machine in the same way as the root state machine of the server. :param execution_mode: the new execution mode of the state machine :raises exceptions.Typ...
3.196244
3.082739
1.03682
self.execution_engine_lock.acquire() return_value = self._run_to_states self.execution_engine_lock.release() return return_value
def run_to_states(self)
Property for the _run_to_states field
4.680969
3.692042
1.267854
super(ContainerState, self).recursively_preempt_states() # notify the transition condition variable to let the state instantaneously stop self._transitions_cv.acquire() self._transitions_cv.notify_all() self._transitions_cv.release() for state in self.states.valu...
def recursively_preempt_states(self)
Preempt the state and all of it child states.
4.972806
4.499839
1.105108
super(ContainerState, self).recursively_pause_states() for state in self.states.values(): state.recursively_pause_states()
def recursively_pause_states(self)
Pause the state and all of it child states.
3.627696
3.034462
1.195499
super(ContainerState, self).recursively_resume_states() for state in self.states.values(): state.recursively_resume_states()
def recursively_resume_states(self)
Resume the state and all of it child states.
3.356356
2.627868
1.277216
super(ContainerState, self).setup_run() # reset the scoped data self._scoped_data = {} self._start_state_modified = False self.add_default_values_of_scoped_variables_to_scoped_data() self.add_input_data_to_scoped_data(self.input_data)
def setup_run(self)
Executes a generic set of actions that has to be called in the run methods of each derived state class. :return:
6.410344
6.799501
0.942767
transition = None while not transition: # (child) state preempted or aborted if self.preempted or state.final_outcome.outcome_id in [-2, -1]: if self.concurrency_queue: self.concurrency_queue.put(self.state_id) self.st...
def handle_no_transition(self, state)
This function handles the case that there is no transition for a specific outcome of a sub-state. The method waits on a condition variable to a new transition that will be connected by the programmer or GUI-user. :param state: The sub-state to find a transition for :return: The transit...
5.76508
5.176874
1.113622
start_state = self.get_start_state(set_final_outcome=True) while not start_state: # depending on the execution mode pause execution execution_signal = state_machine_execution_engine.handle_execution_mode(self) if execution_signal is StateMachineExecutionStatu...
def handle_no_start_state(self)
Handles the situation, when no start state exists during execution The method waits, until a transition is created. It then checks again for an existing start state and waits again, if this is not the case. It returns the None state if the the state machine was stopped.
5.451972
4.665618
1.168542
assert isinstance(state, State) # logger.info("add state {}".format(state)) # handle the case that the child state id is the same as the container state id or future sibling state id while state.state_id == self.state_id or state.state_id in self.states: state.chang...
def add_state(self, state, storage_load=False)
Adds a state to the container state. :param state: the state that is going to be added :param storage_load: True if the state was directly loaded from filesystem :return: the state_id of the new state :raises exceptions.AttributeError: if state.state_id already exist
5.61555
5.1043
1.100161
if state_id not in self.states: raise AttributeError("State_id %s does not exist" % state_id) if state_id == self.start_state_id: self.set_start_state(None) # first delete all transitions and data_flows, which are connected to the state to be deleted ke...
def remove_state(self, state_id, recursive=True, force=False, destroy=True)
Remove a state from the container state. :param state_id: the id of the state to remove :param recursive: a flag to indicate a recursive disassembling of all substates :param force: a flag to indicate forcefully deletion of all states (important for the decider state in the barr...
2.471324
2.535936
0.974521
for transition_id in list(self.transitions.keys()): self.remove_transition(transition_id, destroy=recursive) for data_flow_id in list(self.data_flows.keys()): self.remove_data_flow(data_flow_id, destroy=recursive) for scoped_variable_id in list(self.scoped_variab...
def destroy(self, recursive)
Removes all the state elements. :param recursive: Flag whether to destroy all state elements which are removed
2.2223
2.443178
0.909594
related_transitions = {'external': {'ingoing': [], 'outgoing': []}, 'internal': {'enclosed': [], 'ingoing': [], 'outgoing': []}} related_data_flows = {'external': {'ingoing': [], 'outgoing': []}, 'internal': {'enclosed': [], 'ingoing...
def related_linkage_state(self, state_id)
TODO: document
1.892459
1.876401
1.008558
# find all related transitions related_transitions = {'enclosed': [], 'ingoing': [], 'outgoing': []} for t in self.transitions.values(): # check if internal of new hierarchy state if t.from_state in state_ids and t.to_state in state_ids: related_...
def related_linkage_states_and_scoped_variables(self, state_ids, scoped_variables)
TODO: document
1.793212
1.77591
1.009743
from rafcon.gui.helpers.state import create_new_state_from_state_with_type state_id = state.state_id if state_id not in self.states: raise ValueError("State '{0}' with id '{1}' does not exist".format(state.name, state_id)) new_state = create_new_state_from_state_w...
def change_state_type(self, state, new_state_class)
Changes the type of the state to another type :param state: the state to be changed :param new_state_class: the new type of the state :return: the new state having the new state type :rtype: :py:class:`rafcon.core.states.state.State` :raises exceptions.ValueError: if the state d...
2.973121
2.609409
1.139385
if state is None: self.start_state_id = None elif isinstance(state, State): self.start_state_id = state.state_id else: self.start_state_id = state
def set_start_state(self, state)
Sets the start state of a container state :param state: The state_id of a state or a direct reference ot he state (that was already added to the container) that will be the start state of this container state.
2.121165
2.11304
1.003845
# overwrite the start state in the case that a specific start state is specific e.g. by start_from_state if self.get_path() in state_machine_execution_engine.start_state_paths: for state_id, state in self.states.items(): if state.get_path() in state_machine_executio...
def get_start_state(self, set_final_outcome=False)
Get the start state of the container state :param set_final_outcome: if the final_outcome of the state should be set if the income directly connects to an outcome :return: the start state
3.822928
3.538215
1.080468
if isinstance(state_element, State): return self.remove_state(state_element.state_id, recursive=recursive, force=force, destroy=destroy) elif isinstance(state_element, Transition): return self.remove_transition(state_element.transition_id, destroy=destroy) elif i...
def remove(self, state_element, recursive=True, force=False, destroy=True)
Remove item from state :param StateElement state_element: State or state element to be removed :param bool recursive: Only applies to removal of state and decides whether the removal should be called recursively on all child states :param bool force: if the removal should be forced ...
2.058969
2.229014
0.923713
if transition_id is not None: if transition_id in self._transitions.keys(): raise AttributeError("The transition id %s already exists. Cannot add transition!", transition_id) else: transition_id = generate_transition_id() while transition_id i...
def check_transition_id(self, transition_id)
Check the transition id and calculate a new one if its None :param transition_id: The transition-id to check :return: The new transition id :raises exceptions.AttributeError: if transition.transition_id already exists
2.800042
2.605945
1.074482
for trans_key, transition in self.transitions.items(): if transition.from_state == from_state_id: if transition.from_outcome == from_outcome: raise AttributeError("Outcome %s of state %s is already connected" % (st...
def check_if_outcome_already_connected(self, from_state_id, from_outcome)
check if outcome of from state is not already connected :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :raises exceptions.AttributeError: if the outcome of the state with the state_id==from_state_id ...
2.921013
2.54553
1.147507
# get correct states if from_state_id is not None: if from_state_id == self.state_id: from_state = self else: from_state = self.states[from_state_id] # finally add transition if from_outcome is not None: if fr...
def create_transition(self, from_state_id, from_outcome, to_state_id, to_outcome, transition_id)
Creates a new transition. Lookout: Check the parameters first before creating a new transition :param from_state_id: The source state of the transition :param from_outcome: The outcome of the source state to connect the transition to :param to_state_id: The target state of the transiti...
2.40608
2.408094
0.999163
transition_id = self.check_transition_id(transition_id) # Set from_state_id to None for start transitions, as from_state_id and from_outcome should both be None for # these transitions if from_state_id == self.state_id and from_outcome is None: from_state_id = None...
def add_transition(self, from_state_id, from_outcome, to_state_id, to_outcome, transition_id=None)
Adds a transition to the container state Note: Either the toState or the toOutcome needs to be "None" :param from_state_id: The source state of the transition :param from_outcome: The outcome id of the source state to connect the transition to :param to_state_id: The target state of th...
2.894958
3.058034
0.946673
if not isinstance(state, State): raise TypeError("state must be of type State") if not isinstance(outcome, Outcome): raise TypeError("outcome must be of type Outcome") result_transition = None for key, transition in self.transitions.items(): i...
def get_transition_for_outcome(self, state, outcome)
Determines the next transition of a state. :param state: The state for which the transition is determined :param outcome: The outcome of the state, that is given in the first parameter :return: the transition specified by the the state and the outcome :raises exceptions.TypeError: if th...
2.151417
2.213174
0.972095
if transition_id == -1 or transition_id == -2: raise AttributeError("The transition_id must not be -1 (Aborted) or -2 (Preempted)") if transition_id not in self._transitions: raise AttributeError("The transition_id %s does not exist" % str(transition_id)) self.t...
def remove_transition(self, transition_id, destroy=True)
Removes a transition from the container state :param transition_id: the id of the transition to remove :raises exceptions.AttributeError: if the transition_id is already used
3.44144
3.336605
1.03142
for transition_id in list(self.transitions.keys()): transition = self.transitions[transition_id] if transition.to_outcome == outcome_id and transition.to_state == self.state_id: self.remove_transition(transition_id)
def remove_outcome_hook(self, outcome_id)
Removes internal transition going to the outcome
2.886621
2.540386
1.136293
if data_flow_id is not None: if data_flow_id in self._data_flows.keys(): raise AttributeError("The data_flow id %s already exists. Cannot add data_flow!", data_flow_id) else: data_flow_id = generate_data_flow_id() while data_flow_id in self._d...
def check_data_flow_id(self, data_flow_id)
Check the data flow id and calculate a new one if its None :param data_flow_id: The data flow id to check :return: The new data flow id :raises exceptions.AttributeError: if data_flow.data_flow_id already exists
2.271009
2.159967
1.051409
data_flow_id = self.check_data_flow_id(data_flow_id) self.data_flows[data_flow_id] = DataFlow(from_state_id, from_data_port_id, to_state_id, to_data_port_id, data_flow_id, self) return data_flow_id
def add_data_flow(self, from_state_id, from_data_port_id, to_state_id, to_data_port_id, data_flow_id=None)
Adds a data_flow to the container state :param from_state_id: The id source state of the data_flow :param from_data_port_id: The output_key of the source state :param to_state_id: The id target state of the data_flow :param to_data_port_id: The input_key of the target state :par...
1.841364
2.19609
0.838474
if data_flow_id not in self._data_flows: raise AttributeError("The data_flow_id %s does not exist" % str(data_flow_id)) self._data_flows[data_flow_id].parent = None return self._data_flows.pop(data_flow_id)
def remove_data_flow(self, data_flow_id, destroy=True)
Removes a data flow from the container state :param int data_flow_id: the id of the data_flow to remove :raises exceptions.AttributeError: if the data_flow_id does not exist
2.438916
2.484603
0.981612
# delete all data flows in parent related to data_port_id and self.state_id = external data flows # checking is_root_state_of_library is only necessary in case of scoped variables, as the scoped variables # they are not destroyed by the library state, as the library state does not have ...
def remove_data_flows_with_data_port_id(self, data_port_id)
Remove an data ports whose from_key or to_key equals the passed data_port_id :param int data_port_id: the id of a data_port of which all data_flows should be removed, the id can be a input or output data port id
2.287905
2.248576
1.017491
for scoped_variable_id, scoped_variable in self.scoped_variables.items(): if scoped_variable.name == name: return scoped_variable_id raise AttributeError("Name %s is not in scoped_variables dictionary", name)
def get_scoped_variable_from_name(self, name)
Get the scoped variable for a unique name :param name: the unique name of the scoped variable :return: the scoped variable specified by the name :raises exceptions.AttributeError: if the name is not in the the scoped_variables dictionary
3.38101
3.093749
1.092852
if scoped_variable_id is None: # All data port ids have to passed to the id generation as the data port id has to be unique inside a state scoped_variable_id = generate_data_port_id(self.get_data_port_ids()) self._scoped_variables[scoped_variable_id] = ScopedVariable(nam...
def add_scoped_variable(self, name, data_type=None, default_value=None, scoped_variable_id=None)
Adds a scoped variable to the container state :param name: The name of the scoped variable :param data_type: An optional data type of the scoped variable :param default_value: An optional default value of the scoped variable :param scoped_variable_id: An optional scoped variable id of t...
3.572471
3.520616
1.014729
if scoped_variable_id not in self._scoped_variables: raise AttributeError("A scoped variable with id %s does not exist" % str(scoped_variable_id)) # delete all data flows connected to scoped_variable if destroy: self.remove_data_flows_with_data_port_id(scoped_va...
def remove_scoped_variable(self, scoped_variable_id, destroy=True)
Remove a scoped variable from the container state :param scoped_variable_id: the id of the scoped variable to remove :raises exceptions.AttributeError: if the id of the scoped variable already exists
3.19625
3.352521
0.953387
if state_id == self.state_id: return self.get_data_port_by_id(port_id) for child_state_id, child_state in self.states.items(): if state_id != child_state_id: continue port = child_state.get_data_port_by_id(port_id) if port: ...
def get_data_port(self, state_id, port_id)
Searches for a data port The data port specified by the state id and data port id is searched in the state itself and in its children. :param str state_id: The id of the state the port is in :param int port_id: The id of the port :return: The searched port or None if it is not found
2.012459
2.222337
0.90556
data_port = super(ContainerState, self).get_data_port_by_id(data_port_id) if data_port: return data_port if data_port_id in self.scoped_variables: return self.scoped_variables[data_port_id] return None
def get_data_port_by_id(self, data_port_id)
Search for the given data port id in the data ports of the state The method tries to find a data port in the input and output data ports as well as in the scoped variables. :param data_port_id: the unique id of the data port :return: the data port with the searched id or None if not found
2.764694
2.304286
1.199806
result_dict = {} tmp_dict = self.get_default_input_values_for_state(state) result_dict.update(tmp_dict) for input_port_key, value in state.input_data_ports.items(): # for all input keys fetch the correct data_flow connection and read data into the result_dict ...
def get_inputs_for_state(self, state)
Retrieves all input data of a state. If several data flows are connected to an input port the most current data is used for the specific input port. :param state: the state of which the input data is determined :return: the input data of the target state
3.365699
3.248546
1.036063
for dict_key, value in dictionary.items(): for input_data_port_key, data_port in list(self.input_data_ports.items()): if dict_key == data_port.name: self.scoped_data[str(input_data_port_key) + self.state_id] = \ ScopedData(data_por...
def add_input_data_to_scoped_data(self, dictionary)
Add a dictionary to the scoped data As the input_data dictionary maps names to values, the functions looks for the proper data_ports keys in the input_data_ports dictionary :param dictionary: The dictionary that is added to the scoped data :param state: The state to which the input_dat...
2.777373
2.592979
1.071113
for output_name, value in dictionary.items(): for output_data_port_key, data_port in list(state.output_data_ports.items()): if output_name == data_port.name: if not isinstance(value, data_port.data_type): if (not ((type(value) is f...
def add_state_execution_output_to_scoped_data(self, dictionary, state)
Add a state execution output to the scoped data :param dictionary: The dictionary that is added to the scoped data :param state: The state that finished execution and provide the dictionary
3.182328
3.336316
0.953845
for key, scoped_var in self.scoped_variables.items(): self.scoped_data[str(scoped_var.data_port_id) + self.state_id] = \ ScopedData(scoped_var.name, scoped_var.default_value, scoped_var.data_type, self.state_id, ScopedVariable, parent=self)
def add_default_values_of_scoped_variables_to_scoped_data(self)
Add the scoped variables default values to the scoped_data dictionary
5.065088
4.383901
1.155384
for key, value in dictionary.items(): output_data_port_key = None # search for the correct output data port key of the source state for o_key, o_port in state.output_data_ports.items(): if o_port.name == key: output_data_port_key =...
def update_scoped_variables_with_output_dictionary(self, dictionary, state)
Update the values of the scoped variables with the output dictionary of a specific state. :param: the dictionary to update the scoped variables with :param: the state the output dictionary belongs to
3.85655
3.881459
0.993582
old_state_id = self.state_id super(ContainerState, self).change_state_id(state_id) # Use private variables to change ids to prevent validity checks # change id in all transitions for transition in self.transitions.values(): if transition.from_state == old_sta...
def change_state_id(self, state_id=None)
Changes the id of the state to a new id. This functions replaces the old state_id with the new state_id in all data flows and transitions. :param state_id: The new state if of the state
2.302804
2.285208
1.0077
if not isinstance(transition, Transition): raise TypeError("transition must be of type Transition") # the to_state is None when the transition connects an outcome of a child state to the outcome of a parent state if transition.to_state == self.state_id or transition.to_state...
def get_state_for_transition(self, transition)
Calculate the target state of a transition :param transition: The transition of which the target state is determined :return: the to-state of the transition :raises exceptions.TypeError: if the transition parameter is of wrong type
4.453119
4.508022
0.987821
if isinstance(specific_output_dictionary, dict): output_dict = specific_output_dictionary else: output_dict = self.output_data for output_name, value in self.output_data.items(): output_port_id = self.get_io_data_port_id_from_name_and_type(output_nam...
def write_output_data(self, specific_output_dictionary=None)
Write the scoped data to output of the state. Called before exiting the container state. :param specific_output_dictionary: an optional dictionary to write the output data in :return:
3.234934
3.094554
1.045363
# First let the state do validity checks for outcomes and data ports valid, message = super(ContainerState, self).check_child_validity(child) if not valid and not message.startswith("Invalid state element"): return False, message # Continue with checks if previous on...
def check_child_validity(self, child)
Check validity of passed child object The method is called by state child objects (transitions, data flows) when these are initialized or changed. The method checks the type of the child and then checks its validity in the context of the state. :param object child: The child of the state that ...
6.535484
5.401227
1.21
for data_flow in self.data_flows.values(): # Check whether the data flow connects the given port from_port = self.get_data_port(data_flow.from_state, data_flow.from_key) to_port = self.get_data_port(data_flow.to_state, data_flow.to_key) if check_data_port...
def check_data_port_connection(self, check_data_port)
Checks the connection validity of a data port The method is called by a child state to check the validity of a data port in case it is connected with data flows. The data port does not belong to 'self', but to one of self.states. If the data port is connected to a data flow, the method checks, ...
3.805209
3.297326
1.154029
# First check inputs and outputs valid, message = super(ContainerState, self)._check_data_port_id(data_port) if not valid: return False, message # Container state also has scoped variables for scoped_variable_id, scoped_variable in self.scoped_variables.items...
def _check_data_port_id(self, data_port)
Checks the validity of a data port id Checks whether the id of the given data port is already used by anther data port (input, output, scoped vars) within the state. :param rafcon.core.data_port.DataPort data_port: The data port to be checked :return bool validity, str message: validit...
4.489683
3.624484
1.238709
# First check inputs and outputs valid, message = super(ContainerState, self)._check_data_port_name(data_port) if not valid: return False, message if data_port.data_port_id in self.scoped_variables: for scoped_variable in self.scoped_variables.values(): ...
def _check_data_port_name(self, data_port)
Checks the validity of a data port name Checks whether the name of the given data port is already used by anther data port within the state. Names must be unique with input data ports, output data ports and scoped variables. :param rafcon.core.data_port.DataPort data_port: The data port to be ...
4.349181
3.458201
1.257643
valid, message = self._check_data_flow_id(check_data_flow) if not valid: return False, message valid, message = self._check_data_flow_ports(check_data_flow) if not valid: return False, message return self._check_data_flow_types(check_data_flow)
def _check_data_flow_validity(self, check_data_flow)
Checks the validity of a data flow Calls further checks to inspect the id, ports and data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. message gives ...
2.432559
1.839661
1.322287
data_flow_id = data_flow.data_flow_id if data_flow_id in self.data_flows and data_flow is not self.data_flows[data_flow_id]: return False, "data_flow_id already existing" return True, "valid"
def _check_data_flow_id(self, data_flow)
Checks the validity of a data flow id Checks whether the id of the given data flow is already by anther data flow used within the state. :param rafcon.core.data_flow.DataFlow data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is vali...
2.841171
2.560985
1.109406
# Check whether the data types or origin and target fit from_data_port = self.get_data_port(check_data_flow.from_state, check_data_flow.from_key) to_data_port = self.get_data_port(check_data_flow.to_state, check_data_flow.to_key) # Connections from the data port type "object" ar...
def _check_data_flow_types(self, check_data_flow)
Checks the validity of the data flow connection Checks whether the ports of a data flow have matching data types. :param rafcon.core.data_flow.DataFlow check_data_flow: The data flow to be checked :return bool validity, str message: validity is True, when the data flow is valid, False else. me...
3.087724
2.825542
1.09279
valid, message = self._check_transition_id(check_transition) if not valid: return False, message # Separate check for start transitions if check_transition.from_state is None: return self._check_start_transition(check_transition) valid, message ...
def _check_transition_validity(self, check_transition)
Checks the validity of a transition Calls further checks to inspect the id, origin, target and connection of the transition. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is vali...
2.547559
2.175494
1.171025
transition_id = transition.transition_id if transition_id in self.transitions and transition is not self.transitions[transition_id]: return False, "transition_id already existing" return True, "valid"
def _check_transition_id(self, transition)
Checks the validity of a transition id Checks whether the transition id is already used by another transition within the state :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, F...
4.085684
3.901509
1.047206
for transition in self.transitions.values(): if transition.from_state is None: if start_transition is not transition: return False, "Only one start transition is allowed" if start_transition.from_outcome is not None: return False, "fr...
def _check_start_transition(self, start_transition)
Checks the validity of a start transition Checks whether the given transition is a start transition a whether it is the only one within the state. :param rafcon.core.transition.Transition start_transition: The transition to be checked :return bool validity, str message: validity is True, when ...
4.267087
4.042559
1.055541
to_state_id = transition.to_state to_outcome_id = transition.to_outcome if to_state_id == self.state_id: if to_outcome_id not in self.outcomes: return False, "to_outcome is not existing" else: if to_state_id not in self.states: ...
def _check_transition_target(self, transition)
Checks the validity of a transition target Checks whether the transition target is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives ...
3.026639
2.768722
1.093154
from_state_id = transition.from_state from_outcome_id = transition.from_outcome if from_state_id == self.state_id: return False, "from_state_id of transition must not be the container state itself." \ " In the case of a start transition both the fr...
def _check_transition_origin(self, transition)
Checks the validity of a transition origin Checks whether the transition origin is valid. :param rafcon.core.transition.Transition transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is valid, False else. message gives ...
3.429959
3.594755
0.954157
from_state_id = check_transition.from_state from_outcome_id = check_transition.from_outcome to_state_id = check_transition.to_state to_outcome_id = check_transition.to_outcome # check for connected origin for transition in self.transitions.values(): ...
def _check_transition_connection(self, check_transition)
Checks the validity of a transition connection Checks whether the transition is allowed to connect the origin with the target. :param rafcon.core.transition.Transition check_transition: The transition to be checked :return bool validity, str message: validity is True, when the transition is va...
3.126515
3.156762
0.990418
number_of_all_child_states = 0 max_child_hierarchy_level = 0 for s in self.states.values(): child_hierarchy_level = 0 number_of_child_states, child_hierarchy_level = s.get_states_statistics(child_hierarchy_level) number_of_all_child_states += number_o...
def get_states_statistics(self, hierarchy_level)
Returns the numer of child states :return:
2.038308
1.981542
1.028647
number_of_all_transitions = 0 for s in self.states.values(): number_of_all_transitions += s.get_number_of_transitions() return number_of_all_transitions + len(self.transitions)
def get_number_of_transitions(self)
Returns the numer of child states :return:
2.616655
2.64166
0.990534
if not isinstance(states, dict): raise TypeError("states must be of type dict") if [state_id for state_id, state in states.items() if not isinstance(state, State)]: raise TypeError("element of container_state.states must be of type State") if [state_id for state_...
def states(self, states)
Setter for _states field See property :param states: Dictionary of States :raises exceptions.TypeError: if the states parameter is of wrong type :raises exceptions.AttributeError: if the keys of the dictionary and the state_ids in the dictionary do not match
3.128615
2.914676
1.073401
if not isinstance(transitions, dict): raise TypeError("transitions must be of type dict") if [t_id for t_id, transition in transitions.items() if not isinstance(transition, Transition)]: raise TypeError("element of transitions must be of type Transition") if [t_i...
def transitions(self, transitions)
Setter for _transitions field See property :param: transitions: Dictionary transitions[transition_id] of :class:`rafcon.core.transition.Transition` :raises exceptions.TypeError: if the transitions parameter has the wrong type :raises exceptions.AttributeError: if the keys of the transi...
2.91547
2.808103
1.038234
if not isinstance(data_flows, dict): raise TypeError("data_flows must be of type dict") if [df_id for df_id, data_flow in data_flows.items() if not isinstance(data_flow, DataFlow)]: raise TypeError("element of data_flows must be of type DataFlow") if [df_id for d...
def data_flows(self, data_flows)
Setter for _data_flows field See property :param dict data_flows: Dictionary data_flows[data_flow_id] of :class:`rafcon.core.data_flow.DataFlow` :raises exceptions.TypeError: if the data_flows parameter has the wrong type :raises exceptions.AttributeError: if the keys of the data_flows...
2.423234
2.356072
1.028506
for transition_id in self.transitions: if self.transitions[transition_id].from_state is None: to_state = self.transitions[transition_id].to_state if to_state is not None: return to_state else: return sel...
def start_state_id(self)
The start state is the state to which the first transition goes to. The setter-method creates a unique first transition to the state with the given id. Existing first transitions are removed. If the given state id is None, the first transition is removed. :return: The id of the start state
2.811295
2.910952
0.965765
if start_state_id is not None and start_state_id not in self.states: raise ValueError("start_state_id does not exist") if start_state_id is None and to_outcome is not None: # this is the case if the start state is the state itself if to_outcome not in self.outcomes: ...
def start_state_id(self, start_state_id, to_outcome=None)
Set the start state of the container state See property :param start_state_id: The state id of the state which should be executed first in the Container state :raises exceptions.ValueError: if the start_state_id does not exist in :py:attr:`rafcon.core.states...
2.693276
2.634165
1.02244
if not isinstance(scoped_variables, dict): raise TypeError("scoped_variables must be of type dict") if [sv_id for sv_id, sv in scoped_variables.items() if not isinstance(sv, ScopedVariable)]: raise TypeError("element of scope variable must be of type ScopedVariable") ...
def scoped_variables(self, scoped_variables)
Setter for _scoped_variables field See property :param dict scoped_variables: Dictionary scoped_variables[data_port_id] of :class:`rafcon.core.scope.ScopedVariable` :raises exceptions.TypeError: if the scoped_variables parameter has the wrong type :raises exceptions.AttributeError: if ...
2.944813
2.509854
1.1733
self._script.build_module() outcome_item = self._script.execute(self, execute_inputs, execute_outputs, backward_execution) # in the case of backward execution the outcome is not relevant if backward_execution: return # If the state was preempted, the state...
def _execute(self, execute_inputs, execute_outputs, backward_execution=False)
Calls the custom execute function of the script.py of the state
4.46055
4.182984
1.066356
if self.is_root_state: self.execution_history.push_call_history_item(self, CallType.EXECUTE, None, self.input_data) logger.debug("Running {0}{1}".format(self, " (backwards)" if self.backward_execution else "")) if self.backward_execution: self.setup_backward_run...
def run(self)
This defines the sequence of actions that are taken when the execution state is executed :return:
3.558769
3.516773
1.011942
super(StateMachineTreeController, self).register_view(view) self.view.connect('button_press_event', self.mouse_click) self.view_is_registered = True self.update(with_expand=True)
def register_view(self, view)
Called when the view was registered
6.66703
6.508952
1.024286
shortcut_manager.add_callback_for_action("delete", self._delete_selection) shortcut_manager.add_callback_for_action("add", partial(self._add_new_state, state_type=StateType.EXECUTION)) shortcut_manager.add_callback_for_action("add2", partial(self._add_new_state, state_type=StateType.HIE...
def register_actions(self, shortcut_manager)
Register callback methods for triggered actions :param rafcon.gui.shortcut_manager.ShortcutManager shortcut_manager: Shortcut Manager Object holding mappings between shortcuts and actions.
2.266572
2.175251
1.041982
self._do_selection_update = True # relieve old model if self.__my_selected_sm_id is not None: # no old models available self.relieve_model(self._selected_sm_model) # set own selected state machine id self.__my_selected_sm_id = self.model.selected_state_machi...
def register(self)
Change the state machine that is observed for new selected states to the selected state machine.
4.843968
4.120703
1.17552
if react_to_event(self.view, self.tree_view, event): sm_selection, _ = self.get_state_machine_selection() # only list specific elements are cut by widget if len(sm_selection.states) == 1: global_clipboard.paste(sm_selection.get_selected_state(), limit...
def paste_action_callback(self, *event)
Callback method for paste action
11.24892
11.389453
0.987661
if react_to_event(self.view, self.view['state_machine_tree_view'], event): state_type = StateType.EXECUTION if 'state_type' not in kwargs else kwargs['state_type'] gui_helper_state_machine.add_new_state(self._selected_sm_model, state_type) return True
def _add_new_state(self, *event, **kwargs)
Triggered when shortcut keys for adding a new state are pressed, or Menu Bar "Edit, Add State" is clicked. Adds a new state only if the the state machine tree is in focus.
7.789875
6.409692
1.215327
# do not forward cursor selection updates if state update is running # TODO maybe make this generic for respective abstract controller if self._state_which_is_updated: return super(StateMachineTreeController, self).selection_changed(widget, event)
def selection_changed(self, widget, event=None)
Notify state machine about tree view selection
23.672798
19.729811
1.199849
def set_expansion_state(state_path): state_row_iter = self.state_row_iter_dict_by_state_path[state_path] if state_row_iter: # may elements are missing afterwards state_row_path = self.tree_store.get_path(state_row_iter) self.view.expand_to_path(...
def redo_expansion_state(self, ignore_not_existing_rows=False)
Considers the tree to be collapsed and expand into all tree item with the flag set True
3.538137
3.600315
0.98273
if not self.view_is_registered: return # define initial state-model for update if changed_state_model is None: # reset all parent_row_iter = None self.state_row_iter_dict_by_state_path.clear() self.tree_store.clear() ...
def update(self, changed_state_model=None, with_expand=False)
Checks if all states are in tree and if tree has states which were deleted :param changed_state_model: Model that row has to be updated :param with_expand: The expand flag for the tree
4.958174
4.857076
1.020815
upper_most_lib_state_m = None if isinstance(state_model, LibraryStateModel): uppermost_library_root_state = state_model.state.get_uppermost_library_root_state() if uppermost_library_root_state is None: upper_most_lib_state_m = state_model else...
def show_content(self, state_model)
Check state machine tree specific show content flag. Is returning true if the upper most library state of a state model has a enabled show content flag or if there is no library root state above this state. :param rafcon.gui.models.abstract_state.AbstractStateModel state_model: The state model...
2.823818
2.482249
1.137605
if self._selected_sm_model: return self._selected_sm_model.selection, self._selected_sm_model.selection.states else: return None, set()
def get_state_machine_selection(self)
Getter state machine selection :return: selection object, filtered set of selected states :rtype: rafcon.gui.selection.Selection, set
5.177816
4.395707
1.177926
if event.get_button()[1] == 1: # Left mouse button path_info = self.tree_view.get_path_at_pos(int(event.x), int(event.y)) if path_info: # Valid entry was clicked on path = path_info[0] iter = self.tree_store.get_iter(path) state_...
def _handle_double_click(self, event)
Double click with left mouse button focuses the state and toggles the collapse status
4.814394
4.309244
1.117225
if not outputs: outputs = {} if not inputs: inputs = {} if backward_execution: if hasattr(self._compiled_module, "backward_execute"): return self._compiled_module.backward_execute( state, inputs, outputs, rafcon.cor...
def execute(self, state, inputs=None, outputs=None, backward_execution=False)
Execute the user 'execute' function specified in the script :param ExecutionState state: the state belonging to the execute function, refers to 'self' :param dict inputs: the input data of the script :param dict outputs: the output data of the script :param bool backward_execution: Flag...
3.521144
3.54723
0.992646
script_text = filesystem.read_file(self.path, self.filename) if not script_text: raise IOError("Script file could not be opened or was empty: {0}" "".format(os.path.join(self.path, self.filename))) self.script = script_text
def _load_script(self)
Loads the script from the filesystem :raises exceptions.IOError: if the script file could not be opened
4.493508
4.585104
0.980023
try: imp.acquire_lock() module_name = os.path.splitext(self.filename)[0] + str(self._script_id) # load module tmp_module = imp.new_module(module_name) code = compile(self.script, '%s (%s)' % (self.filename, self._script_id), 'exec') ...
def build_module(self)
Builds a temporary module from the script file :raises exceptions.IOError: if the compilation of the script module failed
3.628582
3.116927
1.164154
config_key = info['args'][1] # config_value = info['args'][2] if config_key == "LIBRARY_PATHS": library_manager.refresh_libraries() elif config_key == "SHORTCUTS": self.refresh_shortcuts() elif config_key == "recently_opened_state_machines": ...
def on_config_value_changed(self, config_m, prop_name, info)
Callback when a config value has been changed :param ConfigModel config_m: The config model that has been changed :param str prop_name: Should always be 'config' :param dict info: Information e.g. about the changed config key
5.127907
5.822653
0.880682
if not self.registered_view: return for item in self.view.sub_menu_open_recently.get_children(): self.view.sub_menu_open_recently.remove(item) menu_item = gui_helper_label.create_menu_item("remove invalid paths", constants.ICON_ERASE, ...
def _update_recently_opened_state_machines(self)
Update the sub menu Open Recent in File menu Method clean's first all menu items of the sub menu 'recent open', then insert the user menu item to clean recent opened state machine paths and finally insert menu items for all elements in recent opened state machines list.
3.774358
3.579563
1.054419
self.sm_notebook.set_show_tabs(False) self.main_window_view['graphical_editor_vbox'].remove(self.sm_notebook) self.full_screen_window.add(self.sm_notebook) position = self.main_window_view.get_top_widget().get_position() self.full_screen_window.show() self.full_s...
def on_full_screen_activate(self, *args)
function to display the currently selected state machine in full screen mode :param args: :return:
3.495579
3.277311
1.0666
for handler_id in self.handler_ids.keys(): self.view[handler_id].disconnect(self.handler_ids[handler_id])
def unregister_view(self)
import log Unregister all registered functions to a view element :return:
4.762212
4.653236
1.023419
if action not in self.registered_shortcut_callbacks: self.registered_shortcut_callbacks[action] = [] self.registered_shortcut_callbacks[action].append(callback) self.shortcut_manager.add_callback_for_action(action, callback)
def add_callback_to_shortcut_manager(self, action, callback)
Helper function to add an callback for an action to the shortcut manager. :param action: the action to add a shortcut for :param callback: the callback if the action is executed :return:
2.14532
2.31279
0.92759
for action in self.registered_shortcut_callbacks.keys(): for callback in self.registered_shortcut_callbacks[action]: self.shortcut_manager.remove_callback_for_action(action, callback) # delete all registered shortcut callbacks self.registered_shortcut_callbac...
def remove_all_callbacks(self)
Remove all callbacks registered to the shortcut manager :return:
3.779529
3.257633
1.160207
# determine sign of determinant # ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0 return ((line_end[0] - line_start[0]) * (point[1] - line_start[1]) - (line_end[1] - line_start[1]) * (point[0] - line_start[0])) < 0
def point_left_of_line(point, line_start, line_end)
Determines whether a point is left of a line :param point: Point to be checked (tuple with x any y coordinate) :param line_start: Starting point of the line (tuple with x any y coordinate) :param line_end: End point of the line (tuple with x any y coordinate) :return: True if point is left of line, els...
1.990959
2.085846
0.954509
length = dist(line_start, line_end) ds = length / float(accuracy) if -ds < (dist(line_start, point) + dist(point, line_end) - length) < ds: return True return False
def point_on_line(point, line_start, line_end, accuracy=50.)
Checks whether a point lies on a line The function checks whether the point "point" (P) lies on the line defined by its starting point line_start (A) and its end point line_end (B). This is done by comparing the distance of [AB] with the sum of the distances [AP] and [PB]. If the difference is smaller ...
4.207008
4.404271
0.955211
def _test(p1, p2, p3): return (p1[0] - p3[0]) * (p2[1] - p3[1]) - (p2[0] - p3[0]) * (p1[1] - p3[1]) b1 = _test(p, v1, v2) < 0.0 b2 = _test(p, v2, v3) < 0.0 b3 = _test(p, v3, v1) < 0.0 return (b1 == b2) and (b2 == b3)
def point_in_triangle(p, v1, v2, v3)
Checks whether a point is within the given triangle The function checks, whether the given point p is within the triangle defined by the the three corner point v1, v2 and v3. This is done by checking whether the point is on all three half-planes defined by the three edges of the triangle. :param p: The...
1.607121
1.768321
0.90884
if not len(t1) == len(t2): return False for idx in range(len(t1)): if digit is not None: if not round(t1[idx], digit) == round(t2[idx], digit): return False else: if not t1[idx] == t2[idx]: return False return True
def equal(t1, t2, digit=None)
Compare two iterators and its elements on specific digit precision The method assume that t1 and t2 are are list or tuple. :param t1: First element to compare :param t2: Second element to compare :param int digit: Number of digits to compare :rtype bool :return: True if equal and False if diff...
1.87741
1.925124
0.975215
box1_x_min, box1_y_min = box1_pos box1_x_max, box1_y_max = (box1_pos[0] + box1_size[0], box1_pos[1] + box1_size[1]) box2_x_min, box2_y_min = box2_pos box2_x_max, box2_y_max = (box2_pos[0] + box2_size[0], box2_pos[1] + box2_size[1]) # 1|2|3 +-> x => works also fo...
def cal_dist_between_2_coord_frame_aligned_boxes(box1_pos, box1_size, box2_pos, box2_size)
Calculate Euclidean distance between two boxes those edges are parallel to the coordinate axis The function decides condition based which corner to corner or edge to edge distance needs to be calculated. :param tuple box1_pos: x and y position of box 1 :param tuple box1_size: x and y size of box 1 :pa...
2.113697
2.123766
0.995259