def test_filter_interface(core, project, tree): project = deepcopy(project) data_menu = DataMenu() module_menu = ModuleMenu() project_menu = ProjectMenu() tree = Tree() data_menu.select_database(project, "local") project_menu.initiate_pipeline(core, project) project_menu.initiate_options(core, project) filter_branch = tree.get_branch(core, project, 'Database Filtering Interface') new_var = filter_branch.get_input_variable(core, project, "device.selected_name") new_var.set_raw_interface(core, "ExampleWaveDevice") new_var.read(core, project) module_menu.activate(core, project, "Hydrodynamics") project_menu.initiate_filter(core, project) assert True
def test_DataMenu_import_data(mocker, tmpdir, core, project, module_menu): # Make a source directory with some files config_tmpdir = tmpdir.mkdir("config") mock_dir = Directory(str(config_tmpdir)) mocker.patch("dtocean_core.utils.database.UserDataDirectory", return_value=mock_dir) data_menu = DataMenu() var_tree = Tree() project = deepcopy(project) mod_name = "Mock Module" core.register_level(project, core._markers["register"], "Mock Module") module_menu.activate(core, project, mod_name) mod_branch = var_tree.get_branch(core, project, mod_name) mod_branch.read_test_data(core, project, os.path.join(dir_path, "inputs_wp2_tidal.pkl")) pre_length = len(project._pool) dts_path = os.path.join(str(tmpdir), "test.dts") data_menu.export_data(core, project, dts_path) assert os.path.isfile(dts_path) data_menu.import_data(core, project, dts_path) assert len(project._pool) > pre_length
def _set_variables(self, box_number): self.varBox.clear() if box_number < 0: return interface_name = self._mod_names[box_number] tree = Tree() if self._var_ids is None: var_id_dict = {} else: var_id_dict = self._var_ids branch = tree.get_branch(self._shell.core, self._shell.project, interface_name) var_inputs = branch.get_inputs(self._shell.core, self._shell.project) unique_vars = OrderedSet(var_inputs) var_names = [] for var_id in unique_vars: var_meta = self._shell.core.get_metadata(var_id) if "SimpleData" in var_meta.structure: if var_meta.types is None: errStr = ("Variable {} with SimpleData structure " "requires types meta data to be " "set").format(var_id) raise ValueError(errStr) if ("int" in var_meta.types or "float" in var_meta.types or "str" in var_meta.types): title = var_meta.title if var_meta.units is not None: title = "{} ({})".format(title, var_meta.units[0]) var_names.append(title) if title not in var_id_dict: var_id_dict[title] = var_id self._var_ids = var_id_dict self.varBox.addItems(var_names) self.varBox.setCurrentIndex(-1) return
def _set_variables(self, shell, active_interfaces, include_str=False): self.varBox.clear() tree = Tree() all_var_names = [] var_id_dict = {} for interface_name in active_interfaces: branch = tree.get_branch(shell.core, shell.project, interface_name) var_inputs = branch.get_inputs(shell.core, shell.project) var_outputs = branch.get_outputs(shell.core, shell.project) unique_vars = OrderedSet(var_inputs + var_outputs) var_names = [] var_names = [] for var_id in unique_vars: var_meta = shell.core.get_metadata(var_id) if "SimpleData" in var_meta.structure: if var_meta.types is None: errStr = ("Variable {} with SimpleData structure " "requires types meta data to be " "set").format(var_id) raise ValueError(errStr) if "int" in var_meta.types or "float" in var_meta.types: var_names.append(var_meta.title) if include_str and "str" in var_meta.types: var_names.append(var_meta.title) if var_meta.title not in var_id_dict: var_id_dict[var_meta.title] = var_id all_var_names.extend(var_names) self._var_ids = var_id_dict self.varBox.addItems(all_var_names) self.varBox.setCurrentIndex(-1) return
def test_ThemeMenu_execute_all(core, project, theme_menu): var_tree = Tree() project = deepcopy(project) theme_menu.activate(core, project, "Mock Theme") theme_menu.activate(core, project, "Mock Theme 2") theme_menu.execute_all(core, project) theme_branch = var_tree.get_branch(core, project, "Mock Theme") var = theme_branch.get_output_variable(core, project, 'project.capex_total') result = var.get_value(core, project) assert result == 1 theme_branch = var_tree.get_branch(core, project, "Mock Theme 2") var = theme_branch.get_output_variable(core, project, 'project.discounted_capex') result = var.get_value(core, project) assert result == 2
def test_ModuleMenu_execute_current_nothemes(core, project, module_menu): var_tree = Tree() project = deepcopy(project) mod_name = "Mock Module" module_menu.activate(core, project, mod_name) mod_branch = var_tree.get_branch(core, project, mod_name) mod_branch.read_test_data(core, project, os.path.join(dir_path, "inputs_wp2_tidal.pkl")) module_menu.execute_current(core, project, execute_themes=False) assert True
def wave_project(core): '''Share a Project object''' project_menu = ProjectMenu() var_tree = Tree() new_project = project_menu.new_project(core, "test wave") options_branch = var_tree.get_branch(core, new_project, "System Type Selection") device_type = options_branch.get_input_variable(core, new_project, "device.system_type") device_type.set_raw_interface(core, "Wave Floating") device_type.read(core, new_project) return new_project
class HubRoot(object): def __init__(self, title, hub_name, branch_cls, active=True, branch_order=None): self._title = title self._tree = Tree() self._hub_name = hub_name self._BranchCls = branch_cls self._active = active self._branch_order = branch_order self._items = [] return def _activate(self, parent, shell, hub_branches): if self._branch_order is None: branch_order = hub_branches else: branch_order = [branch for branch in self._branch_order if branch in hub_branches] for branch_name in branch_order: branch = self._tree.get_branch(shell.core, shell.project, branch_name) new_item = self._BranchCls(parent, branch, self._title, branch_name) if self._active: new_item._activate(shell) else: new_item.setDisabled(True) self._items.append(new_item) return
def project(core): '''Share a Project object''' project_title = "Test" project_menu = ProjectMenu() var_tree = Tree() new_project = project_menu.new_project(core, project_title) options_branch = var_tree.get_branch(core, new_project, "System Type Selection") device_type = options_branch.get_input_variable(core, new_project, "device.system_type") device_type.set_raw_interface(core, "Tidal Fixed") device_type.read(core, new_project) project_menu.initiate_pipeline(core, new_project) return new_project
def test_options_interface_sites(core, wave_project): project_menu = ProjectMenu() var_tree = Tree() interface_name = "Site and System Options" project = deepcopy(wave_project) project_menu.activate(core, project, interface_name) site_system_branch = var_tree.get_branch(core, project, interface_name) available_sites = site_system_branch.get_input_variable( core, project, "hidden.available_sites") available_sites_dict = { "id": [1, 2], "site_name": ["a", "b"], "lease_area_proj4_string": ["a", "b"] } available_sites_df = pd.DataFrame(available_sites_dict) available_sites.set_raw_interface(core, available_sites_df) available_sites.read(core, project) can_execute = project_menu.is_executable(core, project, interface_name) if not can_execute: inputs = site_system_branch.get_input_status(core, project) pprint(inputs) assert can_execute connector = _get_connector(project, "project") interface = connector.get_interface(core, project, interface_name) interface.connect() assert interface.data.site_names.equals(available_sites_df["site_name"]) assert interface.data.corridor_selected == False assert interface.data.lease_selected == False
def test_system_type_interface(core, wave_project): project_menu = ProjectMenu() var_tree = Tree() interface_name = "System Type Selection" project = deepcopy(wave_project) system_type_branch = var_tree.get_branch(core, project, interface_name) can_execute = project_menu.is_executable(core, project, interface_name) if not can_execute: inputs = system_type_branch.get_input_status(core, project) pprint(inputs) assert can_execute connector = _get_connector(project, "project") interface = connector.get_interface(core, project, interface_name) interface.connect() assert interface.data.output == True
def test_options_interface_systems(core, wave_project): project_menu = ProjectMenu() var_tree = Tree() interface_name = "Site and System Options" project = deepcopy(wave_project) project_menu.activate(core, project, interface_name) site_system_branch = var_tree.get_branch(core, project, interface_name) available_systems = site_system_branch.get_input_variable( core, project, "hidden.available_systems") available_systems_dict = { "id": [1, 2], "description": ["a", "b"], "device_type": ["a", "Wave Floating"] } available_systems_df = pd.DataFrame(available_systems_dict) available_systems.set_raw_interface(core, available_systems_df) available_systems.read(core, project) can_execute = project_menu.is_executable(core, project, interface_name) if not can_execute: inputs = site_system_branch.get_input_status(core, project) pprint(inputs) assert can_execute connector = _get_connector(project, "project") interface = connector.get_interface(core, project, interface_name) interface.connect() assert interface.data.system_names.equals(pd.Series(["b"]))
class HubControl(BaseControl): def __init__(self, address, title, view, model, proxy, hub_name, branch_cls, active=True, branch_order=None): super(HubControl, self).__init__(address, title, view, model, proxy) self._tree = Tree() self._hub_name = hub_name self._BranchCls = branch_cls self._active = active self._branch_order = branch_order return def _activate(self, shell, parent): retrieve_branch = True if (self._hub_name in shell.queued_interfaces and shell.queued_interfaces[self._hub_name] is not None): hub_branches = shell.queued_interfaces[self._hub_name] retrieve_branch = False else: hub_branches = self._tree.get_available_branches( shell.core, shell.project, [self._hub_name]) if self._branch_order is None: branch_order = hub_branches else: branch_order = [ branch for branch in self._branch_order if branch in hub_branches ] for branch_name in branch_order: if retrieve_branch: branch = self._tree.get_branch(shell.core, shell.project, branch_name) else: branch = None # Model item address = self._address + "." + branch_name user_dict = { "address": address, "visible": True, "section": "branch", "status": None } name_item = QtGui.QStandardItem(branch_name) name_item.setData(address, QtCore.Qt.UserRole) name_item.setData((user_dict, ), 33) parent.appendRow(name_item) # Controller new_control = self._BranchCls(address, branch_name, self._view, self._model, self._proxy, self._title, branch) new_control._init_ui(name_item) if self._active: new_control._activate(shell, name_item) else: name_item.setFlags(QtCore.Qt.NoItemFlags) self._controls.append(new_control) return