Skip to content

Commit db7d842

Browse files
committed
Exclude activity field from metadata.
thanks ecoinvent
1 parent 3f00e60 commit db7d842

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

activity_browser/app/bwutils/exporters.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from bw2data.utils import safe_filename
77
from bw2io.export.excel import CSVFormatter, create_valid_worksheet_name
8+
from bw2io.export.csv import reformat
89
import xlsxwriter
910

1011
from .pedigree import PedigreeMatrix
@@ -13,9 +14,24 @@
1314
# TODO: reminder to make a pull-request for these things in bw2io repo.
1415
# - Add the 'nan_inf_to_errors' option when opening the xlsxwriter.Workbook.
1516
# - Add handler for pedigree data to exporter
17+
# - Add 'database' field as required CSVFormatter export field.
18+
# - Add code to ensure no second 'activity' field is exported, as this
19+
# messes with following import.
1620

1721

1822
class ABCSVFormatter(CSVFormatter):
23+
def get_activity_metadata(self, act):
24+
excluded = {"database", "name", "activity"}
25+
return {
26+
'name': act.get("name"),
27+
'metadata': sorted([(k, reformat(v))
28+
for k, v in act.items()
29+
if k not in excluded
30+
and not isinstance(v, (dict, list))
31+
]),
32+
'parameters': self.get_activity_parameters(act)
33+
}
34+
1935
def exchange_as_dict(self, exc):
2036
"""Same as CSVFormatter, but explicitly pull the database from the
2137
input activity.

0 commit comments

Comments
 (0)