code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
history_item = self.history_tree_store[child_tree_iter][self.HISTORY_ITEM_STORAGE_ID]
if history_item is None: # is dummy item
if self.history_tree_store.iter_n_children(child_tree_iter) > 0:
child_iter = self.history_tree_store.iter_nth_child(child_tree_iter, 0)
... | def get_history_item_for_tree_iter(self, child_tree_iter) | Hands history item for tree iter and compensate if tree item is a dummy item
:param Gtk.TreeIter child_tree_iter: Tree iter of row
:rtype rafcon.core.execution.execution_history.HistoryItem:
:return history tree item: | 3.434066 | 3.432692 | 1.0004 |
def store_tree_expansion(child_tree_iter, expansion_state):
tree_item_path = self.history_tree_store.get_path(child_tree_iter)
history_item = self.get_history_item_for_tree_iter(child_tree_iter)
# store expansion state if tree item path is valid and expansion stat... | def _store_expansion_state(self) | Iter recursively all tree items and store expansion state | 2.93538 | 2.840655 | 1.033346 |
def restore_tree_expansion(child_tree_iter, expansion_state):
tree_item_path = self.history_tree_store.get_path(child_tree_iter)
history_item = self.get_history_item_for_tree_iter(child_tree_iter)
# restore expansion state if tree item path is valid and expansion s... | def _restore_expansion_state(self) | Iter recursively all tree items and restore expansion state | 2.463566 | 2.403318 | 1.025068 |
selected_state_machine_id = self.model.selected_state_machine_id
if selected_state_machine_id is None:
return
self.update() | def notification_selected_sm_changed(self, model, prop_name, info) | If a new state machine is selected, make sure expansion state is stored and tree updated | 4.278278 | 3.271622 | 1.307693 |
for state_machine_id in list(self._expansion_state.keys()):
if state_machine_id not in self.model.state_machines:
del self._expansion_state[state_machine_id] | def notification_sm_changed(self, model, prop_name, info) | Remove references to non-existing state machines | 4.200238 | 2.857498 | 1.4699 |
if state_machine_execution_engine.status.execution_mode in \
[StateMachineExecutionStatus.STARTED, StateMachineExecutionStatus.STOPPED,
StateMachineExecutionStatus.FINISHED]:
if self.parent is not None and hasattr(self.parent, "focus_notebook_page_of_control... | def execution_history_focus(self, model, prop_name, info) | Arranges to put execution-history widget page to become top page in notebook when execution starts and stops
and resets the boolean of modification_history_was_focused to False each time this notification are observed. | 5.843915 | 5.459163 | 1.070478 |
self.history_tree_store.clear()
selected_sm_m = self.model.get_selected_state_machine_model()
if selected_sm_m:
# the core may continue running without the GUI and for this it needs its execution histories
if state_machine_execution_engine.finished_or_stopped():
... | def clean_history(self, widget, event=None) | Triggered when the 'Clean History' button is clicked.
Empties the execution history tree by adjusting the start index and updates tree store and view. | 11.560283 | 10.443255 | 1.106962 |
# with self._update_lock:
self._update_lock.acquire()
self._store_expansion_state()
self.history_tree_store.clear()
selected_sm_m = self.model.get_selected_state_machine_model()
if not selected_sm_m:
return
for execution_number, execution_his... | def update(self) | rebuild the tree view of the history item tree store
:return: | 3.35173 | 3.169244 | 1.05758 |
if not history_item.state_reference:
logger.error("This must never happen! Current history_item is {}".format(history_item))
return None
content = None
if global_gui_config.get_config_value("SHOW_PATH_NAMES_IN_EXECUTION_HISTORY", False):
content = (h... | def insert_history_item(self, parent, history_item, description, dummy=False) | Enters a single history item into the tree store
:param Gtk.TreeItem parent: Parent tree item
:param HistoryItem history_item: History item to be inserted
:param str description: A description to be added to the entry
:param None dummy: Whether this is just a dummy entry (wrapper for co... | 4.16947 | 4.196863 | 0.993473 |
current_parent = parent
execution_history_iterator = iter(execution_history)
for history_item in execution_history_iterator:
if isinstance(history_item, ConcurrencyItem):
self.insert_concurrent_execution_histories(current_parent, history_item.execution_histor... | def insert_execution_history(self, parent, execution_history, is_root=False) | Insert a list of history items into a the tree store
If there are concurrency history items, the method is called recursively.
:param Gtk.TreeItem parent: the parent to add the next history item to
:param ExecutionHistory execution_history: all history items of a certain state machine executio... | 4.045884 | 3.964765 | 1.02046 |
for execution_history in concurrent_execution_histories:
if len(execution_history) >= 1:
first_history_item = execution_history[0]
# this is just a dummy item to have an extra parent for each branch
# gives better overview in case that one of ... | def insert_concurrent_execution_histories(self, parent, concurrent_execution_histories) | Adds the child execution histories of a concurrency state.
:param Gtk.TreeItem parent: the parent to add the next history item to
:param list[ExecutionHistory] concurrent_execution_histories: a list of all child execution histories
:return: | 6.584224 | 6.362774 | 1.034804 |
library_state = self._get_selected_library_state()
import rafcon.gui.helpers.state_machine as gui_helper_state_machine
gui_helper_state_machine.add_state_by_drag_and_drop(library_state, data) | def on_drag_data_get(self, widget, context, data, info, time) | dragged state is inserted and its state_id sent to the receiver
:param widget:
:param context:
:param data: SelectionData: contains state_id
:param info:
:param time: | 8.453434 | 7.690404 | 1.099218 |
(model, row_path) = self.view.get_selection().get_selected()
if row_path:
physical_library_path = model[row_path][self.ITEM_STORAGE_ID]
smm = gui_singletons.state_machine_manager_model.state_machine_manager
sm = smm.get_open_state_machine_of_file_system_path(... | def select_open_state_machine_of_selected_library_element(self) | Select respective state machine of selected library in state machine manager if already open | 4.150083 | 4.152991 | 0.9993 |
menu_item_text = self.get_menu_item_text(menu_item)
logger.info("Delete item '{0}' pressed.".format(menu_item_text))
model, path = self.view.get_selection().get_selected()
if path:
# Second confirmation to delete library
tree_m_row = self.tree_store[pat... | def menu_item_remove_libraries_or_root_clicked(self, menu_item) | Removes library from hard drive after request second confirmation | 4.283175 | 4.184503 | 1.02358 |
(model, row) = self.view.get_selection().get_selected()
tree_item_key = model[row][self.ID_STORAGE_ID]
library_item = model[row][self.ITEM_STORAGE_ID]
library_path = model[row][self.LIB_PATH_STORAGE_ID]
if isinstance(library_item, dict): # sub-tree
os_path =... | def extract_library_properties_from_selected_row(self) | Extracts properties library_os_path, library_path, library_name and tree_item_key from tree store row | 3.699026 | 2.873375 | 1.287345 |
library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row()
if library_path is None:
return None
logger.debug("Link library state '{0}' (with library tree path: {2} and file system path: {1}) into state "
... | def _get_selected_library_state(self) | Returns the LibraryState which was selected in the LibraryTree
:return: selected state in TreeView
:rtype: LibraryState | 6.549146 | 6.328375 | 1.034886 |
self.execution_history = execution_history
if generate_run_id:
self._run_id = run_id_generator()
self.backward_execution = copy.copy(backward_execution)
self.thread = threading.Thread(target=self.run)
self.thread.start() | def start(self, execution_history, backward_execution=False, generate_run_id=True) | Starts the execution of the state in a new thread.
:return: | 2.561288 | 2.703745 | 0.947311 |
if self.thread:
self.thread.join()
self.thread = None
else:
logger.debug("Cannot join {0}, as the state hasn't been started, yet or is already finished!".format(self)) | def join(self) | Waits until the state finished execution. | 7.415958 | 5.395878 | 1.374375 |
self.state_execution_status = StateExecutionStatus.ACTIVE
self.preempted = False
if not isinstance(self.input_data, dict):
raise TypeError("input_data must be of type dict")
if not isinstance(self.output_data, dict):
raise TypeError("output_data must be o... | def setup_run(self) | Executes a generic set of actions that has to be called in the run methods of each derived state class.
:raises exceptions.TypeError: if the input or output data are not of type dict | 3.607099 | 2.972469 | 1.213503 |
self.preempted = True
self.paused = False
self.started = False | def recursively_preempt_states(self) | Preempt the state | 7.862587 | 6.610847 | 1.189346 |
from rafcon.core.states.library_state import LibraryState
result_dict = {}
for input_port_key, value in state.input_data_ports.items():
if isinstance(state, LibraryState):
if state.use_runtime_value_input_data_ports[input_port_key]:
defaul... | def get_default_input_values_for_state(self, state) | Computes the default input values for a state
:param State state: the state to get the default input values for | 3.242601 | 3.21653 | 1.008105 |
from rafcon.core.states.library_state import LibraryState
result_dict = {}
for key, data_port in state.output_data_ports.items():
if isinstance(state, LibraryState) and state.use_runtime_value_output_data_ports[key]:
result_dict[data_port.name] = copy.copy(st... | def create_output_dictionary_for_state(state) | Return empty output dictionary for a state
:param state: the state of which the output data is determined
:return: the output data of the target state | 3.780943 | 3.842551 | 0.983967 |
if data_port_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
data_port_id = generate_data_port_id(self.get_data_port_ids())
self._input_data_ports[data_port_id] = InputDataPort(name, data_type, defau... | def add_input_data_port(self, name, data_type=None, default_value=None, data_port_id=None) | Add a new input data port to the state.
:param str name: the name of the new input data port
:param data_type: the type of the new output data port considered of class :class:`type` or
:class:`str` which has to be convertible to :class:`type`
:param default_value: the ... | 3.015994 | 3.097372 | 0.973727 |
if data_port_id in self._input_data_ports:
if destroy:
self.remove_data_flows_with_data_port_id(data_port_id)
self._input_data_ports[data_port_id].parent = None
return self._input_data_ports.pop(data_port_id)
else:
raise AttributeE... | def remove_input_data_port(self, data_port_id, force=False, destroy=True) | Remove an input data port from the state
:param int data_port_id: the id or the output data port to remove
:param bool force: if the removal should be forced without checking constraints
:raises exceptions.AttributeError: if the specified input data port does not exist | 2.792438 | 2.999208 | 0.931058 |
if not self.is_root_state:
# delete all data flows in parent related to data_port_id and self.state_id
data_flow_ids_to_remove = []
for data_flow_id, data_flow in self.parent.data_flows.items():
if data_flow.from_state == self.state_id and data_flow.f... | def remove_data_flows_with_data_port_id(self, data_port_id) | Remove all data flows whose from_key or to_key equals the passed data_port_id
:param 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.327431 | 2.221099 | 1.047873 |
if data_port_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
data_port_id = generate_data_port_id(self.get_data_port_ids())
self._output_data_ports[data_port_id] = OutputDataPort(name, data_type, def... | def add_output_data_port(self, name, data_type, default_value=None, data_port_id=None) | Add a new output data port to the state
:param str name: the name of the new output data port
:param data_type: the type of the new output data port considered of class :class:`type` or
:class:`str` which has to be convertible to :class:`type`
:param default_value: the... | 2.982672 | 3.081381 | 0.967966 |
if data_port_id in self._output_data_ports:
if destroy:
self.remove_data_flows_with_data_port_id(data_port_id)
self._output_data_ports[data_port_id].parent = None
return self._output_data_ports.pop(data_port_id)
else:
raise Attribu... | def remove_output_data_port(self, data_port_id, force=False, destroy=True) | Remove an output data port from the state
:param int data_port_id: the id of the output data port to remove
:raises exceptions.AttributeError: if the specified input data port does not exist | 2.774422 | 2.864763 | 0.968465 |
if data_port_type is InputDataPort:
for ip_id, output_port in self.input_data_ports.items():
if output_port.name == name:
return ip_id
raise AttributeError("Name '{0}' is not in input_data_ports".format(name))
elif data_port_type is Ou... | def get_io_data_port_id_from_name_and_type(self, name, data_port_type) | Returns the data_port_id of a data_port with a certain name and data port type
:param name: the name of the target data_port
:param data_port_type: the data port type of the target data port
:return: the data port specified by the name and the type
:raises exceptions.AttributeError: if ... | 3.016627 | 3.120995 | 0.966559 |
if data_port_id in self.input_data_ports:
return self.input_data_ports[data_port_id]
elif data_port_id in self.output_data_ports:
return self.output_data_ports[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.
:param int data_port_id: the unique id of the data port
:return: the data port with the searched id or None if it is not found | 1.652139 | 1.76994 | 0.933444 |
if by_name:
state_identifier = self.name
else:
state_identifier = self.state_id
if not self.is_root_state:
if appendix is None:
return self.parent.get_path(state_identifier, by_name)
else:
return self.paren... | def get_path(self, appendix=None, by_name=False) | Recursively create the path of the state.
The path is generated in bottom up method i.e. from the nested child states to the root state. The method
concatenates either State.state_id (always unique) or State.name (maybe not unique but human readable) as
state identifier for the path.
:... | 2.212743 | 2.01293 | 1.099264 |
state_identifier = storage.get_storage_id_for_state(self)
if not self.is_root_state:
if appendix is None:
return self.parent.get_storage_path(state_identifier)
else:
return self.parent.get_storage_path(state_identifier + PATH_SEPARATOR + ... | def get_storage_path(self, appendix=None) | Recursively create the storage path of the state.
The path is generated in bottom up method i.e. from the nested child states to the root state. The method
concatenates the concatenation of (State.name and State.state_id) as state identifier for the path.
:param str appendix: the part of the p... | 2.666851 | 2.697344 | 0.988695 |
if self.parent:
if self.is_root_state:
return self.parent
else:
return self.parent.get_state_machine()
return None | def get_state_machine(self) | Get a reference of the state_machine the state belongs to
:rtype rafcon.core.state_machine.StateMachine
:return: respective state machine | 3.715851 | 3.903624 | 0.951898 |
if not isinstance(file_system_path, string_types):
raise TypeError("file_system_path must be a string")
self._file_system_path = file_system_path | def file_system_path(self, file_system_path) | Setter for file_system_path attribute of state
:param str file_system_path:
:return: | 2.208388 | 2.408467 | 0.916927 |
if outcome_id is None:
outcome_id = generate_outcome_id(list(self.outcomes.keys()))
if name in self._outcomes:
logger.error("Two outcomes cannot have the same names")
return
if outcome_id in self.outcomes:
logger.error("Two outcomes cannot... | def add_outcome(self, name, outcome_id=None) | Add a new outcome to the state
:param str name: the name of the outcome to add
:param int outcome_id: the optional outcome_id of the new outcome
:return: outcome_id: the outcome if of the generated state
:rtype: int | 2.599854 | 2.616438 | 0.993661 |
if isinstance(state_element, Income):
self.remove_income(force, destroy=destroy)
if isinstance(state_element, Outcome):
return self.remove_outcome(state_element.outcome_id, force=force, destroy=destroy)
elif isinstance(state_element, InputDataPort):
r... | def remove(self, state_element, recursive=True, force=False, destroy=True) | Remove item from state
:param StateElement state_element: 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 without c... | 2.266693 | 2.479165 | 0.914297 |
if outcome_id not in self.outcomes:
raise AttributeError("There is no outcome_id %s" % str(outcome_id))
if not force:
if outcome_id == -1 or outcome_id == -2:
raise AttributeError("You cannot remove the outcomes with id -1 or -2 as a state must always be... | def remove_outcome(self, outcome_id, force=False, destroy=True) | Remove an outcome from the state
:param int outcome_id: the id of the outcome to remove
:raises exceptions.AttributeError: if the specified outcome does not exist or
equals the aborted or preempted outcome | 5.11829 | 4.686224 | 1.092199 |
# Check type of child and call appropriate validity test
if isinstance(child, Income):
return self._check_income_validity(child)
if isinstance(child, Outcome):
return self._check_outcome_validity(child)
if isinstance(child, DataPort):
return s... | def check_child_validity(self, child) | Check validity of passed child object
The method is called by state child objects (outcomes, data ports) 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 is ... | 3.522591 | 2.801625 | 1.257339 |
for outcome_id, outcome in self.outcomes.items():
# Do not compare outcome with itself when checking for existing name/id
if check_outcome is not outcome:
if check_outcome.outcome_id == outcome_id:
return False, "outcome id '{0}' existing in s... | def _check_outcome_validity(self, check_outcome) | Checks the validity of an outcome
Checks whether the id or the name of the outcome is already used by another outcome within the state.
:param rafcon.core.logical_port.Outcome check_outcome: The outcome to be checked
:return bool validity, str message: validity is True, when the outcome is val... | 3.31776 | 2.991939 | 1.1089 |
valid, message = self._check_data_port_id(check_data_port)
if not valid:
return False, message
valid, message = self._check_data_port_name(check_data_port)
if not valid:
return False, message
# Check whether the type matches any connected data p... | def _check_data_port_validity(self, check_data_port) | Checks the validity of a data port
Checks whether the data flows connected to the port do not conflict with the data types.
:param rafcon.core.data_port.DataPort check_data_port: The data port to be checked
:return bool validity, str message: validity is True, when the data port is valid, Fals... | 4.458174 | 3.994132 | 1.116181 |
for input_data_port_id, input_data_port in self.input_data_ports.items():
if data_port.data_port_id == input_data_port_id and data_port is not input_data_port:
return False, "data port id already existing in state"
for output_data_port_id, output_data_port in self.ou... | 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) within the
state.
:param rafcon.core.data_port.DataPort data_port: The data port to be checked
:return bool validity, str message: validity is True, wh... | 1.917455 | 1.736266 | 1.104355 |
if data_port.data_port_id in self.input_data_ports:
for input_data_port in self.input_data_ports.values():
if data_port.name == input_data_port.name and data_port is not input_data_port:
return False, "data port name already existing in state's input data... | 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 and output data ports.
:param rafcon.core.data_port.DataPort data_port: The data port to be checked
:r... | 1.954756 | 1.792561 | 1.090482 |
for data_port in self.input_data_ports.values():
if data_port.name in self.input_data and self.input_data[data_port.name] is not None:
#check for class
if not isinstance(self.input_data[data_port.name], data_port.data_type):
logger.error("... | def check_input_data_type(self) | Check the input data types of the state
Checks all input data ports if the handed data is not of the specified type and generate an error logger message
with details of the found type conflict. | 3.354319 | 2.929518 | 1.145007 |
for data_port in self.output_data_ports.values():
if data_port.name in self.output_data and self.output_data[data_port.name] is not None:
# check for class
if not isinstance(self.output_data[data_port.name], data_port.data_type):
logger.er... | def check_output_data_type(self) | Check the output data types of the state
Checks all output data ports if the handed data is not of the specified type and generate an error logger
message with details of the found type conflict. | 3.403724 | 2.957041 | 1.151057 |
if state_id is None:
state_id = state_id_generator(used_state_ids=[self.state_id])
if not self.is_root_state and not self.is_root_state_of_library:
used_ids = list(self.parent.states.keys()) + [self.parent.state_id, self.state_id]
if state_id in used_ids:
... | def change_state_id(self, state_id=None) | Changes the id of the state to a new id
If no state_id is passed as parameter, a new state id is generated.
:param str state_id: The new state id of the state
:return: | 2.848798 | 3.027189 | 0.94107 |
target_dict = self.semantic_data
for path_element in path_as_list:
if path_element in target_dict:
target_dict = target_dict[path_element]
else:
raise KeyError("The state with name {1} and id {2} holds no semantic data with path {0}."
... | def get_semantic_data(self, path_as_list) | Retrieves an entry of the semantic data.
:param list path_as_list: The path in the vividict to retrieve the value from
:return: | 3.369121 | 3.449226 | 0.976776 |
assert isinstance(key, string_types)
target_dict = self.get_semantic_data(path_as_list)
target_dict[key] = value
return path_as_list + [key] | def add_semantic_data(self, path_as_list, value, key) | Adds a semantic data entry.
:param list path_as_list: The path in the vividict to enter the value
:param value: The value of the new entry.
:param key: The key of the new entry.
:return: | 3.366578 | 4.229849 | 0.79591 |
if len(path_as_list) == 0:
raise AttributeError("The argument path_as_list is empty but but the method remove_semantic_data needs a "
"valid path to remove a vividict item.")
target_dict = self.get_semantic_data(path_as_list[0:-1])
removed_el... | def remove_semantic_data(self, path_as_list) | Removes a entry from the semantic data vividict.
:param list path_as_list: The path of the vividict to delete.
:return: removed value or dict | 4.345964 | 3.374361 | 1.287937 |
for in_key in list(self.input_data_ports.keys()):
self.remove_input_data_port(in_key, force=True, destroy=recursive)
for out_key in list(self.output_data_ports.keys()):
self.remove_output_data_port(out_key, force=True, destroy=recursive)
if self._income:
... | def destroy(self, recursive) | Removes all the state elements.
:param recursive: Flag wether to destroy all state elements which are removed | 2.335178 | 2.562335 | 0.911348 |
if not isinstance(input_data_ports, dict):
raise TypeError("input_data_ports must be of type dict")
if [port_id for port_id, port in input_data_ports.items() if not port_id == port.data_port_id]:
raise AttributeError("The key of the input dictionary and the id of the dat... | def input_data_ports(self, input_data_ports) | Property for the _input_data_ports field
See Property.
:param dict input_data_ports: Dictionary that maps :class:`int` data_port_ids onto values of type
:class:`rafcon.core.state_elements.data_port.InputDataPort`
:raises exceptions.TypeError: if the input_... | 2.467485 | 2.27376 | 1.0852 |
if not isinstance(output_data_ports, dict):
raise TypeError("output_data_ports must be of type dict")
if [port_id for port_id, port in output_data_ports.items() if not port_id == port.data_port_id]:
raise AttributeError("The key of the output dictionary and the id of the... | def output_data_ports(self, output_data_ports) | Setter for _output_data_ports field
See property
:param dict output_data_ports: Dictionary that maps :class:`int` data_port_ids onto values of type
:class:`rafcon.core.state_elements.data_port.OutputDataPort`
:raises exceptions.TypeError: if the output_dat... | 2.475539 | 2.281868 | 1.084874 |
if not isinstance(income, Income):
raise ValueError("income must be of type Income")
old_income = self.income
self._income = income
try:
income.parent = self
except ValueError:
self._income = old_income
raise | def income(self, income) | Setter for the state's income | 3.303313 | 3.326169 | 0.993128 |
if not isinstance(outcomes, dict):
raise TypeError("outcomes must be of type dict")
if [outcome_id for outcome_id, outcome in outcomes.items() if not isinstance(outcome, Outcome)]:
raise TypeError("element of outcomes must be of type Outcome")
if [outcome_id for ... | def outcomes(self, outcomes) | Setter for _outcomes field
See property.
:param dict outcomes: Dictionary outcomes[outcome_id] that maps :class:`int` outcome_ids onto values of type
:class:`rafcon.core.state_elements.logical_port.Outcome`
:raises exceptions.TypeError: if outcomes parameter has t... | 2.827133 | 2.611081 | 1.082744 |
from rafcon.core.states.library_state import LibraryState
return isinstance(self.parent, LibraryState) | def is_root_state_of_library(self) | If self is the attribute LibraryState.state_copy of a LibraryState its the library root state and its parent
is a LibraryState
:return True or False
:rtype bool | 10.052298 | 8.028709 | 1.252044 |
from rafcon.core.state_machine import StateMachine
if self.is_root_state_of_library:
return self
state = self
while state.parent is not None and not isinstance(state.parent, StateMachine):
if state.parent.is_root_state_of_library:
return... | def get_next_upper_library_root_state(self) | Get next upper library root state
The method recursively checks state parent states till finding a StateMachine as parent or a library root state.
If self is a LibraryState the next upper library root state is searched and it is not handed self.state_copy.
:return library root state (Execution... | 3.513957 | 2.487322 | 1.412747 |
library_root_state = self.get_next_upper_library_root_state()
parent_library_root_state = library_root_state
# initial a library root state has to be found and if there is no further parent root state
# parent_library_root_state and library_root_state are no more identical
... | def get_uppermost_library_root_state(self) | Find state_copy of uppermost LibraryState
Method checks if there is a parent library root state and assigns it to be the current library root state till
there is no further parent library root state. | 3.134434 | 2.776105 | 1.129076 |
# Set the final outcome of the state
if outcome is not None:
self.final_outcome = outcome
# If we are within a concurrency state, we have to notify it about our finalization
if self.concurrency_queue:
self.concurrency_queue.put(self.state_id)
l... | def finalize(self, outcome=None) | Finalize state
This method is called when the run method finishes
:param rafcon.core.logical_port.Outcome outcome: final outcome of the state
:return: Nothing for the moment | 5.309249 | 5.430619 | 0.977651 |
network_c = Network()
buses = aggregatebuses(
network, busmap, {
'x': _leading(
busmap, network.buses), 'y': _leading(
busmap, network.buses)})
# keep attached lines
lines = network.lines.copy()
mask = lines.bus0.isin(buses.index)
lines... | def cluster_on_extra_high_voltage(network, busmap, with_time=True) | Main function of the EHV-Clustering approach. Creates a new clustered
pypsa.Network given a busmap mapping all bus_ids to other bus_ids of the
same network.
Parameters
----------
network : pypsa.Network
Container for all network components.
busmap : dict
Maps old bus_ids to new... | 2.671345 | 2.784112 | 0.959497 |
M = nx.MultiGraph()
for e in edges:
n0, n1, weight, key = e
M.add_edge(n0, n1, weight=weight, key=key)
return M | def graph_from_edges(edges) | Constructs an undirected multigraph from a list containing data on
weighted edges.
Parameters
----------
edges : list
List of tuples each containing first node, second node, weight, key.
Returns
-------
M : :class:`networkx.classes.multigraph.MultiGraph | 3.333912 | 3.228939 | 1.03251 |
# TODO There could be a more convenient way of doing this. This generators
# single purpose is to prepare data for multiprocessing's starmap function.
g = graph.copy()
for i in range(0, len(nodes), n):
yield (nodes[i:i + n], g) | def gen(nodes, n, graph) | Generator for applying multiprocessing.
Parameters
----------
nodes : list
List of nodes in the system.
n : int
Number of desired multiprocessing units.
graph : :class:`networkx.classes.multigraph.MultiGraph
Graph representation of an electrical grid.
Returns
----... | 11.535728 | 11.861383 | 0.972545 |
def fetch():
query = session.query(EgoGridPfHvBusmap.bus0, EgoGridPfHvBusmap.bus1).\
filter(EgoGridPfHvBusmap.scn_name == scn_name)
return dict(query.all())
busmap = fetch()
# TODO: Or better try/except/finally
if not busmap:
print('Busmap does not exist and... | def busmap_from_psql(network, session, scn_name) | Retrieves busmap from `model_draft.ego_grid_pf_hv_busmap` on the
<OpenEnergyPlatform>[www.openenergy-platform.org] by a given scenario
name. If this busmap does not exist, it is created with default values.
Parameters
----------
network : pypsa.Network object
Container for all network compo... | 5.768881 | 4.63146 | 1.245586 |
super(DescriptionEditorController, self).register_actions(shortcut_manager)
shortcut_manager.add_callback_for_action("abort", self._abort) | 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. | 9.350896 | 7.680743 | 1.217447 |
super(GraphicalEditorController, self).register_view(view)
self.view.connect('meta_data_changed', self._meta_data_changed)
self.focus_changed_handler_id = self.view.editor.connect('focus-changed', self._move_focused_item_into_viewport)
self.view.editor.connect("drag-data-receiv... | def register_view(self, view) | Called when the View was registered | 3.715854 | 3.690944 | 1.006749 |
shortcut_manager.add_callback_for_action("add", partial(self._add_new_state, state_type=StateType.EXECUTION))
shortcut_manager.add_callback_for_action("add_execution_state", partial(self._add_new_state,
state_type=S... | 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. | 1.986754 | 1.973637 | 1.006646 |
config_key = info['args'][1]
# config_value = info['args'][2]
if config_key in ["ENABLE_CACHING", "SHOW_ABORTED_PREEMPTED", "SHOW_DATA_FLOWS",
"SHOW_DATA_FLOW_VALUE_LABELS", "SHOW_NAMES_ON_DATA_FLOWS", "ROTATE_NAMES_ON_CONNECTION"]:
self.update_vie... | 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 | 8.422421 | 9.453359 | 0.890945 |
state_id_insert = data.get_text()
parent_m = self.model.selection.get_selected_state()
if not isinstance(parent_m, ContainerStateModel):
return
state_v = self.canvas.get_view_for_model(parent_m.states[state_id_insert])
pos_start = state_v.model.get_meta_data_... | def on_drag_data_received(self, widget, context, x, y, data, info, time) | Receives state_id from LibraryTree and moves the state to the position of the mouse
:param widget:
:param context:
:param x: Integer: x-position of mouse
:param y: Integer: y-position of mouse
:param data: SelectionData: contains state_id
:param info:
:param time... | 6.100075 | 5.950928 | 1.025063 |
hovered_item = ItemFinder(self.view.editor).get_item_at_point((x, y))
if isinstance(hovered_item, NameView):
hovered_item = hovered_item.parent
if hovered_item is None:
self.view.editor.unselect_all()
elif isinstance(hovered_item.model, ContainerStateMode... | def on_drag_motion(self, widget, context, x, y, time) | Changes the selection on mouse over during drag motion
:param widget:
:param context:
:param x: Integer: x-position of mouse
:param y: Integer: y-position of mouse
:param time: | 2.996083 | 3.129306 | 0.957427 |
if react_to_event(self.view, self.view.editor, event):
state_type = StateType.EXECUTION if 'state_type' not in kwargs else kwargs['state_type']
return gui_helper_state_machine.add_new_state(self.model, state_type) | 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 graphical editor is in focus. | 6.886406 | 6.872108 | 1.002081 |
if react_to_event(self.view, self.view.editor, event):
logger.debug("copy selection")
global_clipboard.copy(self.model.selection)
return True | def _copy_selection(self, *event) | Copies the current selection to the clipboard. | 9.696259 | 8.462726 | 1.145761 |
if react_to_event(self.view, self.view.editor, event):
logger.debug("cut selection")
global_clipboard.cut(self.model.selection)
return True | def _cut_selection(self, *event) | Cuts the current selection and copys it to the clipboard. | 10.463627 | 8.90394 | 1.175168 |
if react_to_event(self.view, self.view.editor, event):
logger.debug("Paste")
gui_helper_state_machine.paste_into_selected_state(self.model)
return True | def _paste_clipboard(self, *event) | Paste the current clipboard into the current selection if the current selection is a container state. | 12.746082 | 9.759113 | 1.30607 |
self.view.editor.handler_block(self.drag_motion_handler_id)
self.move_item_into_viewport(focused_item)
self.view.editor.handler_unblock(self.drag_motion_handler_id) | def _move_focused_item_into_viewport(self, view, focused_item) | Called when an item is focused, moves the item into the viewport
:param view:
:param StateView | ConnectionView | PortView focused_item: The focused item | 3.386444 | 3.566251 | 0.949581 |
if not item:
return
HORIZONTAL = 0
VERTICAL = 1
if not isinstance(item, Item):
state_v = item.parent
elif not isinstance(item, StateView):
state_v = self.canvas.get_parent(item)
else:
state_v = item
viewport... | def move_item_into_viewport(self, item) | Causes the `item` to be moved into the viewport
The zoom factor and the position of the viewport are updated to move the `item` into the viewport. If `item`
is not a `StateView`, the parental `StateView` is moved into the viewport.
:param StateView | ConnectionView | PortView item: The item to... | 3.07743 | 3.037743 | 1.013065 |
if self.model is model: # only used for the state machine destruction case
self.canvas.get_view_for_model(self.root_state_m).remove() | def state_machine_destruction(self, model, prop_name, info) | Clean up when state machine is being destructed | 16.76527 | 15.474015 | 1.083447 |
meta_signal_message = info['arg']
if meta_signal_message.origin == "graphical_editor_gaphas": # Ignore changes caused by ourself
return
if meta_signal_message.origin == "load_meta_data": # Meta data can't be applied, as the view has not yet
return ... | def meta_changed_notify_after(self, state_machine_m, _, info) | Handle notification about the change of a state's meta data
The meta data of the affected state(s) are read and the view updated accordingly.
:param StateMachineModel state_machine_m: Always the state machine model belonging to this editor
:param str _: Always "state_meta_signal"
:param... | 5.59145 | 5.185667 | 1.078251 |
state_machine_m = self.model
state_v = self.canvas.get_view_for_model(state_m)
if state_v is None:
logger.warning('There is no view for state model {0}'.format(state_m))
self.move_item_into_viewport(state_v)
# check_relative size in view and call it again if ... | def set_focus_to_state_model(self, state_m, ratio_requested=0.8) | Focus a state view of respective state model
:param rafcon.gui.model.state state_m: Respective state model of state view to be focused
:param ratio_requested: Minimum ratio of the screen which is requested, so can be more
:return: | 3.86407 | 3.877949 | 0.996421 |
parent_state_v = self.canvas.get_view_for_model(parent_state_m)
hierarchy_level = parent_state_v.hierarchy_level
transition_v = TransitionView(transition_m, hierarchy_level)
# Draw transition above all other state elements
self.canvas.add(transition_v, parent_state_v, ... | def add_transition_view_for_model(self, transition_m, parent_state_m) | Creates a `TransitionView` and adds it to the canvas
The method creates a`TransitionView` from the given `TransitionModel `transition_m` and adds it to the canvas.
:param TransitionModel transition_m: The transition for which a view is to be created
:param ContainerStateModel parent_state_m: ... | 3.559163 | 3.663338 | 0.971563 |
parent_state_v = self.canvas.get_view_for_model(parent_state_m)
hierarchy_level = parent_state_v.hierarchy_level
data_flow_v = DataFlowView(data_flow_m, hierarchy_level)
# Draw data flow above NameView but beneath all other state elements
self.canvas.add(data_flow_v, p... | def add_data_flow_view_for_model(self, data_flow_m, parent_state_m) | Creates a `DataFlowView` and adds it to the canvas
The method creates a`DataFlowView` from the given `DataFlowModel `data_flow_m` and adds it to the canvas.
:param DataFlowModel data_flow_m: The data flow for which a view is to be created
:param ContainerStateModel parent_state_m: The parenta... | 4.001435 | 4.144979 | 0.965369 |
if not react_to_event(self.view, self.view.editor, event):
return False
if not rafcon.gui.singleton.state_machine_manager_model.selected_state_machine_id == \
self.model.state_machine.state_machine_id:
return False
return True | def react_to_event(self, event) | Check whether the given event should be handled
Checks, whether the editor widget has the focus and whether the selected state machine corresponds to the
state machine of this editor.
:param event: GTK event object
:return: True if the event should be handled, else False
:rtype... | 8.156754 | 6.092654 | 1.338785 |
global _loop
_loop = bot.loop
player_manager.user_id = bot.user.id
player_manager.channel_finder_func = bot.get_channel
register_event_listener(_handle_event)
register_update_listener(_handle_update)
lavalink_node = node.Node(
_loop,
dispatch,
bot._connection._... | async def initialize(bot: Bot, host, password, rest_port, ws_port, timeout=30) | Initializes the websocket connection to the lavalink player.
.. important::
This function must only be called AFTER the bot has received its
"on_ready" event!
Parameters
----------
bot : Bot
An instance of a discord.py `Bot` object.
host : str
The hostname or IP ad... | 4.072563 | 4.040466 | 1.007944 |
node_ = node.get_node(channel.guild.id)
p = await node_.player_manager.create_player(channel)
return p | async def connect(channel: discord.VoiceChannel) | Connects to a discord voice channel.
This is the publicly exposed way to connect to a discord voice channel.
The :py:func:`initialize` function must be called first!
Parameters
----------
channel
Returns
-------
Player
The created Player object.
Raises
------
Inde... | 7.778236 | 9.826791 | 0.791534 |
if not asyncio.iscoroutinefunction(coro):
raise TypeError("Function is not a coroutine.")
if coro not in _event_listeners:
_event_listeners.append(coro) | def register_event_listener(coro) | Registers a coroutine to receive lavalink event information.
This coroutine will accept three arguments: :py:class:`Player`,
:py:class:`LavalinkEvents`, and possibly an extra. The value of the extra depends
on the value of the second argument.
If the second argument is :py:attr:`LavalinkEvents.TRACK_E... | 2.804415 | 4.376673 | 0.640764 |
if not asyncio.iscoroutinefunction(coro):
raise TypeError("Function is not a coroutine.")
if coro not in _update_listeners:
_update_listeners.append(coro) | def register_update_listener(coro) | Registers a coroutine to receive lavalink player update information.
This coroutine will accept a two arguments: an instance of :py:class:`Player`
and an instance of :py:class:`PlayerState`.
Parameters
----------
coro
Raises
------
TypeError
If ``coro`` is not a coroutine. | 2.790328 | 3.945185 | 0.707274 |
if not asyncio.iscoroutinefunction(coro):
raise TypeError("Function is not a coroutine.")
if coro not in _stats_listeners:
_stats_listeners.append(coro) | def register_stats_listener(coro) | Registers a coroutine to receive lavalink server stats information.
This coroutine will accept a single argument which will be an instance
of :py:class:`Stats`.
Parameters
----------
coro
Raises
------
TypeError
If ``coro`` is not a coroutine. | 2.751209 | 3.995045 | 0.688655 |
self._tool = None
self._painter = None
self.relieve_model(self._selection)
self._selection = None
# clear observer class attributes, also see ExtendenController.destroy()
self._Observer__PROP_TO_METHS.clear()
self._Observer__METH_TO_PROPS.clear()
... | def prepare_destruction(self) | Get rid of circular references | 8.265122 | 7.578549 | 1.090594 |
# Method had to be inherited, as the base method has a bug:
# It misses the statement max_dist = d
v2i = self.get_matrix_v2i
vx, vy = vpos
max_dist = distance
port = None
glue_pos = None
item = None
rect = (vx - distance, vy - distance, ... | def get_port_at_point(self, vpos, distance=10, exclude=None, exclude_port_fun=None) | Find item with port closest to specified position.
List of items to be ignored can be specified with `exclude`
parameter.
Tuple is returned
- found item
- closest, connectable port
- closest point on found port (in view coordinates)
:Parameters:
vpos
... | 4.902061 | 4.786205 | 1.024206 |
items = self._qtree.find_intersect((pos[0], pos[1], 1, 1))
for item in self._canvas.sort(items, reverse=True):
if not selected and item in self.selected_items:
continue # skip selected items
if item in exclude:
continue
v2i =... | def get_item_at_point_exclude(self, pos, selected=True, exclude=None) | Return the topmost item located at ``pos`` (x, y).
Parameters:
- selected: if False returns first non-selected item
- exclude: if specified don't check for these items | 4.976125 | 5.594161 | 0.889521 |
gaphas_items = []
for item in items:
if isinstance(item, Element):
gaphas_items.append(item)
else:
try:
gaphas_items.append(item.parent)
except AttributeError:
pass
super(Exte... | def queue_draw_item(self, *items) | Extends the base class method to allow Ports to be passed as item
:param items: Items that are to be redrawn | 3.838955 | 4.119693 | 0.931855 |
items = self._qtree.find_intersect((pos[0] - distance, pos[1] - distance, 2 * distance, 2 * distance))
filtered_items = []
for item in self._canvas.sort(items, reverse=True):
if not selected and item in self.selected_items:
continue # skip selected items
... | def get_items_at_point(self, pos, selected=True, distance=0) | Return the items located at ``pos`` (x, y).
:param bool selected: if False returns first non-selected item
:param float distance: Maximum distance to be considered as "at point" (in viewport pixel) | 3.562135 | 3.664108 | 0.97217 |
if not items:
return
elif not hasattr(items, "__iter__"):
items = (items,)
selection_changed = False
with self._suppress_selection_events():
for item in items:
self.queue_draw_item(item)
if item is not None and ... | def select_item(self, items) | Select an items. This adds `items` to the set of selected items. | 3.069423 | 2.844323 | 1.07914 |
self.queue_draw_item(item)
if item.model in self._selection:
with self._suppress_selection_events():
self._selection.remove(item.model)
self.emit('selection-changed', self._get_selected_items()) | def unselect_item(self, item) | Unselect an item. | 5.154698 | 4.935197 | 1.044477 |
items = self._get_selected_items()
with self._suppress_selection_events():
self._selection.clear()
self.queue_draw_item(*items)
self.emit('selection-changed', self._get_selected_items()) | def unselect_all(self) | Clearing the selected_item also clears the focused_item. | 5.324268 | 5.085895 | 1.04687 |
return set(self.canvas.get_view_for_model(model) for model in self._selection) | def _get_selected_items(self) | Return an Item (e.g. StateView) for each model (e.g. StateModel) in the current selection | 15.388551 | 7.198242 | 2.137821 |
if items is None:
items = ()
elif not hasattr(items, "__iter__"):
items = (items,)
models = set(item.model for item in items)
self._selection.handle_new_selection(models) | def handle_new_selection(self, items) | Determines the selection
The selection is based on the previous selection, the currently pressed keys and the passes newly selected items
:param items: The newly selected item(s) | 3.523543 | 4.651376 | 0.757527 |
focused_model = self._selection.focus
if not focused_model:
return None
return self.canvas.get_view_for_model(focused_model) | def _get_focused_item(self) | Returns the currently focused item | 7.465989 | 6.84926 | 1.090043 |
if not item:
return self._del_focused_item()
if item.model is not self._selection.focus:
self.queue_draw_item(self._focused_item, item)
self._selection.focus = item.model
self.emit('focus-changed', item) | def _set_focused_item(self, item) | Sets the focus to the passed item | 5.236814 | 5.189744 | 1.00907 |
previous = {}
next_ = {}
concurrent = {}
grouped_by_run_id = {}
start_item = None
for k,v in execution_history_items.items():
if v['item_type'] == 'StateMachineStartItem':
start_item = v
else:
# connect the item to its predecessor
prev_it... | def log_to_raw_structure(execution_history_items) | :param dict execution_history_items: history items, in the simplest case
directly the opened shelve log file
:return: start_item, the StateMachineStartItem of the log file
previous, a dict mapping history_item_id --> history_item_id of previous history item
next_, a dict mapping... | 4.161215 | 3.402051 | 1.223149 |
try:
import pandas as pd
except ImportError:
raise ImportError("The Python package 'pandas' is required for log_to_DataFrame.")
start, next_, concurrency, hierarchy, gitems = log_to_collapsed_structure(
execution_history_items, throw_on_pickle_error=throw_on_pickle_error)
g... | def log_to_DataFrame(execution_history_items, data_in_columns=[], data_out_columns=[], scoped_in_columns=[],
scoped_out_columns=[], semantic_data_columns=[], throw_on_pickle_error=True) | Returns all collapsed items in a table-like structure (pandas.DataFrame) with one row per executed
state and a set of properties resp. columns (e.g. state_name, outcome, run_id) for this state.
The data flow (data_in/out, scoped_data_in/out, semantic_data) is omitted from this table
representation by defau... | 2.514972 | 2.404979 | 1.045736 |
import matplotlib.pyplot as plt
import matplotlib.dates as dates
import numpy as np
d = log_to_DataFrame(execution_history_items)
# de-duplicate states and make mapping from state to idx
unique_states, idx = np.unique(d.path_by_name, return_index=True)
ordered_unique_states = np.array... | def log_to_ganttplot(execution_history_items) | Example how to use the DataFrame representation | 3.64608 | 3.576683 | 1.019402 |
from future.utils import raise_
from threading import Condition
import sys
from rafcon.utils import log
global exception_info, result
from gi.repository import GLib
condition = Condition()
exception_info = None
@log.log_exceptions()
def fun():
global except... | def call_gui_callback(callback, *args, **kwargs) | Wrapper method for GLib.idle_add
This method is intended as replacement for idle_add. It wraps the method with a callback option. The advantage is
that this way, the call is blocking. The method return, when the callback method has been called and executed.
:param callback: The callback method, e.g. on_op... | 4.527769 | 4.550701 | 0.994961 |
tooltip_event_box = Gtk.EventBox()
tooltip_event_box.set_tooltip_text(tab_name)
tab_label = Gtk.Label()
if global_gui_config.get_config_value('USE_ICONS_AS_TAB_LABELS', True):
tab_label.set_markup('<span font_desc="%s %s">&#x%s;</span>' %
(constants.ICON_FONT,
... | def create_tab_header_label(tab_name, icons) | Create the tab header labels for notebook tabs. If USE_ICONS_AS_TAB_LABELS is set to True in the gui_config,
icons are used as headers. Otherwise, the titles of the tabs are rotated by 90 degrees.
:param tab_name: The label text of the tab, written in small letters and separated by underscores, e.g. states_tre... | 2.906571 | 2.63732 | 1.102093 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.