def calculate_scenarios(self): if not ps_utils.PresamplesParameterManager.has_parameterized_exchanges(): QMessageBox.warning( self, "No parameterized exchanges", "Please set formulas on exchanges to make use of scenario analysis.", QMessageBox.Ok, QMessageBox.Ok ) return flow_scenarios = "Save as flow scenarios (excel)" presamples = "Save as presamples package (presamples)" choice_dlg = ChoiceSelectionDialog.get_choice(self, flow_scenarios, presamples) if choice_dlg.exec_() != ChoiceSelectionDialog.Accepted: return if choice_dlg.choice == flow_scenarios: df = self.build_flow_scenarios() self.store_flows_to_file(df) elif choice_dlg.choice == presamples: dialog = ForceInputDialog.get_text( self, "Add label", "Add a label to the calculated scenarios" ) if dialog.exec_() == ForceInputDialog.Accepted: result = dialog.output if result in ps_utils.find_all_package_names(): overwrite = QMessageBox.question( self, "Label already in use", "Overwrite the old calculations?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No ) if overwrite == QMessageBox.Yes: older = ps_utils.get_package_path(result) ps_utils.remove_package(older) self.build_presamples_packages(safe_filename(result, False)) else: self.build_presamples_packages(safe_filename(result, False))
def savefilepath(self, default_file_name: str, file_filter: str = ALL_FILTER): default = default_file_name or "LCA results" safe_name = safe_filename(default, add_hash=False) filepath, _ = QtWidgets.QFileDialog.getSaveFileName( parent=self, caption='Choose location to save lca results', dir=os.path.join(ab_settings.data_dir, safe_name), filter=file_filter, ) return filepath
def calculate_scenarios(self): if not ps_utils.PresamplesParameterManager.can_build_presamples(): QMessageBox.warning( self, "No parameterized exchanges", "Please set formulas on exchanges to make use of scenario analysis.", QMessageBox.Ok, QMessageBox.Ok ) return dialog = ForceInputDialog.get_text( self, "Add label", "Add a label to the calculated scenarios" ) if dialog.exec_() == ForceInputDialog.Accepted: result = dialog.output if result in ps_utils.find_all_package_names(): overwrite = QMessageBox.question( self, "Label already in use", "Overwrite the old calculations?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No ) if overwrite == QMessageBox.Yes: older = ps_utils.get_package_path(result) ps_utils.remove_package(older) self.build_presamples_packages(safe_filename(result, False)) else: self.build_presamples_packages(safe_filename(result, False))
def backup_project_directory(project): """Backup project data directory to a ``.tar.gz`` (compressed tar archive). ``project`` is the name of a project. Backup archive is saved to the user's home directory. Restoration is done using ``restore_project_directory``. Returns the filepath of the backup archive.""" if project not in projects: raise ValueError("Project {} does not exist".format(project)) fp = os.path.join( os.path.expanduser("~"), "brightway2-project-{}-backup.{}.tar.gz".format( project, datetime.datetime.now().strftime("%d-%B-%Y-%I-%M%p"))) dir_path = os.path.join(projects._base_data_dir, safe_filename(project)) with open(os.path.join(dir_path, ".project-name.json"), "w") as f: json.dump({'name': project}, f) print("Creating project backup archive - this could take a few minutes...") with tarfile.open(fp, "w:gz") as tar: tar.add(dir_path, arcname=safe_filename(project))
def savefilepath(self, default_file_name: str, caption: str = None, file_filter: str = None): """ Construct and return default path where data is stored Uses the application directory for AB """ safe_name = safe_filename(default_file_name, add_hash=False) caption = caption or "Choose location to save lca results" filepath, _ = QFileDialog.getSaveFileName( parent=self, caption=caption, dir=os.path.join(ab_settings.data_dir, safe_name), filter=file_filter or self.ALL_FILTER, ) # getSaveFileName can now weirdly return Path objects. return str(filepath) if filepath else filepath