Skip to content

Read EcoSpold 2 mathematicalRelation formulas - #215

Merged
ccomb merged 3 commits into
mainfrom
ecospold2-mathematical-relation
Jul 15, 2026
Merged

Read EcoSpold 2 mathematicalRelation formulas#215
ccomb merged 3 commits into
mainfrom
ecospold2-mathematical-relation

Conversation

@ccomb

@ccomb ccomb commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Why

EcoSpold 2 datasets carry their calculation logic in mathematicalRelation attributes: <parameter> elements declare variables, and an exchange's amount can be defined as a formula over them. The parser ignored all of it — parameters were dropped on the floor and formulas were invisible, so a consumer could never inspect how an amount was derived, and a stored amount inconsistent with its formula went unnoticed. The SimaPro path already evaluates formulas through Expr; this brings EcoSpold 2 formula reading onto the same machinery.

What it does now

  • <parameter> variables land on the activity: the resolved value in activityParams and the raw formula in activityParamExprs — the same fields the SimaPro parser fills. A parameter with a variableName but no usable amount is dropped with a warning.
  • An exchange's mathematicalRelation is checked after the whole dataset is read (its variables may be declared later in the file), against a dataset-local environment: the dataset's parameters plus every exchange's own variableName bound to its stored amount.
  • The stored amount always stays authoritative. The evaluator supports only a subset of the formula language (no UnitConversion, no cross-dataset Ref) with SimaPro-flavoured semantics, so its result serves as a consistency check: a formula that evaluates to a different value is reported as a divergence warning, never applied.
  • Formulas that cannot be evaluated are summarized in a single warning per dataset — real databases use unsupported functions heavily, and one line per exchange would flood the load log.
  • Attributes on a nested <property> are excluded from exchange capture, the same way property amounts already were.

Cross-dataset variable resolution is out of scope: everything is resolved within one dataset.

Tests

New mathematicalRelation formulas group in EcoSpold2Spec: divergence keeps the stored amount and warns, parameter storage on the activity, the unresolvable-variable fallback, the dropped-parameter warning, and the property-attribute no-leak case. Full suite: 1555 examples, 0 failures.

ccomb added 3 commits July 15, 2026 05:34
EcoSpold 2 datasets define exchange amounts as formulas over dataset
parameters and exchange variable names, but the parser ignored both:
<parameter> elements were dropped and formulas were invisible.

Parse <parameter> variables onto the activity (resolved value plus raw
formula, the same fields the SimaPro parser already fills) and re-evaluate
each exchange's mathematicalRelation against the dataset-local environment
once the file is fully read, since the variables it references may be
declared after the exchange. A formula that evaluates replaces the stored
amount; one that doesn't (unknown variable, unsupported function,
cross-dataset reference) keeps the stored amount and is reported as a
load-time warning rather than silently ignored. Nested <property>
attributes are excluded from capture the same way property amounts
already are.
The evaluator covers only a subset of the EcoSpold 2 formula language
(no UnitConversion, no cross-dataset Ref) with SimaPro-flavoured
semantics, while stored amounts are pre-evaluated by the editor that
wrote the dataset. Overriding a stored amount with our re-evaluation
could corrupt data whenever the two disagree for evaluator reasons
rather than staleness, so the formula result is now a consistency
check: a divergence warns and keeps the stored value.

Real databases use unsupported functions heavily, so unevaluable
formulas are summarized in one warning per dataset instead of one per
exchange. A <parameter> carrying a variableName but no usable amount
is now dropped with a warning instead of silently.
@ccomb
ccomb merged commit 268b0fd into main Jul 15, 2026
9 checks passed
@ccomb
ccomb deleted the ecospold2-mathematical-relation branch July 15, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant