Skip to content

Divide an EcoSpold 1 dataset of several products by its allocation keys - #880

Open
ccomb wants to merge 2 commits into
mainfrom
es1-allocation-reading
Open

ccomb wants to merge 2 commits into
mainfrom
es1-allocation-reading

Conversation

@ccomb

@ccomb ccomb commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Problem

An EcoSpold 1 dataset can make several products. It files them in output group 2 and divides its other lines between them with <allocation> keys: a product, a fraction in percent, and the numbers of the lines the fraction applies to. The reader ignored those keys. A block whose lines are meant to be split by a mass or economic key loaded as if no key was given. The writer also put coproducts in output group 1, which the format defines as an avoided product system.

Solution

  • The reader reads each dataset's allocation keys and translates them into what the engine already divides blocks by:
    • every product takes one fraction of every line it shares: that fraction becomes the product's declared share, as other readers state it. A reading that keeps the block whole keeps it to price the products;
    • the fractions differ from line to line: each product is declared at 100 % and each (product, line) pair carries its own fraction. Only the reading by declared shares applies these. A line no key gives a product counts 0 for it, which is the only reading a key implies, and the load says so.
  • A key that cannot be applied leaves the block whole and the load says why: a number naming no line or several lines, a key for something that is not a product, two different fractions for one pair, an unreadable number or fraction, or keys giving no product any line it shares. Dividing by the other keys would apply them to lines their author did not mean.
  • A dataset that names no reference product but lists allocated products takes the first of them that makes something as its reference, and the load says which.
  • A product in group 1, group 3, an unknown group or no group is still read as a coproduct, as before, and the load now says so. The writer puts a coproduct in group 2.
  • When a block is kept whole, its dataset number also points to each of its coproducts. An input naming that number and a coproduct is then linked to that block, not to another one making the same product.
  • A single file holding one dataset of several products is now counted before allocation, as a directory counts it. Its processes get the same identifiers whether the file is loaded alone or from its directory.

Remarks

  • The cache signature moves: nothing changes type, so a cache written before would keep these blocks undivided.
  • The translation is a pure function in its own module (EcoSpold.Allocation1). The parser only collects the keys and the line numbers.
  • Writing these keys back out is left for the next change. This one only reads them.

How to test

cabal test lca-tests --test-options='--match "EcoSpold1Allocation"'

The tests cover: one fraction per product, fractions line by line, a product with no line, totals other than 100, and each refusal. They also check that each dataset of a file reads its own keys, that a file loads the same alone or from its directory, and that an input buying a coproduct is linked to the block its number names. Without the coproduct entries, this last test links the input to the wrong block.

The reader now reads the <allocation> keys and turns them into product
shares, or into fractions per line when they differ from line to line. A
key that cannot be applied leaves the block whole and the load says why.
Coproducts are written in output group 2, the format's group for an
allocated product, instead of group 1, which means an avoided product.
…keys leave out

A dataset naming no reference took its first output read as a coproduct,
even one listed at zero or filed in group 3. It now takes the first product
of group 2 that makes something, and the load names it. A product the keys
give no line is declared at 0 % aloud, and keys giving no product any line
leave the block whole. The cache signature moves, since nothing changes
type.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-reviewed pr-cycle ran

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant