Skip to content

Commit

Permalink
Merge pull request #1364 from mrvisscher/csv-export
Browse files Browse the repository at this point in the history
Added export to .csv button to LCA results tabs
  • Loading branch information
mrvisscher authored Sep 19, 2024
2 parents d4994be + 27bd728 commit 1165399
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions activity_browser/layouts/tabs/LCA_results_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,23 @@ def generate_content_on_click(self, index):
self.tabs.sankey.new_sankey()

@QtCore.Slot(name="lciaScenarioExport")
def generate_lcia_scenario_export(self):
def generate_lcia_scenario_csv(self):
"""Create a dataframe of the impact category results for all reference flows,
impact categories and scenarios, then call the 'export to csv'
"""
df = self.mlca.lca_scores_to_dataframe()
filepath, _ = QFileDialog.getSaveFileName(
parent=self,
caption="Choose location to save lca results",
filter="Comma Separated Values (*.csv);; All Files (*.*)",
)
if filepath:
if not filepath.endswith(".csv"):
filepath += ".csv"
df.to_csv(filepath)

@QtCore.Slot(name="lciaScenarioExport")
def generate_lcia_scenario_excel(self):
"""Create a dataframe of the impact category results for all reference flows,
impact categories and scenarios, then call the 'export to excel'
"""
Expand Down Expand Up @@ -727,13 +743,23 @@ def build_export(
# Then add the additional label and export btn, plus new stretch.
exp_layout = QHBoxLayout()
exp_layout.addWidget(QLabel("Export all data"))
btn = QPushButton("Excel")
btn.setToolTip(

csv_btn = QPushButton(".csv")
csv_btn.setToolTip(
"Include all reference flows, impact categories and scenarios"
)
if self.parent:
btn.clicked.connect(self.parent.generate_lcia_scenario_export)
exp_layout.addWidget(btn)
csv_btn.clicked.connect(self.parent.generate_lcia_scenario_csv)

excel_btn = QPushButton("Excel")
excel_btn.setToolTip(
"Include all reference flows, impact categories and scenarios"
)
if self.parent:
excel_btn.clicked.connect(self.parent.generate_lcia_scenario_excel)

exp_layout.addWidget(csv_btn)
exp_layout.addWidget(excel_btn)
layout.addWidget(vertical_line())
layout.addLayout(exp_layout)
layout.addSpacerItem(stretch)
Expand Down Expand Up @@ -793,13 +819,23 @@ def build_export(
# Then add the additional label and export btn, plus new stretch.
exp_layout = QHBoxLayout()
exp_layout.addWidget(QLabel("Export all data"))
btn = QPushButton("Excel")
btn.setToolTip(

csv_btn = QPushButton(".csv")
csv_btn.setToolTip(
"Include all reference flows, impact categories and scenarios"
)
if self.parent:
btn.clicked.connect(self.parent.generate_lcia_scenario_export)
exp_layout.addWidget(btn)
csv_btn.clicked.connect(self.parent.generate_lcia_scenario_csv)

excel_btn = QPushButton("Excel")
excel_btn.setToolTip(
"Include all reference flows, impact categories and scenarios"
)
if self.parent:
excel_btn.clicked.connect(self.parent.generate_lcia_scenario_excel)

exp_layout.addWidget(csv_btn)
exp_layout.addWidget(excel_btn)
layout.addWidget(vertical_line())
layout.addLayout(exp_layout)
layout.addSpacerItem(stretch)
Expand Down

0 comments on commit 1165399

Please sign in to comment.