Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added export to .csv button to LCA results tabs #1364

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading