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

Show non-found CS aspects in tables for deletion #1388

Merged
merged 2 commits into from
Oct 1, 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
56 changes: 35 additions & 21 deletions activity_browser/ui/tables/models/lca_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import numpy as np
import pandas as pd
from PySide2 import QtWidgets
from PySide2.QtCore import QModelIndex, Qt, Slot

from activity_browser import signals
from activity_browser import signals, application
from activity_browser.bwutils import commontasks as bc
from activity_browser.mod import bw2data as bd
from activity_browser.mod.bw2data.backends import ActivityDataset
Expand Down Expand Up @@ -124,7 +125,7 @@ def sync(self):
columns=self.HEADERS,
)
# Drop rows where the fu key was invalid in some way.
self._dataframe = df.dropna().reset_index(drop=True)
self._dataframe = df
self.key_col = self._dataframe.columns.get_loc("key")
self.updated.emit()

Expand All @@ -145,7 +146,8 @@ def build_row(self, key: tuple, amount: float = 1.0) -> dict:
log.error(
f"Could not load key '{key}' in Calculation Setup '{self.current_cs}'"
)
return {}

return {"key": key, "Amount": amount, "Activity": f"NOT FOUND: {key}", "Database": key[0]}

@Slot(name="deleteRows")
def delete_rows(self, proxies: list) -> None:
Expand All @@ -155,9 +157,12 @@ def delete_rows(self, proxies: list) -> None:

# we can disconnect from the deleted activities
for key in [self._dataframe.at[row, "key"] for row in rows]:
activity = bd.get_activity(key)
activity.changed.disconnect(self.sync)
del self._activities[activity.key]
try:
activity = bd.get_activity(key)
activity.changed.disconnect(self.sync)
del self._activities[activity.key]
except ActivityDataset.DoesNotExist:
pass

self._dataframe = self._dataframe.drop(rows).reset_index(drop=True)
self.updated.emit()
Expand Down Expand Up @@ -230,7 +235,6 @@ def sync(self) -> None:
method_tuples = [
mthd
for mthd in bd.calculation_setups[self.current_cs].get("ia", [])
if mthd in bd.methods
]

# build rows for all the collected methods and store in our dataframe
Expand All @@ -244,23 +248,30 @@ def build_row(self, method_tuple: tuple) -> dict:
"""
Build a single row for the methods table and connect the table to the method we're building the row for.
"""
# gather data using the given method_tuple
method_metadata = bd.methods[method_tuple]
method = bd.Method(method_tuple)
try:
# gather data using the given method_tuple
method_metadata = bd.methods[method_tuple]
method = bd.Method(method_tuple)

# construct a row dictionary
row = {
"Name": ", ".join(method_tuple),
"Unit": method_metadata.get("unit", "Unknown"),
"# CFs": method_metadata.get("num_cfs", 0),
"method": method_tuple,
}

# construct a row dictionary
row = {
"Name": ", ".join(method_tuple),
"Unit": method_metadata.get("unit", "Unknown"),
"# CFs": method_metadata.get("num_cfs", 0),
"method": method_tuple,
}
# if the method changes we need to sync
method.changed.connect(self.sync, Qt.UniqueConnection)
self._methods[method.name] = method

# if the method changes we need to sync
method.changed.connect(self.sync, Qt.UniqueConnection)
self._methods[method.name] = method
return row
except KeyError:
log.error(
f"Could not load key '{method_tuple}' in Calculation Setup '{self.current_cs}'"
)

return row
return {"Name": f"NOT FOUND: {method_tuple}", "Unit": "Unknown", "# CFs": 0, "method": method_tuple}

@Slot(list, name="deleteRows")
def delete_rows(self, proxies: list) -> None:
Expand All @@ -270,6 +281,9 @@ def delete_rows(self, proxies: list) -> None:

# we can disconnect from the deleted methods
for method_tuple in [self._dataframe.at[row, "method"] for row in rows]:
if method_tuple not in bd.methods:
continue

method = bd.Method(method_tuple)
method.changed.disconnect(self.sync)
del self._methods[method.name]
Expand Down
Loading