output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
def get_action_arguments(self, target_state_m): """ Collect argument attributes for action signal Use non empty list dict to create arguments for action signal msg and logger messages. The action parent model can be different then the target state model because logical and data port changes als...
Write a Python 3 function that can collect non empty list dict to create arguments for action signal and msg and logger messages
As a python code expert, you are capable of creating scripts from specifications.
def copy(self, selection, smart_selection_adaption=True): """ Copy all selected items to the clipboard using smart selection adaptation by default :param selection: the current selection :param bool smart_selection_adaption: flag to enable smart selection adaptation mode :return...
Create a Python 3 function to copy all selected items to the clipboard using smart selection adaptation by default
As a python code expert, you are capable of creating scripts from specifications.
Cuts all selected items and copy them to the clipboard using smart selection adaptation by default
Here you have a function in Python 3, explain what it does def cut(self, selection, smart_selection_adaption=False): assert isinstance(selection, Selection) import rafcon.gui.helpers.state_machine as gui_helper_state_machine if gui_helper_state_machine.is_selection_inside_of_library_state(sele...
You are a Python code analyst, evaluating scripts for potential improvements.
Paste objects to target state.
How would you explain what the following Python 3 function does def paste(self, target_state_m, cursor_position=None, limited=None, convert=False): self.reset_clipboard_mapping_dicts() if not isinstance(target_state_m, StateModel): logger.warning("Paste is not performed because target state ...
You are a Python code generator, capable of creating scripts from specifications.
def reset_clipboard(self): """ Resets the clipboard, so that old elements do not pollute the new selection that is copied into the clipboard. :return: """ # reset selections for state_element_attr in ContainerState.state_element_attrs: self.model_copies[s...
Can you create a Python 3 function that resets the clipboard so that old elements do not pollute the new selection that is copied into the the clipboard.
As a Python code analyst, you investigate and solve complex coding mysteries
def do_selection_reduction_to_one_parent(selection): """ Find and reduce selection to one parent state. :param selection: :return: state model which is parent of selection or None if root state """ all_models_selected = selection.get_all() # check if all elements select...
Write a Python 3 script for finding and reduce selection to one parent state.
As a Python code composer, you craft elegant and concise scripts.
def do_smart_selection_adaption(selection, parent_m): """ Reduce and extend transition and data flow element selection if already enclosed by selection The smart selection adaptation checks and ignores directly data flows and transitions which are selected without selected related origin or t...
Implement a Python 3 function for reducing and extend transition and data flow element selection if already enclosed by selection The smart selection adaptation checks and ignores directly data flows and transitions which are selected without selected related origin or targets elements. Additional the linkage (data flo...
As a python code expert, you are capable of creating scripts from specifications.
Create a dictionary of all models and model objects that are copied and the model objects of the selected elements.
Make a summary of the following Python 3 code def __create_core_and_model_object_copies(self, selection, smart_selection_adaption): all_models_selected = selection.get_all() if not all_models_selected: logger.warning("Nothing to copy because state machine selection is empty.") r...
As a Python code analyst, you investigate and solve complex coding mysteries
Method runs the prepare destruction method of all models in a dict.
Here you have a function in Python 3, explain what it does def destroy_all_models_in_dict(target_dict): if target_dict: for model_list in target_dict.values(): if isinstance(model_list, (list, tuple)): for model in model_list: model.prepare...
As a Python code analyst, you investigate and solve complex coding mysteries
Destroys the clipboard by relieving all model references.
Can you generate the documentation for the following Python 3 function def destroy(self): self.destroy_all_models_in_dict(self.model_copies) self.model_copies = None self.copy_parent_state_id = None self.outcome_id_mapping_dict = None self.port_id_mapping_dict = None self...
You are a Python code analyst, evaluating scripts for potential improvements.
Extend a bounding box by a given factor
Explain what the following Python 3 code does def extend_extents(extents, factor=1.1): width = extents[2] - extents[0] height = extents[3] - extents[1] add_width = (factor - 1) * width add_height = (factor - 1) * height x1 = extents[0] - add_width / 2 x2 = extents[2] + add_width / 2 y1 = ext...
You are a Python code analyst, evaluating scripts for potential improvements.
This method calculates the relative position of the given item s handle to its parent.
Make a summary of the following Python 3 code def calc_rel_pos_to_parent(canvas, item, handle): from gaphas.item import NW if isinstance(item, ConnectionView): return item.canvas.get_matrix_i2i(item, item.parent).transform_point(*handle.pos) parent = canvas.get_parent(item) if parent: ...
You are a Python code analyst, evaluating scripts for potential improvements.
This method asserts that only one value of the provided list is True.
Here you have a function in Python 3, explain what it does def assert_exactly_one_true(bool_list): assert isinstance(bool_list, list) counter = 0 for item in bool_list: if item: counter += 1 return counter == 1
You are a Python code analyst, evaluating scripts for potential improvements.
Looks for and returns the PortView to the given handle in the provided state
Given the following Python 3 function, write the documentation def get_port_for_handle(handle, state): from rafcon.gui.mygaphas.items.state import StateView if isinstance(state, StateView): if state.income.handle == handle: return state.income else: for outcome in state.o...
You are a Python code architect, reviewing and designing scalable and efficient code
Checks the type of connection and creates a new connection if it is not already added
Here you have a function in Python 3, explain what it does def create_new_connection(from_port, to_port): from rafcon.gui.mygaphas.items.ports import ScopedVariablePortView, LogicPortView, DataPortView if isinstance(from_port, LogicPortView) and isinstance(to_port, LogicPortView): return add_transition...
You are a Python code architect, reviewing and designing scalable and efficient code
This method adds a data flow between two state models.
Here you have a function in Python 3, explain what it does def add_data_flow_to_state(from_port, to_port): from rafcon.gui.mygaphas.items.ports import InputPortView, OutputPortView, ScopedVariablePortView from rafcon.gui.models.container_state import ContainerStateModel from_state_v = from_port.parent ...
You are a Python code analyst, evaluating scripts for potential improvements.
This method adds a transition from one state to another.
Here you have a function in Python 3, explain what it does def add_transition_to_state(from_port, to_port): from rafcon.gui.mygaphas.items.ports import IncomeView, OutcomeView from_state_v = from_port.parent to_state_v = to_port.parent from_state_m = from_state_v.model to_state_m = to_state_v.mode...
As a Python code composer, you craft elegant and concise scripts.
This method returns all relative positions of waypoints in a transition_v.
Given the following Python 3 function, write the documentation def get_relative_positions_of_waypoints(transition_v): handles_list = transition_v.handles() rel_pos_list = [] for handle in handles_list: if handle in transition_v.end_handles(include_waypoints=True): continue rel_po...
You are a Python code architect, reviewing and designing scalable and efficient code
This method updates the meta data of the transition waypoints if they changed.
Explain what the following Python 3 code does def update_meta_data_for_transition_waypoints(graphical_editor_view, transition_v, last_waypoint_list, publish=True): from rafcon.gui.mygaphas.items.connection import TransitionView assert isinstance(transition_v, TransitionView) transition_m = transition_v.mo...
As a Python code translator, you convert algorithms and pseudocode into Python.
This method updates the meta data of a name view.
Can you tell what is the following Python 3 function doing def update_meta_data_for_name_view(graphical_editor_view, name_v, publish=True): from gaphas.item import NW rel_pos = calc_rel_pos_to_parent(graphical_editor_view.editor.canvas, name_v, name_v.handles()[NW]) state_v = graphical_editor_view.editor....
You are a Python code architect, reviewing and designing scalable and efficient code
This method updates the meta data of a state view. It updates all ports and transitions and child state views.
Given the following Python 3 function, write the documentation def update_meta_data_for_state_view(graphical_editor_view, state_v, affects_children=False, publish=True): from gaphas.item import NW # Update all port meta data to match with new position and size of parent update_meta_data_for_port(graphical_...
You are a Python code generator, capable of creating scripts from specifications.
def remove(self): """Remove recursively all children and then the StateView itself """ self.canvas.get_first_view().unselect_item(self) for child in self.canvas.get_children(self)[:]: child.remove() self.remove_income() for outcome_v in self.outcomes[:]: ...
How would you code a function in Python 3 to remove all children and then the StateView itself.
You are a Python code architect, reviewing and designing scalable and efficient code
Enable or disable the KeepRectangleWithinConstraint for all child states.
Can you generate a brief explanation for the following Python 3 code def set_enable_flag_keep_rect_within_constraints(self, enable): for child_state_v in self.child_state_views(): self.keep_rect_constraints[child_state_v].enable = enable child_state_v.keep_rect_constraints[child_state_v....
You are a Python code architect, reviewing and designing scalable and efficient code
def show_content(self, with_content=False): """Checks if the state is a library with the `show_content` flag set :param with_content: If this parameter is `True`, the method return only True if the library represents a ContainerState :return: Whether the content of a library state is ...
Write a Python 3 function for checking if the state is a library with the show_content flag set
You are a Python code architect, reviewing and designing scalable and efficient code
Calculate the position of a port on a line.
Explain what the following Python 3 code does def _calculate_port_pos_on_line(self, port_num, side_length, port_width=None): if port_width is None: port_width = 2 * self.border_width border_size = self.border_width pos = 0.5 * border_size + port_num * port_width outermost_pos...
As a Python code composer, you craft elegant and concise scripts.
Writes a dictionary to a yaml file
Given the following Python 3 function, write the documentation def write_dict_to_yaml(dictionary, path, **kwargs): with open(path, 'w') as f: yaml.dump(dictionary, f, indent=4, **kwargs)
As a python code expert, you are capable of creating scripts from specifications.
Loads a dictionary from a yaml file
Here you have a function in Python 3, explain what it does def load_dict_from_yaml(path): f = file(path, 'r') dictionary = yaml.load(f) f.close() return dictionary
You are a Python code generator, capable of creating scripts from specifications.
Writes a dictionary to a json file.
How would you explain what the following Python 3 function does def write_dict_to_json(dictionary, path, **kwargs): result_string = json.dumps(dictionary, cls=JSONObjectEncoder, indent=4, check_circular=False, sort_keys=True, **kwargs) with open(path, 'w') as f: # We canno...
As a Python code translator, you convert algorithms and pseudocode into Python.
Loads a dictionary from a json file.
Can you generate a brief explanation for the following Python 3 code def load_objects_from_json(path, as_dict=False): f = open(path, 'r') if as_dict: result = json.load(f) else: result = json.load(f, cls=JSONObjectDecoder, substitute_modules=substitute_modules) f.close() return resul...
You are a Python code generator, capable of creating scripts from specifications.
Solve the child for a specific variable.
Given the following Python 3 function, write the documentation def solve_for(self, var=None): if not self.enable: return margin = self.margin_method() def parent_width(): return self.parent_se[0].value - self.parent_nw[0].value def parent_height(): ...
You are a Python code architect, reviewing and designing scalable and efficient code
Solve for the child of the log entry.
Given the following Python 3 function, write the documentation def solve_for(self, var=None): margin = self.margin_method() if self.parent_nw[0].value > self.child[0].value - margin: _update(self.child[0], self.parent_nw[0].value + margin) # Right edge (east) if self.parent_s...
You are a Python code architect, reviewing and designing scalable and efficient code
def update_port_side(self): """Updates the initial position of the port The port side is ignored but calculated from the port position. Then the port position is limited to the four side lines of the state. """ from rafcon.utils.geometry import point_left_of_line p = (s...
How would you code a function in Python 3 to update the initial position of the port.
You are a Python code generator, capable of creating scripts from specifications.
def _solve(self): """ Calculates the correct position of the port and keeps it aligned with the binding rect """ # As the size of the containing state may has changed we need to update the distance to the border self.update_distance_to_border() px, py = self._point ...
Write a Python 3 function for solving the port movement and keep it aligned with the binding rect.
As a Python code translator, you convert algorithms and pseudocode into Python.
def limit_pos(p, se_pos, nw_pos): """ Limits position p to stay inside containing state :param p: Position to limit :param se_pos: Bottom/Right boundary :param nw_pos: Top/Left boundary :return: """ if p > se_pos: _update(p, se_pos) eli...
How would you implement a function in Python 3 that limits the position p to stay inside containing state
As a Python code translator, you convert algorithms and pseudocode into Python.
Calculates the positions to limit the port movement to
Can you tell what is the following Python 3 function doing def get_adjusted_border_positions(self): nw_x, nw_y = self._rect[0] se_x, se_y = self._rect[1] nw_x += self._distance_to_border nw_y += self._distance_to_border se_x -= self._distance_to_border se_y -= self._dist...
You are a Python code architect, reviewing and designing scalable and efficient code
def set_nearest_border(self): """Snaps the port to the correct side upon state size change """ px, py = self._point nw_x, nw_y, se_x, se_y = self.get_adjusted_border_positions() if self._port.side == SnappedSide.RIGHT: _update(px, se_x) elif self._port.side =...
Create a Python 3 function to snap the port to the correct side upon state size change
You are a Python code architect, reviewing and designing scalable and efficient code
Removes obsolete state machine folders
Can you tell what is the following Python 3 function doing def remove_obsolete_folders(states, path): elements_in_folder = os.listdir(path) # find all state folder elements in system path state_folders_in_file_system = [] for folder_name in elements_in_folder: if os.path.exists(os.path.join(path...
As a Python code analyst, you investigate and solve complex coding mysteries
Checks if the base path includes deprecated characters and returns corrected version
Can you tell what is the following Python 3 function doing def clean_path_from_deprecated_naming(base_path): def warning_logger_message(insert_string): not_allowed_characters = "'" + "', '".join(REPLACED_CHARACTERS_FOR_NO_OS_LIMITATION.keys()) + "'" logger.warning("Deprecated {2} in {0}. Please avoi...
As a Python code composer, you craft elegant and concise scripts.
This function cleans a file system path in terms of removing all not allowed characters of each path element.
Given the following Python 3 function, write the documentation def clean_path(base_path): path_elements = base_path.split(os.path.sep) reduced_path_elements = [clean_path_element(elem, max_length=255) for elem in path_elements] if not all(path_elements[i] == elem for i, elem in enumerate(reduced_path_elemen...
As a Python code analyst, you investigate and solve complex coding mysteries
Saves a state machine to a file system.
Here you have a function in Python 3, explain what it does def save_state_machine_to_path(state_machine, base_path, delete_old_state_machine=False, as_copy=False): # warns the user in the logger when using deprecated names clean_path_from_deprecated_naming(base_path) state_machine.acquire_modification_lock...
As a Python code composer, you craft elegant and concise scripts.
Saves the script file for a state and the source path.
Here you have a function in Python 3, explain what it does def save_script_file_for_state_and_source_path(state, state_path_full, as_copy=False): from rafcon.core.states.execution_state import ExecutionState if isinstance(state, ExecutionState): source_script_file = os.path.join(state.script.path, state...
You are a Python code architect, reviewing and designing scalable and efficient code
def save_semantic_data_for_state(state, state_path_full): """Saves the semantic data in a separate json file. :param state: The state of which the script file should be saved :param str state_path_full: The path to the file system storage location of the state """ destination_script_file = os.path...
Create a Python 3 function to save the semantic data for the state to a separate json file.
As a python code expert, you are capable of creating scripts from specifications.
Recursively saves a state to a json file
Can you tell what is the following Python 3 function doing def save_state_recursively(state, base_path, parent_path, as_copy=False): from rafcon.core.states.execution_state import ExecutionState from rafcon.core.states.container_state import ContainerState state_path = os.path.join(parent_path, get_storage...
As a Python code analyst, you investigate and solve complex coding mysteries
Loads a state machine from the given path.
Can you tell what is the following Python 3 function doing def load_state_machine_from_path(base_path, state_machine_id=None): logger.debug("Loading state machine from path {0}...".format(base_path)) state_machine_file_path = os.path.join(base_path, STATEMACHINE_FILE) state_machine_file_path_old = os.path....
You are a Python code generator, capable of creating scripts from specifications.
Recursively loads the state of a state machine.
Can you generate a brief explanation for the following Python 3 code def load_state_recursively(parent, state_path=None, dirty_states=[]): from rafcon.core.states.execution_state import ExecutionState from rafcon.core.states.container_state import ContainerState from rafcon.core.states.hierarchy_state impor...
As a python code expert, you are capable of creating scripts from specifications.
Loads the content of a file by using json. load.
Can you generate the documentation for the following Python 3 function def load_data_file(path_of_file): if os.path.exists(path_of_file): return storage_utils.load_objects_from_json(path_of_file) raise ValueError("Data file not found: {0}".format(path_of_file))
As a Python code analyst, you investigate and solve complex coding mysteries
Limit the length of a string to a maximum length.
Can you generate the documentation for the following Python 3 function def limit_text_max_length(text, max_length, separator='_'): if max_length is not None: if isinstance(text, string_types) and len(text) > max_length: max_length = int(max_length) half_length = float(max_length - 1)...
As a Python code translator, you convert algorithms and pseudocode into Python.
Replace characters that conflict with a free OS choice when in a file system path.
Make a summary of the following Python 3 code def clean_path_element(text, max_length=None, separator='_'): elements_to_replace = REPLACED_CHARACTERS_FOR_NO_OS_LIMITATION for elem, replace_with in elements_to_replace.items(): text = text.replace(elem, replace_with) if max_length is not None: ...
You are a Python code architect, reviewing and designing scalable and efficient code
def limit_text_to_be_path_element(text, max_length=None, separator='_'): """ Replace characters that are not in the valid character set of RAFCON. :param text: the string to be cleaned :param max_length: the maximum length of the output string :param separator: the separator used for rafcon.core.storag...
How would you code a function in Python 3 to limit the text to be a path element.
As a Python code translator, you convert algorithms and pseudocode into Python.
Calculates the storage id for a state
Can you generate the documentation for the following Python 3 function def get_storage_id_for_state(state): if global_config.get_config_value('STORAGE_PATH_WITH_STATE_NAME'): max_length = global_config.get_config_value('MAX_LENGTH_FOR_STATE_NAME_IN_STORAGE_PATH') max_length_of_state_name_in_folder_...
You are a Python code analyst, evaluating scripts for potential improvements.
Updates the right bar pane position if needed
Can you generate a brief explanation for the following Python 3 code def pane_position_check(self): text_buffer = self.get_buffer() # not needed if the right side bar is un-docked from rafcon.gui.singleton import main_window_controller if main_window_controller is None or main_window_c...
You are a Python code generator, capable of creating scripts from specifications.
Adds a new call - history - item to the list of items that can be executed by the state machine.
Explain what the following Python 3 code does def push_call_history_item(self, state, call_type, state_for_scoped_data, input_data=None): last_history_item = self.get_last_history_item() from rafcon.core.states.library_state import LibraryState # delayed imported on purpose if isinstance(state_...
As a python code expert, you are capable of creating scripts from specifications.
Adds a new return - history - item to the list of return - history items
Given the following Python 3 function, write the documentation def push_return_history_item(self, state, call_type, state_for_scoped_data, output_data=None): last_history_item = self.get_last_history_item() from rafcon.core.states.library_state import LibraryState # delayed imported on purpose ...
As a python code expert, you are capable of creating scripts from specifications.
Adds a new concurrency - history - item to the list of concurrency - history items that are currently in the execution history.
Can you generate the documentation for the following Python 3 function def push_concurrency_history_item(self, state, number_concurrent_threads): last_history_item = self.get_last_history_item() return_item = ConcurrencyItem(state, self.get_last_history_item(), numb...
You are a Python code analyst, evaluating scripts for potential improvements.
Updates an existing hash object with another Hashable list set tuple dict or stringifyable object.
Given the following Python 3 function, write the documentation def update_hash_from_dict(obj_hash, object_): if isinstance(object_, Hashable): object_.update_hash(obj_hash) elif isinstance(object_, (list, set, tuple)): if isinstance(object_, set): # A set is not ordered ...
As a Python code translator, you convert algorithms and pseudocode into Python.
def mutable_hash(self, obj_hash=None): """Creates a hash with the (im)mutable data fields of the object Example: >>> my_obj = type("MyDerivedClass", (Hashable,), { "update_hash": lambda self, h: h.update("RAFCON") })() >>> my_obj_hash = my_obj.mutable_hash() >>> prin...
Implement a function in Python 3 to create a hash with the immutable data fields of the object
As a Python code translator, you convert algorithms and pseudocode into Python.
Logs a new record to all logging views.
Explain what the following Python 3 code does def emit(self, record): try: # Shorten the source name of the record (remove rafcon.) if sys.version_info >= (2, 7): record.__setattr__("name", record.name.replace("rafcon.", "")) msg = self.format(record) ...
As a Python code translator, you convert algorithms and pseudocode into Python.
def get_meta_data_editor(self, for_gaphas=True): """Returns the editor for the specified editor This method should be used instead of accessing the meta data of an editor directly. It return the meta data of the editor available (with priority to the one specified by `for_gaphas`) and converts ...
Write a Python 3 function for returning the meta data editor for the specified editor.
As a Python code translator, you convert algorithms and pseudocode into Python.
Sets the meta data for a specific key of the desired editor.
Explain what the following Python 3 code does def set_meta_data_editor(self, key, meta_data, from_gaphas=True): self.do_convert_meta_data_if_no_data(from_gaphas) meta_gui = self.meta['gui'] meta_gui = meta_gui['editor_gaphas'] if from_gaphas else meta_gui['editor_opengl'] key_path = key...
You are a Python code architect, reviewing and designing scalable and efficient code
Creates a hash with the meta data of the model
Explain what the following Python 3 code does def meta_data_hash(self, obj_hash=None): if obj_hash is None: obj_hash = hashlib.sha256() self.update_meta_data_hash(obj_hash) return obj_hash
You are a Python code architect, reviewing and designing scalable and efficient code
def prepare_destruction(self): """Prepares the model for destruction """ self._Observer__PROP_TO_METHS.clear() self._Observer__METH_TO_PROPS.clear() self._Observer__PAT_TO_METHS.clear() self._Observer__METH_TO_PAT.clear() self._Observer__PAT_METH_TO_KWARGS.clear(...
Write a Python 3 function that can prepare the model for destruction.
As a python code expert, you are capable of creating scripts from specifications.
This class converts a Gdk. Color into its r g b parts and adds an alpha according to needs AppsApps.
Make a summary of the following Python 3 code def get_col_rgba(color, transparency=None, opacity=None): r, g, b = color.red, color.green, color.blue # Convert from 0-6535 to 0-1 r /= 65535. g /= 65535. b /= 65535. if transparency is not None or opacity is None: transparency = 0 if trans...
As a Python code composer, you craft elegant and concise scripts.
Calculate the side length of a resize handle
Make a summary of the following Python 3 code def get_side_length_of_resize_handle(view, item): from rafcon.gui.mygaphas.items.state import StateView, NameView if isinstance(item, StateView): return item.border_width * view.get_zoom_factor() / 1.5 elif isinstance(item, NameView): return item...
You are a Python code architect, reviewing and designing scalable and efficient code
def draw_connected_scoped_label(context, color, name_size, handle_pos, port_side, port_side_size, draw_connection_to_port=False): """Draw label of scoped variable This method draws the label of a scoped variable connected to a data port. This is represented by drawing a bigger ...
Can you create a Python 3 function that draws label of scoped variable This method draws the label of a scoped variable connected to a data port. This is represented by drawing a bigger label where the top part is filled and the bottom part isn't. :param context: Draw Context :param Gdk.Color color: Color to draw the l...
As a Python code translator, you convert algorithms and pseudocode into Python.
Draws a normal label indicating the port name.
Can you tell what is the following Python 3 function doing def draw_port_label(context, port, transparency, fill, label_position, show_additional_value=False, additional_value=None, only_extent_calculations=False): """Draws a normal label indicating the port name. :param context: Draw Conte...
As a Python code analyst, you investigate and solve complex coding mysteries
def draw_label_path(context, width, height, arrow_height, distance_to_port, port_offset): """Draws the path for an upright label :param context: The Cairo context :param float width: Width of the label :param float height: Height of the label :param float distance_to_port: Distance to the port rela...
Can you implement a function in Python 3 that draws the path for an upright label on the Cairo context.
As a Python code analyst, you investigate and solve complex coding mysteries
Prepares the model for destruction.
Can you generate the documentation for the following Python 3 function def prepare_destruction(self, recursive=True): self.destruction_signal.emit() try: self.unregister_observer(self) except KeyError: # Might happen if the observer was already unregistered pass ...
You are a Python code architect, reviewing and designing scalable and efficient code
Reloads the input data port models directly from the state copy
Given the following Python 3 function, write the documentation def _load_input_data_port_models(self): if not self.state_copy_initialized: return self.input_data_ports = [] for input_data_port_m in self.state_copy.input_data_ports: new_ip_m = deepcopy(input_data_port_m) ...
As a Python code analyst, you investigate and solve complex coding mysteries
def _load_output_data_port_models(self): """Reloads the output data port models directly from the the state""" if not self.state_copy_initialized: return self.output_data_ports = [] for output_data_port_m in self.state_copy.output_data_ports: new_op_m = deepcopy(o...
Write a Python 3 script for reloading the output data port models directly from the state copy
As a python code expert, you are capable of creating scripts from specifications.
def _load_income_model(self): """Reloads the income model directly from the state""" if not self.state_copy_initialized: return self.income = None income_m = deepcopy(self.state_copy.income) income_m.parent = self income_m.income = income_m.income self...
Can you implement a function in Python 3 that reloads the income model directly from the state copy
You are a Python code analyst, evaluating scripts for potential improvements.
def _load_outcome_models(self): """Reloads the outcome models directly from the state""" if not self.state_copy_initialized: return self.outcomes = [] for outcome_m in self.state_copy.outcomes: new_oc_m = deepcopy(outcome_m) new_oc_m.parent = self ...
Can you create a Python 3 function that reloads the outcome models directly from the state copy
As a Python code translator, you convert algorithms and pseudocode into Python.
def show_content(self): """Check if content of library is to be shown Content is shown, if the uppermost state's meta flag "show_content" is True and the library hierarchy depth (up to MAX_VISIBLE_LIBRARY_HIERARCHY level) is not to high. :return: Whether the content is ...
Implement a Python 3 function for checking if content of library is to be shown
You are a Python code generator, capable of creating scripts from specifications.
Prepares the model for destruction. Unregisters the model from observing itself.
How would you explain what the following Python 3 function does def prepare_destruction(self): if self.core_element is None: logger.verbose("Multiple calls of prepare destruction for {0}".format(self)) self.destruction_signal.emit() try: self.unregister_observer(self) ...
You are a Python code generator, capable of creating scripts from specifications.
This method notifies the parent state about changes made to the state element
Can you generate a brief explanation for the following Python 3 code def model_changed(self, model, prop_name, info): if self.parent is not None: self.parent.model_changed(model, prop_name, info)
As a Python code analyst, you investigate and solve complex coding mysteries
This method notifies the parent state about changes made to the meta data
Can you generate a brief explanation for the following Python 3 code def meta_changed(self, model, prop_name, info): if self.parent is not None: msg = info.arg # Add information about notification to the signal message notification = Notification(model, prop_name, info) ...
As a Python code composer, you craft elegant and concise scripts.
Callback when a config value has been changed
Can you tell what is the following Python 3 function doing def on_config_value_changed(self, config_m, prop_name, info): config_key = info['args'][1] if config_key in ["EXECUTION_TICKER_ENABLED"]: self.check_configuration()
You are a Python code analyst, evaluating scripts for potential improvements.
Relieve all state machines that have no active execution and hide the widget
Given the following Python 3 function, write the documentation def disable(self): self.ticker_text_label.hide() if self.current_observed_sm_m: self.stop_sm_m_observation(self.current_observed_sm_m)
You are a Python code analyst, evaluating scripts for potential improvements.
Show current execution status in the widget
Here you have a function in Python 3, explain what it does def on_state_execution_status_changed_after(self, model, prop_name, info): from rafcon.gui.utils.notification_overview import NotificationOverview from rafcon.core.states.state import State def name_and_next_state(state): as...
As a Python code analyst, you investigate and solve complex coding mysteries
Register all observable which are of interest
Explain what the following Python 3 code does def register_observer(self): self.execution_engine.add_observer(self, "start", notify_before_function=self.on_start) self.execution_engine.add_observer(self, "pause", notify_before_function=self.on_pause) self.execution_engine.add_observer(self, "sto...
You are a Python code analyst, evaluating scripts for potential improvements.
This function registers all states of state machine.
Can you generate the documentation for the following Python 3 function def register_states_of_state_machine(self, state_machine): root = state_machine.root_state root.add_observer(self, "state_execution_status", notify_after_function=self.on_state_execution_status_changed_after...
As a Python code translator, you convert algorithms and pseudocode into Python.
A function tha registers recursively all child states of a state
Make a summary of the following Python 3 code def recursively_register_child_states(self, state): self.logger.info("Execution status observer add new state {}".format(state)) if isinstance(state, ContainerState): state.add_observer(self, "add_state", notify_aft...
You are a Python code analyst, evaluating scripts for potential improvements.
This method is called when a state machine is added to the state machine manager
Make a summary of the following Python 3 code def on_add_state_machine_after(self, observable, return_value, args): self.logger.info("Execution status observer register new state machine sm_id: {}".format(args[1].state_machine_id)) self.register_states_of_state_machine(args[1])
As a Python code analyst, you investigate and solve complex coding mysteries
This function is called when the state machine execution status of a state machine has changed after the state machine execution status of a state machine is created.
Explain what the following Python 3 code does def on_state_execution_status_changed_after(self, observable, return_value, args): self.logger.info("Execution status has changed for state '{0}' to status: {1}" "".format(observable.get_path(by_name=True), observable.state_execution_status)...
As a Python code analyst, you investigate and solve complex coding mysteries
This function executes all the child states and stores the output data for the next state.
Here you have a function in Python 3, explain what it does def run(self): try: self._initialize_hierarchy() while self.child_state is not self: # print("hs1", self.name) self.handling_execution_mode = True execution_mode = singleton.state_...
You are a Python code analyst, evaluating scripts for potential improvements.
def _handle_backward_execution_before_child_execution(self): """ Sets up all data after receiving a backward execution step from the execution engine :return: a flag to indicate if normal child state execution should abort """ self.backward_execution = True last_history_item = se...
Can you create a Python 3 function that sets up all data after receiving a backward execution step from the execution engine
As a python code expert, you are capable of creating scripts from specifications.
This function processes all data for a child state and executes it.
Can you generate the documentation for the following Python 3 function def _execute_current_child(self): self.child_state.input_data = self.get_inputs_for_state(self.child_state) self.child_state.output_data = self.create_output_dictionary_for_state(self.child_state) # process data of last sta...
You are a Python code generator, capable of creating scripts from specifications.
Cleanup the former child state execution and prepare for the next state execution in the backward execution case.
Can you generate the documentation for the following Python 3 function def _handle_backward_execution_after_child_execution(self): self.child_state.state_execution_status = StateExecutionStatus.WAIT_FOR_NEXT_STATE # the item popped now from the history will be a CallItem and will contain the scoped data...
As a Python code composer, you craft elegant and concise scripts.
def rotate_and_detach_tab_labels(self): """Rotates tab labels of a given notebook by 90 degrees and makes them detachable. :param notebook: GTK Notebook container, whose tab labels are to be rotated and made detachable """ icons = {'Libraries': constants.SIGN_LIB, 'States Tree': constan...
Write a Python 3 script to rotate tab labels of a given GTK Notebook container by 90 degrees and makes them detachable.
As a Python code analyst, you investigate and solve complex coding mysteries
def bring_tab_to_the_top(self, tab_label): """Find tab with label tab_label in list of notebooks and set it to the current page. :param tab_label: String containing the label of the tab to be focused """ found = False for notebook in self.left_bar_notebooks: for i in...
Write a Python 3 script for finding tab with label tab_label in list of notebooks and set it to the current page.
As a Python code composer, you craft elegant and concise scripts.
Generates the default success transition of a state to its parent success
Can you generate the documentation for the following Python 3 function def add_transitions_from_selected_state_to_parent(): task_string = "create transition" sub_task_string = "to parent state" selected_state_m, msg = get_selected_single_state_model_and_check_for_its_parent() if selected_state_m is Non...
You are a Python code analyst, evaluating scripts for potential improvements.
def add_transitions_to_closest_sibling_state_from_selected_state(): """ Generates the outcome transitions from outcomes with positive outcome_id to the closest next state :return: """ task_string = "create transition" sub_task_string = "to closest sibling state" selected_state_m, msg = get_sele...
Can you create a Python 3 function that generates the outcome transitions from outcomes with positive outcome_id to the closest next state
As a Python code analyst, you investigate and solve complex coding mysteries
def add_coordinates(network): """ Add coordinates to nodes based on provided geom Parameters ---------- network : PyPSA network container Returns ------- Altered PyPSA network container ready for plotting """ for idx, row in network.buses.iterrows(): wkt_geom = to_shape...
Can you create a Python 3 function that adds coordinates to nodes based on provided geom
You are a Python code architect, reviewing and designing scalable and efficient code
Plots the line loading of the given time series.
Here you have a function in Python 3, explain what it does def plot_line_loading( network, timesteps=range(1,2), filename=None, boundaries=[], arrows=False): """ Plots line loading as a colored heatmap. Line loading is displayed as relative to nominal capacity in %. ...
As a Python code composer, you craft elegant and concise scripts.
Plot difference in line loading between two networks.
Explain what the following Python 3 code does def plot_line_loading_diff(networkA, networkB, timestep=0): # new colormap to make sure 0% difference has the same color in every plot def shiftedColorMap( cmap, start=0, midpoint=0.5, stop=1.0, name='shif...
You are a Python code architect, reviewing and designing scalable and efficient code
def network_expansion(network, method = 'rel', ext_min=0.1, ext_width=False, filename=None, boundaries=[]): """Plot relative or absolute network extension of AC- and DC-lines. Parameters ---------- network: PyPSA network container Holds topology of grid including resul...
Can you implement a function in Python 3 that plots relative or absolute network extension of AC - and DC - lines.
You are a Python code generator, capable of creating scripts from specifications.
def network_expansion_diff (networkA, networkB, filename=None, boundaries=[]): """Plot relative network expansion derivation of AC- and DC-lines. Parameters ---------- networkA: PyPSA network container Holds topology of grid including results from powerflow analysis networkB: PyPSA netw...
Write a Python 3 script for plotting relative network expansion derivation of AC - and DC - lines.
As a Python code translator, you convert algorithms and pseudocode into Python.
def full_load_hours(network, boundaries=[], filename=None, two_cb=False): """Plot loading of lines in equivalten full load hours. Parameters ---------- network: PyPSA network container Holds topology of grid including results from powerflow analysis filename: str or None Save fi...
How would you code a function in Python 3 to plot loading of lines in equivalten full load hours.
As a Python code analyst, you investigate and solve complex coding mysteries
def plot_q_flows(network): """Plot maximal reactive line load. Parameters ---------- network: PyPSA network container Holds topology of grid including results from powerflow analysis """ cmap_line = plt.cm.jet q_flows_max = abs(network.lines_t.q0.abs().max()/(network.line...
Write a Python 3 function for plotting maximal reactive line load.
As a Python code analyst, you investigate and solve complex coding mysteries
def max_load(network, boundaries=[], filename=None, two_cb=False): """Plot maximum loading of each line. Parameters ---------- network: PyPSA network container Holds topology of grid including results from powerflow analysis filename: str or None Save figure in this direct...
Write a Python 3 function for plotting maximum loading of each line.
As a Python code translator, you convert algorithms and pseudocode into Python.
def load_hours(network, min_load=0.9, max_load=1, boundaries=[0, 8760]): """Plot number of hours with line loading in selected range. Parameters ---------- network: PyPSA network container Holds topology of grid including results from powerflow analysis min_load: float Cho...
Can you implement a function in Python 3 that plots number of hours with line loading in selected range.
You are a Python code generator, capable of creating scripts from specifications.