LCA-ActivityBrowser / activity-browser

GUI for brightway2
GNU Lesser General Public License v3.0
140 stars 54 forks source link

Database tree view #632

Closed marc-vdm closed 2 months ago

marc-vdm commented 3 years ago

As discussed a few times, a tree view for databases would be nice to have, this could be based on some classification system already present in databases like ecoinvent.

For whoever picks this up: Through other work, I found that the classifications are stored in the Metadatastore:

from activity_browser.bwutils import AB_metadata

db = AB_metadata.get_database_metadata(database_name)

This db object is a Pandas Dataframe, with a column classifications. Each entry is a list in which the classifications are stored as tuples: (name of classification, class)

Hope that saves some work for whoever picks this up.

TODO

marc-vdm commented 1 year ago

See related discussion here https://github.com/LCA-ActivityBrowser/activity-browser/issues/596#issuecomment-1325671704

Joeytje50 commented 1 year ago

https://unstats.un.org/unsd/classifications/Econ/Download/In%20Text/ISIC_Rev_4_english_structure.Txt This tree view should be incorporated in the static files, and then read by AB to build a tree view of the different categories. On the branch https://github.com/marc-vdm/activity-browser/tree/including_classifications there are already some of these classifications loaded for most of the ecoinvent activities. The activities should be grouped under their respective tree view when showing it.

The tree should be built up similar to Impact Categories, and the filtering should be made to work similar to it. When not in the tree view, the categories should not necessarily be shown, although that might be discussed still.

Furthermore, dragging and dropping activities should still be possible: dragging a parent tree level should drag and drop all child levels.

Finally, it might be useful to make the tree view code work more general, i.e. to reuse the same class when building the tree view of different things.

Databases that do not have these classifications loaded, should disable the tree view. Databases always load in list view by default.

marc-vdm commented 1 year ago

One more thing: It may be good to check out whether it's smart to move the storage of the data up to the ActivityBiosphereWidget instead of having two dataframes, one for the tree and one for the list, but perhaps that's not a problem at all since we already use the MetaDataStore. Happy to think along on this you want. Ok, so we get the data from df_from_metadata(self, db_name: str) -> pd.DataFrame:, you can probably do something similar in the treeview to get the data, probably all you need is df = AB_metadata.get_database_metadata(db_name), though you may need to transform the data from a pd.DataFrame to a dict or something.

marc-vdm commented 1 year ago

On the branch https://github.com/marc-vdm/activity-browser/tree/including_classifications there are already some of these classifications loaded for most of the ecoinvent activities.

The classifications are now available in master, so no need to base the branch of my fork, just from master is fine 👍

marc-vdm commented 2 months ago

Resolved in #1047

github-actions[bot] commented 2 months ago

[!NOTE] This issue has been implemented in the new release of Activity Browser 🚀 (version 2.10.0), you can get the new version by updating Activity Browser.

Do you want to be notified of new releases of Activity Browser? Subscribe to our updates mailing list ✉.

🤖 beep boop! I'm a bot and this message was an automated action. If updating does not make sense for this issue, just ignore this.