output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
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 t... | Can you write a function in Python 3 where it
checks whether a point p is within the given triangle | As a Python code translator, you convert algorithms and pseudocode into Python. |
Compare two iterators and their elements on specific digit precision
| Given the following Python 3 function, write the documentation
def equal(t1, t2, digit=None):
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:
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Calculates the Euclidean distance between two boxes that are parallel to the coordinate axis. | Can you generate a brief explanation for the following Python 3 code
def cal_dist_between_2_coord_frame_aligned_boxes(box1_pos, box1_size, box2_pos, box2_size):
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_p... | You are a Python code architect, reviewing and designing scalable and efficient code |
def mouse_click(self, widget, event=None):
"""Triggered when mouse click is pressed in the history tree. The method shows all scoped data for an execution
step as tooltip or fold and unfold the tree by double-click and select respective state for double clicked
element.
"""
if ev... | How would you implement a function in Python 3 that
triggers when mouse click is pressed in the history tree. | As a Python code analyst, you investigate and solve complex coding mysteries |
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:
... | Can you write a function in Python 3 where it
hands history item for tree iter and compensate if tree item is a dummy item | You are a Python code analyst, evaluating scripts for potential improvements. |
Iterate recursively all tree items and store expansion state | Can you tell what is the following Python 3 function doing
def _store_expansion_state(self):
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... | You are a Python code architect, reviewing and designing scalable and efficient code |
Iterate recursively all tree items and restore expansion state | Explain what the following Python 3 code does
def _restore_expansion_state(self):
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)
... | As a python code expert, you are capable of creating scripts from specifications. |
If a new state machine is selected make sure expansion state is stored and tree updated | Explain what the following Python 3 code does
def notification_selected_sm_changed(self, model, prop_name, info):
selected_state_machine_id = self.model.selected_state_machine_id
if selected_state_machine_id is None:
return
self.update() | As a Python code analyst, you investigate and solve complex coding mysteries |
Remove references to non - existing state machines | Given the following Python 3 function, write the documentation
def notification_sm_changed(self, model, prop_name, info):
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] | You are a Python code generator, capable of creating scripts from specifications. |
Arranges to put execution - history widget page to become top page in notebook when execution starts and stops and resets modification_history_was_focused to False each time this notification are observed. | How would you explain what the following Python 3 function does
def execution_history_focus(self, model, prop_name, info):
if state_machine_execution_engine.status.execution_mode in \
[StateMachineExecutionStatus.STARTED, StateMachineExecutionStatus.STOPPED,
StateMachineExecutio... | As a python code expert, you are capable of creating scripts from specifications. |
Triggered when the Clean History button is clicked. | How would you explain what the following Python 3 function does
def clean_history(self, widget, event=None):
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... | As a python code expert, you are capable of creating scripts from specifications. |
def update(self):
"""
rebuild the tree view of the history item tree store
:return:
"""
# with self._update_lock:
self._update_lock.acquire()
self._store_expansion_state()
self.history_tree_store.clear()
selected_sm_m = self.model.get_selected_stat... | Write a Python 3 script to
rebuild the tree view of the history item tree store | As a Python code analyst, you investigate and solve complex coding mysteries |
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 ... | Can you implement a function in Python 3 that
inserts a single history item into the tree store. | As a Python code translator, you convert algorithms and pseudocode into Python. |
This method inserts a list of execution history items into a tree store. | Can you generate the documentation for the following Python 3 function
def insert_execution_history(self, parent, execution_history, is_root=False):
current_parent = parent
execution_history_iterator = iter(execution_history)
for history_item in execution_history_iterator:
if isinsta... | As a Python code analyst, you investigate and solve complex coding mysteries |
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 a... | Can you write a function in Python 3 where it
adds the child execution histories of a concurrency state. | You are a Python code analyst, evaluating scripts for potential improvements. |
dragged state is inserted and its state_id sent to the receiver | Can you generate the documentation for the following Python 3 function
def on_drag_data_get(self, widget, context, data, info, time):
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_... | You are a Python code architect, reviewing and designing scalable and efficient code |
def select_open_state_machine_of_selected_library_element(self):
"""Select respective state machine of selected library in state machine manager if already open """
(model, row_path) = self.view.get_selection().get_selected()
if row_path:
physical_library_path = model[row_path][self.... | How would you code a function in Python 3 to
select respective state machine of selected library in state machine manager if already open | As a Python code translator, you convert algorithms and pseudocode into Python. |
def menu_item_remove_libraries_or_root_clicked(self, menu_item):
"""Removes library from hard drive after request second confirmation"""
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_sele... | Create a Python 3 function for
removing libraries from hard drive after second confirmation | As a Python code translator, you convert algorithms and pseudocode into Python. |
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 """
(model, row) = self.view.get_selection().get_selected()
tree_item_key = model[row][self.ID_STORAGE_ID]
library_item = mode... | Implement a function in Python 3 to
extract properties library_os_path library_path library_name and tree_item_key from selected row | You are a Python code architect, reviewing and designing scalable and efficient code |
Returns the LibraryState which was selected in the LibraryTree
| Can you generate the documentation for the following Python 3 function
def _get_selected_library_state(self):
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 s... | As a Python code composer, you craft elegant and concise scripts. |
Starts the execution of the state in a new thread. | Here you have a function in Python 3, explain what it does
def start(self, execution_history, backward_execution=False, generate_run_id=True):
self.execution_history = execution_history
if generate_run_id:
self._run_id = run_id_generator()
self.backward_execution = copy.copy(backward... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Waits until the state finished execution. | Make a summary of the following Python 3 code
def join(self):
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)) | As a Python code analyst, you investigate and solve complex coding mysteries |
Sets up the state execution status and preempted state | How would you explain what the following Python 3 function does
def setup_run(self):
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... | You are a Python code architect, reviewing and designing scalable and efficient code |
def recursively_preempt_states(self):
"""Preempt the state
"""
self.preempted = True
self.paused = False
self.started = False | Can you implement a function in Python 3 that
preempts the state of the current object. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns the default input values for a state | How would you explain what the following Python 3 function does
def get_default_input_values_for_state(self, state):
from rafcon.core.states.library_state import LibraryState
result_dict = {}
for input_port_key, value in state.input_data_ports.items():
if isinstance(state, LibrarySta... | As a Python code translator, you convert algorithms and pseudocode into Python. |
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
"""
from rafcon.core.states.library_state import LibraryState
result_d... | Write a Python 3 function for
creating a dictionary of output data for a state | You are a Python code generator, capable of creating scripts from specifications. |
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
... | Write a Python 3 function for
adding a new input data port to the state. | As a Python code analyst, you investigate and solve complex coding mysteries |
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.Att... | Write a Python 3 function that can
remove an input data port from the state. | You are a Python code architect, reviewing and designing scalable and efficient code |
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
... | Create a Python 3 function to
remove all data flows whose from_key or to_key equals the passed data_port_id. | As a Python code translator, you convert algorithms and pseudocode into Python. |
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
... | Create a Python 3 function for
adding a new output data port to the state | You are a Python code generator, capable of creating scripts from specifications. |
Removes an output data port from the state. | Can you tell what is the following Python 3 function doing
def remove_output_data_port(self, data_port_id, force=False, destroy=True):
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[da... | You are a Python code generator, capable of creating scripts from specifications. |
Returns the data_port_id of a data port with a certain name and data port type | Make a summary of the following Python 3 code
def get_io_data_port_id_from_name_and_type(self, name, data_port_type):
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
... | You are a Python code analyst, evaluating scripts for potential improvements. |
This method searches for the given data port id in the input and output data ports of the state and returns the data port with the searched id or None if it is not found. | Make a summary of the following Python 3 code
def get_data_port_by_id(self, data_port_id):
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 ... | You are a Python code generator, capable of creating scripts from specifications. |
Recursively generates the path of the state. | How would you explain what the following Python 3 function does
def get_path(self, appendix=None, by_name=False):
if by_name:
state_identifier = self.name
else:
state_identifier = self.state_id
if not self.is_root_state:
if appendix is None:
r... | As a Python code composer, you craft elegant and concise scripts. |
Recursively creates the storage path of the state. | Here you have a function in Python 3, explain what it does
def get_storage_path(self, appendix=None):
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)
e... | You are a Python code generator, capable of creating scripts from specifications. |
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
"""
if self.parent:
if self.is_root_state:
return self.parent
else:
... | Can you create a Python 3 function that
gets a reference of the state_machine the state belongs to | As a Python code composer, you craft elegant and concise scripts. |
Add a new outcome to the state | Explain what the following Python 3 code does
def add_outcome(self, name, outcome_id=None):
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
... | As a Python code composer, you craft elegant and concise scripts. |
Removes the state element from the state store. | Can you generate the documentation for the following Python 3 function
def remove(self, state_element, recursive=True, force=False, destroy=True):
if isinstance(state_element, Income):
self.remove_income(force, destroy=destroy)
if isinstance(state_element, Outcome):
return self.r... | As a Python code composer, you craft elegant and concise scripts. |
Removes an outcome from the state. | Explain what the following Python 3 code does
def remove_outcome(self, outcome_id, force=False, destroy=True):
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:
... | As a Python code composer, you craft elegant and concise scripts. |
Checks validity of passed child object and returns a boolean indicating if the child is valid. | Explain what the following Python 3 code does
def check_child_validity(self, child):
# 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_... | As a Python code translator, you convert algorithms and pseudocode into Python. |
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 val... | How would you code a function in Python 3 to
check the validity of an outcome | You are a Python code analyst, evaluating scripts for potential improvements. |
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,... | Can you write a function in Python 3 where it
checks the validity of a data port | As a python code expert, you are capable of creating scripts from specifications. |
Checks the validity of a data port id | Can you tell what is the following Python 3 function doing
def _check_data_port_id(self, data_port):
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 por... | You are a Python code analyst, evaluating scripts for potential improvements. |
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.Dat... | Write a Python 3 script for
checking the validity of a data port name | You are a Python code generator, capable of creating scripts from specifications. |
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.
"""
for data_port in self.input_data_ports.values... | Write a Python 3 script to
check the input data types of the state and generates an error message if they are not of the specified type. | As a python code expert, you are capable of creating scripts from specifications. |
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.
"""
for data_port in self.output_data_ports.va... | Implement a Python 3 function for
checking the output data types of the state and generates an error if they are not of the specified type | As a Python code analyst, you investigate and solve complex coding mysteries |
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:
"""
if state_id is None:
state_id = state_id_... | Can you create a Python 3 function that
changes the id of the state to a new id. | You are a Python code analyst, evaluating scripts for potential improvements. |
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:
"""
target_dict = self.semantic_data
for path_element in path_as_list:
if path_eleme... | Can you create a Python 3 function that
retrieves an entry of the semantic data. | As a python code expert, you are capable of creating scripts from specifications. |
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:
"""
assert isinst... | How would you implement a function in Python 3 that
adds a semantic data entry. | As a Python code translator, you convert algorithms and pseudocode into Python. |
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
"""
if len(path_as_list) == 0:
raise AttributeError("The argument path_as_l... | How would you implement a function in Python 3 that
removes an entry from the semantic data vividict. | As a Python code analyst, you investigate and solve complex coding mysteries |
def destroy(self, recursive):
""" Removes all the state elements.
:param recursive: Flag wether to destroy all state elements which are removed
"""
for in_key in list(self.input_data_ports.keys()):
self.remove_input_data_port(in_key, force=True, destroy=recursive)
f... | Create a Python 3 function to
remove all the state elements. | As a Python code analyst, you investigate and solve complex coding mysteries |
Property for the _input_data_ports field | Can you generate the documentation for the following Python 3 function
def input_data_ports(self, input_data_ports):
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 ==... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Setters for _outcomes field
| Can you tell what is the following Python 3 function doing
def outcomes(self, outcomes):
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 Type... | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns True if the state is the root state of a library state and False otherwise | Here you have a function in Python 3, explain what it does
def is_root_state_of_library(self):
from rafcon.core.states.library_state import LibraryState
return isinstance(self.parent, LibraryState) | As a Python code analyst, you investigate and solve complex coding mysteries |
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.s... | Write a Python 3 script to
return the next upper library root state in the state_copy. | As a Python code analyst, you investigate and solve complex coding mysteries |
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.
"""
library_root_state = self.g... | How would you code a function in Python 3 to
find state_copy of uppermost LibraryState Method checks if there is a parent library root state and assigns it to the current library root state till there is no further parent library root state till there is no further parent library root state. | You are a Python code analyst, evaluating scripts for potential improvements. |
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
"""
# Set the final outcome of the state
if outcom... | Write a Python 3 function for
finalizing 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 | As a python code expert, you are capable of creating scripts from specifications. |
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.Mu... | Implement a Python 3 function for
constructing an undirected multigraph from a list containing data on weighted edges. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns a dict containing all the bus_ids of all network components in a given scenario. | Here you have a function in Python 3, explain what it does
def busmap_from_psql(network, session, scn_name):
def fetch():
query = session.query(EgoGridPfHvBusmap.bus0, EgoGridPfHvBusmap.bus1).\
filter(EgoGridPfHvBusmap.scn_name == scn_name)
return dict(query.all())
busmap = fetch... | You are a Python code analyst, evaluating scripts for potential improvements. |
K - mean clustering algorithm. | Explain what the following Python 3 code does
def kmean_clustering(network, n_clusters=10, load_cluster=False,
line_length_factor=1.25,
remove_stubs=False, use_reduced_coordinates=False,
bus_weight_tocsv=None, bus_weight_fromcsv=None,
n... | You are a Python code analyst, evaluating scripts for potential improvements. |
Register callback methods for triggered actions
| Here you have a function in Python 3, explain what it does
def register_actions(self, shortcut_manager):
super(DescriptionEditorController, self).register_actions(shortcut_manager)
shortcut_manager.add_callback_for_action("abort", self._abort) | You are a Python code architect, reviewing and designing scalable and efficient code |
Called when the View was registered | Here you have a function in Python 3, explain what it does
def register_view(self, view):
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._mo... | You are a Python code analyst, evaluating scripts for potential improvements. |
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.
"""
shortcut_manager.add_callback_for... | Can you implement a function in Python 3 that
registers callback methods for triggered actions. | As a Python code analyst, you investigate and solve complex coding mysteries |
Handles the drag data received from the LibraryTree and moves the state to the position of the mouse. | Can you tell what is the following Python 3 function doing
def on_drag_data_received(self, widget, context, x, y, data, info, time):
state_id_insert = data.get_text()
parent_m = self.model.selection.get_selected_state()
if not isinstance(parent_m, ContainerStateModel):
return
... | You are a Python code analyst, evaluating scripts for potential improvements. |
Changes the selection on mouse over during drag motion | How would you explain what the following Python 3 function does
def on_drag_motion(self, widget, context, x, y, time):
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 No... | You are a Python code architect, reviewing and designing scalable and efficient code |
Triggered when the add new state is clicked. | Given the following Python 3 function, write the documentation
def _add_new_state(self, *event, **kwargs):
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_n... | You are a Python code generator, capable of creating scripts from specifications. |
Copies the current selection to the clipboard. | Can you generate a brief explanation for the following Python 3 code
def _copy_selection(self, *event):
if react_to_event(self.view, self.view.editor, event):
logger.debug("copy selection")
global_clipboard.copy(self.model.selection)
return True | You are a Python code generator, capable of creating scripts from specifications. |
def _cut_selection(self, *event):
"""Cuts the current selection and copys it to the clipboard.
"""
if react_to_event(self.view, self.view.editor, event):
logger.debug("cut selection")
global_clipboard.cut(self.model.selection)
return True | Write a Python 3 function that can
cut the current selection and copies it to the clipboard. | As a Python code analyst, you investigate and solve complex coding mysteries |
Paste the current clipboard into the current selection if the current selection is a container state. | Can you generate a brief explanation for the following Python 3 code
def _paste_clipboard(self, *event):
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 | You are a Python code analyst, evaluating scripts for potential improvements. |
Called when an item is focused moves the item into the viewport | Can you generate a brief explanation for the following Python 3 code
def _move_focused_item_into_viewport(self, view, focused_item):
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... | You are a Python code analyst, evaluating scripts for potential improvements. |
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 Sta... | Write a Python 3 function for
moving the item into the viewport. | You are a Python code generator, capable of creating scripts from specifications. |
def state_machine_destruction(self, model, prop_name, info):
""" Clean up when state machine is being destructed """
if self.model is model: # only used for the state machine destruction case
self.canvas.get_view_for_model(self.root_state_m).remove() | Write a Python 3 script for
cleaning up when state machine is being destructed | You are a Python code generator, capable of creating scripts from specifications. |
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 t... | Can you implement a function in Python 3 that
handles the meta data of the affected state | As a Python code translator, you convert algorithms and pseudocode into Python. |
Called when any state machine changes within the state machine | Can you generate a brief explanation for the following Python 3 code
def state_machine_change_after(self, model, prop_name, info):
if 'method_name' in info and info['method_name'] == 'root_state_change':
method_name, model, result, arguments, instance = self._extract_info_data(info['kwargs'])
... | You are a Python code generator, capable of creating scripts from specifications. |
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
... | Create a Python 3 function for
focusing a state view of respective state model | As a Python code composer, you craft elegant and concise scripts. |
Adds a new state view for the given state model. | Given the following Python 3 function, write the documentation
def add_state_view_for_model(self, state_m, parent_v=None, rel_pos=(0, 0), size=(100, 100), hierarchy_level=1):
assert isinstance(state_m, AbstractStateModel)
state_meta = state_m.get_meta_data_editor()
# Use default values if no si... | You are a Python code analyst, evaluating scripts for potential improvements. |
Creates a TransitionView from the given transition_m and adds it to the canvas. | How would you explain what the following Python 3 function does
def add_transition_view_for_model(self, transition_m, parent_state_m):
parent_state_v = self.canvas.get_view_for_model(parent_state_m)
hierarchy_level = parent_state_v.hierarchy_level
transition_v = TransitionView(transition_m, hie... | As a Python code composer, you craft elegant and concise scripts. |
Adds a data flow view to the canvas | Here you have a function in Python 3, explain what it does
def add_data_flow_view_for_model(self, data_flow_m, parent_state_m):
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_leve... | You are a Python code analyst, evaluating scripts for potential improvements. |
Checks whether the given event should be handled by the state machine manager | Can you generate the documentation for the following Python 3 function
def react_to_event(self, event):
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.st... | As a python code expert, you are capable of creating scripts from specifications. |
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
... | Write a Python 3 function that can
initialize the Lavalink node. | You are a Python code generator, capable of creating scripts from specifications. |
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
... | Create a Python 3 function for
connecting to a discord voice channel. | You are a Python code analyst, evaluating scripts for potential improvements. |
Registers a coroutine function that will receive lavalink event information. | Here you have a function in Python 3, explain what it does
def register_event_listener(coro):
if not asyncio.iscoroutinefunction(coro):
raise TypeError("Function is not a coroutine.")
if coro not in _event_listeners:
_event_listeners.append(coro) | As a Python code analyst, you investigate and solve complex coding mysteries |
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
------
TypeE... | Write a Python 3 function that can
register a coroutine to receive lavalink player update information. | You are a Python code generator, capable of creating scripts from specifications. |
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... | Create a Python 3 function to
register a coroutine to receive lavalink server stats information. | You are a Python code generator, capable of creating scripts from specifications. |
def prepare_destruction(self):
"""Get rid of circular references"""
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_M... | Implement a function in Python 3 to
remove all references to the current model and the current selection and clear the attribute cache. | You are a Python code analyst, evaluating scripts for potential improvements. |
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, connecta... | Can you implement a function in Python 3 that
finds 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 Position specified in ... | You are a Python code generator, capable of creating scripts from specifications. |
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
"""
items = self._... | Can you implement a function in Python 3 that
returns the item at the given position. | As a Python code analyst, you investigate and solve complex coding mysteries |
Extends the base class method to allow Ports to be passed as item
| Given the following Python 3 function, write the documentation
def queue_draw_item(self, *items):
gaphas_items = []
for item in items:
if isinstance(item, Element):
gaphas_items.append(item)
else:
try:
gaphas_items.append(item.p... | You are a Python code architect, reviewing and designing scalable and efficient code |
Return the items located at the given point. | Can you tell what is the following Python 3 function doing
def get_items_at_point(self, pos, selected=True, distance=0):
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):
... | As a python code expert, you are capable of creating scripts from specifications. |
def select_item(self, items):
""" Select an items. This adds `items` to the set of selected items. """
if not items:
return
elif not hasattr(items, "__iter__"):
items = (items,)
selection_changed = False
with self._suppress_selection_events():
... | Write a Python 3 function that can
select an item. This adds items to the set of selected items. | As a Python code composer, you craft elegant and concise scripts. |
def unselect_all(self):
""" Clearing the selected_item also clears the focused_item. """
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_i... | Create a Python 3 function to
clear the selected_item also clears the focused_item. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _get_selected_items(self):
""" Return an Item (e.g. StateView) for each model (e.g. StateModel) in the current selection """
return set(self.canvas.get_view_for_model(model) for model in self._selection) | Write a Python 3 function for
returning a set of items for each model in the current selection | You are a Python code analyst, evaluating scripts for potential improvements. |
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)
"""
if items is None:
items = ()
eli... | Create a Python 3 function to
determine 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) | You are a Python code architect, reviewing and designing scalable and efficient code |
Returns the currently focused item | Given the following Python 3 function, write the documentation
def _get_focused_item(self):
focused_model = self._selection.focus
if not focused_model:
return None
return self.canvas.get_view_for_model(focused_model) | As a Python code analyst, you investigate and solve complex coding mysteries |
Sets the focus to the passed item | Here you have a function in Python 3, explain what it does
def _set_focused_item(self, item):
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
... | As a Python code analyst, you investigate and solve complex coding mysteries |
converts the history items in the simplest case
to the raw structure of the log file | Can you tell what is the following Python 3 function doing
def log_to_raw_structure(execution_history_items):
previous = {}
next_ = {}
concurrent = {}
grouped_by_run_id = {}
start_item = None
for k,v in execution_history_items.items():
if v['item_type'] == 'StateMachineStartItem':
... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def log_to_collapsed_structure(execution_history_items, throw_on_pickle_error=True,
include_erroneous_data_ports=False, full_next=False):
"""
Collapsed structure means that all history items belonging to the same state execution are
merged together into one object (e.g. CallIt... | Write a Python 3 function for
collapsing structure means that all history items belonging to the same state execution are merged together into one object (e.g. CallItem and ReturnItem of an ExecutionState). This is based on the log structure in which all Items which belong together have the same run_id. The collapsed i... | As a python code expert, you are capable of creating scripts from specifications. |
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
... | Can you create a Python 3 function that
returns a pandas. DataFrame containing all the data flow items in the execution history. | You are a Python code architect, reviewing and designing scalable and efficient code |
Example how to use the DataFrame representation
| How would you explain what the following Python 3 function does
def log_to_ganttplot(execution_history_items):
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
... | You are a Python code analyst, evaluating scripts for potential improvements. |
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 execut... | Implement a Python 3 function for
wrapping method for GLib. idle_add | You are a Python code analyst, evaluating scripts for potential improvements. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.