Skip to content

Commit

Permalink
Add parameteried exchange events
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Nov 15, 2024
1 parent 8fca464 commit 2c46fc4
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bw2data/backends/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ def __init__(self, document=None, **kwargs):
self._document.output_code,
)

@property
def id(self):
return self._document.id

def save(self, signal: bool = True, data_already_set: bool = False, force_insert: bool = False):
if not data_already_set and not self.valid():
raise ValidityError(
Expand Down
2 changes: 1 addition & 1 deletion bw2data/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ def save(self, *args, **kwargs):
exc = ExchangeDataset.get_or_none(id=self.exchange)
if exc and exc.data.get("formula") != self.formula:
exc.data["formula"] = self.formula
exc.save()
exc.save(signal=False)

@staticmethod
def load(group):
Expand Down
15 changes: 14 additions & 1 deletion bw2data/revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
from bw2data.backends.utils import dict_as_activitydataset, dict_as_exchangedataset
from bw2data.database import DatabaseChooser
from bw2data.errors import DifferentObjects, IncompatibleClasses
from bw2data.parameters import ActivityParameter, DatabaseParameter, ParameterBase, ProjectParameter
from bw2data.parameters import (
ActivityParameter,
DatabaseParameter,
ParameterBase,
ParameterizedExchange,
ProjectParameter,
)
from bw2data.signals import SignaledDataset
from bw2data.snowflake_ids import snowflake_id_generator
from bw2data.utils import get_node
Expand Down Expand Up @@ -316,6 +322,11 @@ def _unwrap_diff_dict(cls, data: dict) -> dict:
}


class RevisionedParameterizedExchange(RevisionedParameter):
KEYS = ("id", "group", "formula", "exchange")
ORM_CLASS = ParameterizedExchange


class RevisionedProjectParameter(RevisionedParameter):
KEYS = ("id", "name", "formula", "amount", "data")
ORM_CLASS = ProjectParameter
Expand Down Expand Up @@ -453,6 +464,7 @@ def handle(cls, revision_data: dict) -> None:
ProjectParameter: "project_parameter",
DatabaseParameter: "database_parameter",
ActivityParameter: "activity_parameter",
ParameterizedExchange: "parameterized_exchange",
}
REVISIONED_LABEL_AS_OBJECT = {
"lci_node": RevisionedNode,
Expand All @@ -461,5 +473,6 @@ def handle(cls, revision_data: dict) -> None:
"project_parameter": RevisionedProjectParameter,
"database_parameter": RevisionedDatabaseParameter,
"activity_parameter": RevisionedActivityParameter,
"parameterized_exchange": RevisionedParameterizedExchange,
}
REVISIONS_OBJECT_AS_LABEL = {v: k for k, v in REVISIONED_LABEL_AS_OBJECT.items()}
Loading

0 comments on commit 2c46fc4

Please sign in to comment.