activity-browser
activity-browser copied to clipboard
Controller refactor
Checklist
- [ ] Keep pull requests small so they can be easily reviewed.
- [ ] Update the documentation, please follow the numpy style guide.
- [ ] Update tests.
- [ ] Categorize the PR by setting a good title and adding one of the labels:
bug,feature,ui,change,documentation,breaking,cias they show up in the changelog. - [ ] Link this PR to related issues by using closing keywords.
- [ ] Add a milestone to the PR (and related issues, if any) for the intended release.
- [ ] Request a review from another developer.
Some notes:
Projects
- [x] When starting AB/switching project: 'Reset metadata.' print happens twice
- [x] When creating default data/biosphere (3.9.1): each new patch flow is printed like:
Adding activity to metadata: 'Trifluralin' (kilogram, GLO, ('water',))('biosphere3', 'ff31383c-1658-5034-b266-8f2e0c94c538'), probably useful in log level - [ ] Error when deleting project:
traceback
Reset project settings directory to:C:\Users\meidemtvander\AppData\Local\pylca\Brightway3\proj.4dc844abccfc0d132d087c1c7fcec557
Reset metadata.
Reset metadata.
Traceback (most recent call last):
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\actions\project\project_delete.py", line 37, in onTrigger
projects.delete_project(project_to_delete, delete_dialog.deletion_warning_checked())
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\project.py", line 57, in delete_project
patched[ProjectManager]["delete_project"](self, name, delete_dir)
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\project.py", line 302, in delete_project
shutil.rmtree(dir_path)
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\shutil.py", line 787, in rmtree
return _rmtree_unsafe(path, onerror)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\shutil.py", line 629, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\shutil.py", line 634, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\shutil.py", line 632, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\meidemtvander\\AppData\\Local\\pylca\\Brightway3\\proj.4dc844abccfc0d132d087c1c7fcec557\\lci\\databases.db'
Reset project settings directory to:C:\Users\meidemtvander\AppData\Local\pylca\Brightway3\default.c21f969b5f03d33d43e04f8f136e7682
Impact categories
- [x] Deleting IC puts name in dialog header, would be better in body
- [x] Move inspect to top in IC list
Databases/Activities
- [x] When creating new db, it should be opened
- [x] When creating new activity, activity details should be opened
- [x] When opening empty database
C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py:127: UserWarning: This database is empty warnings.warn("This database is empty") - [x] When db with items is open, open new db with 0 activities, then create one and delete it:
traceback
Current shape and databases in the MetaDataStore:(0, 0)set()
Adding:new db
C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py:127: UserWarning: This database is empty
warnings.warn("This database is empty")
Current shape and databases in the MetaDataStore:(2, 8){'new db'}
Adding:other new db
Deleting activity from metadata:('other new db', '316fe876b56641f1b0faa66b687624e5')
C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py:127: UserWarning: This database is empty
warnings.warn("This database is empty")
C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\ui\tables\models\inventory.py:112: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
df.dropna(how='all', axis=1, inplace=True)
- [x] when enabling 'Edit Activity',
1 unique locations and 1 unique units in new dbis printed, I don't see added value of this - [ ] when editing non-exchange data about activity (amt/unit/product/description)
Updating activity in metadata: 'other new act' (unit, GLO, None)('new db', 'cfeb6e46ddc44cc693843e64b50113ba')is printed, perhaps move to log level and add old/new values - [x] when deleting an activity used in another activity, user gets warning about downstream consumers, confirm, then exchange table is not updated
- [x] activity exchange is then broken when closing activity and re-opening it:
traceback
Adding:new db
+showing tab:Activity Details
1 unique locations and 1 unique units in new db
Deleting activity from metadata:('new db', '9a45f54231fa4c9aae732cc9e4b5aae2')
-hiding tab:Activity Details
Broken exchange: <Model: ActivityDataset> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT ? OFFSET ?
Params: ['new db', '9a45f54231fa4c9aae732cc9e4b5aae2', 1, 0], removing.
Traceback (most recent call last):
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7266, in get
return clone.execute(database)[0]
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 4566, in __getitem__
return self.row_cache[item]
~~~~~~~~~~~~~~^^^^^^
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\ui\tables\models\activity.py", line 56, in create_row
"Unit": exchange.input.get("unit", "Unknown"),
^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\proxies.py", line 151, in _get_input
self._input = get_activity(self['input'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\utils.py", line 335, in get_activity
return Database(key[0]).get(key[1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\base.py", line 56, in get
return patched[SQLiteBackend]["get"](self, code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py", line 133, in get
ActivityDataset.code == code).get()
^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7269, in get
raise self.model.DoesNotExist('%s instance matching query does '
bw2data.backends.peewee.schema.ActivityDatasetDoesNotExist: <Model: ActivityDataset> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT ? OFFSET ?
Params: ['new db', '9a45f54231fa4c9aae732cc9e4b5aae2', 1, 0]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7266, in get
return clone.execute(database)[0]
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 4566, in __getitem__
return self.row_cache[item]
~~~~~~~~~~~~~~^^^^^^
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\actions\exchange\exchange_delete.py", line 23, in onTrigger
exchange.delete()
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\proxies.py", line 169, in delete
in_db = Database(self.input["database"])
^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\proxies.py", line 151, in _get_input
self._input = get_activity(self['input'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\utils.py", line 335, in get_activity
return Database(key[0]).get(key[1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\base.py", line 56, in get
return patched[SQLiteBackend]["get"](self, code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py", line 133, in get
ActivityDataset.code == code).get()
^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7269, in get
raise self.model.DoesNotExist('%s instance matching query does '
bw2data.backends.peewee.schema.ActivityDatasetDoesNotExist: <Model: ActivityDataset> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT ? OFFSET ?
Params: ['new db', '9a45f54231fa4c9aae732cc9e4b5aae2', 1, 0]
Exchange was deleted, continue.
+showing tab:Activity Details
- [x] similarly, when deleting a database which is used in other databases:
traceback
+showing tab:Activity Details
1 unique locations and 1 unique units in new db
Broken exchange: <Model: ActivityDataset> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT ? OFFSET ?
Params: ['other new db', '1716c257c31d4773a045b7a315af9ab3', 1, 0], removing.
Traceback (most recent call last):
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7266, in get
return clone.execute(database)[0]
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 4566, in __getitem__
return self.row_cache[item]
~~~~~~~~~~~~~~^^^^^^
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\ui\tables\models\activity.py", line 56, in create_row
"Unit": exchange.input.get("unit", "Unknown"),
^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\proxies.py", line 151, in _get_input
self._input = get_activity(self['input'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\utils.py", line 335, in get_activity
return Database(key[0]).get(key[1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\base.py", line 56, in get
return patched[SQLiteBackend]["get"](self, code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py", line 133, in get
ActivityDataset.code == code).get()
^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7269, in get
raise self.model.DoesNotExist('%s instance matching query does '
bw2data.backends.peewee.schema.ActivityDatasetDoesNotExist: <Model: ActivityDataset> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT ? OFFSET ?
Params: ['other new db', '1716c257c31d4773a045b7a315af9ab3', 1, 0]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7266, in get
return clone.execute(database)[0]
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 4566, in __getitem__
return self.row_cache[item]
~~~~~~~~~~~~~~^^^^^^
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\actions\exchange\exchange_delete.py", line 23, in onTrigger
exchange.delete()
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\proxies.py", line 165, in delete
[qact.emitLater("changed", self.input) for qact in qactivity_list if qact["id"] == self.input._document.id]
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\proxies.py", line 165, in <listcomp>
[qact.emitLater("changed", self.input) for qact in qactivity_list if qact["id"] == self.input._document.id]
^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\proxies.py", line 151, in _get_input
self._input = get_activity(self['input'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\utils.py", line 335, in get_activity
return Database(key[0]).get(key[1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\brightway\bw2data\backends\base.py", line 56, in get
return patched[SQLiteBackend]["get"](self, code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\bw2data\backends\peewee\database.py", line 133, in get
ActivityDataset.code == code).get()
^^^^^
File "C:\Users\meidemtvander\AppData\Local\miniconda3\envs\ab\Lib\site-packages\peewee.py", line 7269, in get
raise self.model.DoesNotExist('%s instance matching query does '
bw2data.backends.peewee.schema.ActivityDatasetDoesNotExist: <Model: ActivityDataset> instance matching query does not exist:
SQL: SELECT "t1"."id", "t1"."data", "t1"."code", "t1"."database", "t1"."location", "t1"."name", "t1"."product", "t1"."type" FROM "activitydataset" AS "t1" WHERE (("t1"."database" = ?) AND ("t1"."code" = ?)) ORDER BY Random() LIMIT ? OFFSET ?
Params: ['other new db', '1716c257c31d4773a045b7a315af9ab3', 1, 0]
Exchange was deleted, continue.
Traceback (most recent call last):
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\layouts\tabs\project_manager.py", line 258, in database_changed
self.table.model.sync(db.name)
File "C:\Users\meidemtvander\OneDrive - Universiteit Leiden\Documents\SD\academia\coding\PycharmProjects\activity-browser\activity_browser\ui\tables\models\inventory.py", line 103, in sync
raise KeyError("This database does not exist!", db_name)
KeyError: ('This database does not exist!', 'other new db')