From 45c6c184a734626a01a88a4c0ac4b50c24b7d7e8 Mon Sep 17 00:00:00 2001 From: Manuel Klarmann Date: Tue, 17 Nov 2026 03:52:27 +0100 Subject: [PATCH 1/9] Ranges: several steps compared as one, chosen at the top of the page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A reviewer of a chain of fixes asks what some of them did together. A range is a run of at least two consecutive steps, short of every step: the state before its first step against the state after its last, judged as the whole way is (largest tolerance of its steps, no noise, no verdict). Its classes come from the rule on those two states, never from a sum of steps: two moves of 0.8 % under a 1 % tolerance agree one by one and differ together. - chain: `ranges=` ("all", (first, last) pairs, None, "auto": all up to 8 steps); `ranges_within`; pairs held as references to a few dozen judgments, so 16 states x 66 ranges x 25 indicators x 12k items fit in memory. - format: `ranges`, `counts.ranges`, one class/direction/band per range on every item after the total; the validator works each out again and counts range-only moves as worth a look. Mutation probes in tests/test_ranges.py. - matrix: `of.ranges`, a code per range, and "=" for a result equal to the state before it (a chain of fixes would otherwise hold every number 16 times); a "=" first in an indicator or after a missing result is refused. - description: `ranges` ("all", "none", pairs, {"within": [a, b]}). - page: Shift-click (or Shift+arrow) for the steps from one to another, ⌘/Ctrl to add or take off an end, a "Several steps" switch for touch. Steps apart take in those between, hatched and said; a run the file does not compare is said and changes nothing. The matrix, distributions, worst list and drawer follow the range from the file's own counts. `#step=first..last`. - SPEC sections 3, 4.2, 4.5, 5.3, 10; A28, A29; GLOSSARY "Range". Co-Authored-By: Claude Opus 5.5 --- GLOSSARY.md | 1 + SPEC.md | 73 ++- examples/diagnostics.json | 656 ++++++++++++++++++- examples/local/diagnostics.json | 648 +++++++++++++++++- examples/local/matrix.json | 42 +- src/sentier_diagnostics/chain.py | 185 ++++-- src/sentier_diagnostics/fileformat.py | 103 ++- src/sentier_diagnostics/from_tables.py | 31 +- src/sentier_diagnostics/matrix.py | 118 +++- src/sentier_diagnostics/page/body.html | 4 + src/sentier_diagnostics/page/diagnostics.css | 11 + src/sentier_diagnostics/page/diagnostics.js | 350 ++++++++-- tests/js/page.test.js | 126 ++++ tests/test_matrix_page.py | 9 +- tests/test_modules.py | 11 +- tests/test_ranges.py | 301 +++++++++ 16 files changed, 2464 insertions(+), 205 deletions(-) create mode 100644 tests/test_ranges.py diff --git a/GLOSSARY.md b/GLOSSARY.md index 6043bc0..dc52f2f 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -9,6 +9,7 @@ The words this repository uses, each in one line. [SPEC.md](SPEC.md) says the re - **Step**: from one state to the next, with its kind, claim, tolerance and noise. - **Step 0**: the reproduction of the published results. The start, never the target. A chain that does not start from the published results has no step 0: its steps are numbered from 1. - **Chain**: the states in order and the steps between them. +- **Range**: a run of at least two consecutive steps, short of every step, compared as one: the state before its first step against the state after its last, judged as the whole way is. Its producer chooses which ranges a file holds. On the page, choosing several steps chooses a range. - **Pair**: one item in one indicator, before and after a step. - **Class**: what a pair is, by one rule: agrees, within noise, differs, beyond 10x, zero reference, zero result, sign change, near zero, missing. - **Moved**: a pair of class differs, beyond 10x, zero reference, zero result or sign change. Only these have a direction. diff --git a/SPEC.md b/SPEC.md index 15e6cc4..c350b50 100644 --- a/SPEC.md +++ b/SPEC.md @@ -88,6 +88,29 @@ that step, made up, and a test holds what it shows. **Order matters.** Where two steps touch the same results, each one's share depends on the order they were applied in. The file keeps the order; the page says so. +**Ranges: several steps together.** A reviewer of a chain of fixes asks what some of them +did together, not only what each did. A **range** is a run of at least two consecutive +steps, short of every step (that is the whole way): it compares the state before its first +step with the state after its last, and is judged as the whole way is (section 5.3): the +largest tolerance of its steps, no noise, and no verdict, since each claim is judged in its +own step. Its classes are worked out by the rule from those two states, never added up +from its steps: steps that each move 0.8 % under a tolerance of 1 % agree one by one, and +two of them together differ. + +**Decision: a run, not any set.** Each state is built on the one before it, so the only +comparisons a chain holds are between two of its states, and a set of steps with a gap, +such as the first and the third fix, was never built on its own. A page that is asked for +steps apart takes in the steps between them and says so; it never sums steps it cannot +see, and it never claims what a combination nobody built would give. Building every +combination is the producer's business: 11 fixes have 2,047 of them. + +**The producer chooses its ranges** (`ranges` of `chain.build`): `"all"`, a list of +`(first step, last step)` pairs (`chain.ranges_within` gives every run between two steps, +such as the fixes of a build), or none. Without a choice, a chain of at most 8 steps has +every range and a longer one none (`chain.AUTO_RANGES`): n steps have n(n-1)/2 - 1 ranges, +and each is a comparison of every item in every indicator. A description of CSV tables +says the same in its `ranges` key. + **One chain per reference.** A database with two references (sentier-bafu-agribalyse has ADEME's published results on ecoinvent and its own build on ecoinvent) gets one file per reference. A joint view is an open question (section 15). @@ -124,7 +147,8 @@ control characters, bounded lengths. | `rule` | The floors and the tolerance of the whole way (section 5) | | `states` | `[{id, label, about, kind, identity, join}]` in order. `identity` is a short table of texts (commit, release, machine); `join` is what the reader counted when it matched its rows to items: `{compared, unmatched, ambiguous, note}`, or null | | `steps` | `[{id, from, to, label, about, kind, explained, link, claim, tolerance, noise}]`, one fewer than the states, each from one state to the next | -| `counts` | `{steps: {step: {indicator: block}}, total: {indicator: block}}` | +| `ranges` | Optional. `[{id, steps, from, to, tolerance}]`: the runs of consecutive steps compared as one (section 3). `id` is `first..last`, `from` the state before the first step, `to` the state after the last, `tolerance` the largest of its steps. Absent where the file has none | +| `counts` | `{steps: {step: {indicator: block}}, total: {indicator: block}}`, and `ranges: {range: {indicator: block}}` where, and only where, the file has ranges | | `attribution` | `{indicator: {dominant: {step: n}, not_attributable: n, spread: n, unexplained_moved: n}}` (section 7) | | `items` | The listed items, worst first (section 10.4) | | `items_count` | `{all, qualifying, listed, not_listed}` | @@ -146,15 +170,16 @@ A **block** counts one indicator in one step, or over the whole way: "closer": 12, "further": 9} ``` -`verdicts` is null for a step without a claim and for the whole way. `closer` and +`verdicts` is null for a step without a claim, for the whole way and for a range. `closer` and `further` count, for a step after step 0, the moved values that came closer to or went -further from the published results. They are null for step 0 and the whole way, null for +further from the published results. They are null for step 0, the whole way and a range, null for every step of a chain whose first state is not the published results (there is nothing to come closer to), and no page shows them as better or worse. An **item** holds `id, name, place, group, unit` (its reference unit), `values` (per indicator, one result per state, `null` where missing), and per indicator one class, -direction and band per step plus one for the whole way, the verdicts per step (or null +direction and band per step, then one for the whole way, then one per range in the order of +`ranges`; the verdicts per step (or null when no step has a claim), and `breakdowns` (`{step or "total": file name}`, or null). ### 4.3 The validator @@ -171,7 +196,8 @@ many were left out. A file that disagrees with its own rule is refused, not show It also **works the counts out again from the listed items.** Only a pair worth a look adds to the classes that moved, to missing (by side), to directions, bands, the verdicts "as claimed", "off claim", "not claimed" and "claimed, not moved", to `closer` and -`further`, and to the attribution; and every item with such a pair is worth a look. So +`further`, and to the attribution; and every item with such a pair, in a step, the whole +way or a range, is worth a look. So where nothing worth a look is left out (`not_listed` 0), these counts must equal what the listed items hold, and where some are left out, no count may be smaller than what the listed items hold. What only quiet pairs add to (agrees, within noise, near zero, and the @@ -202,16 +228,18 @@ writes it beside the file. ```json {"format": "sentier-diagnostics-matrix/1", - "of": {"title": "...", "states": ["a", "b", "c"], "indicators": ["x:climate", "x:water"], "steps": ["s0", "s1"]}, + "of": {"title": "...", "states": ["a", "b", "c"], "indicators": ["x:climate", "x:water"], "steps": ["s0", "s1"], + "ranges": []}, "items": [["p01", "Wheat", "FR", "crops", "kg"], ...], - "values": [[0.52, 0.53, 0.47, 1.2, 1.2, null], ...], + "values": [[0.52, 0.53, 0.47, 1.2, "=", null], ...], "classes": ["=Dd===", ...], "verdicts": ["a.==", ...]} ``` One row per item, in the order of the listed items (worst first): `[id, name, place, -group, unit]`; the results per indicator and state, indicator after indicator; per -indicator one code per step and one for the whole way; and, where a step has a claim, per +group, unit]`; the results per indicator and state, indicator after indicator, a result +that is the same number as the state before it (bit for bit) written `"="`; per indicator +one code per step, one for the whole way and one per range of `of.ranges`; and, where a step has a claim, per indicator one verdict code per step (`.` for a step without a claim; `verdicts` is null when no step has one). The class codes are `=` agrees, `~` within noise, `0` near zero, `-` missing, and for a pair that moved its class in upper case up and lower case down: `D` @@ -227,6 +255,12 @@ exactly, and every listed item must be in the matrix with the same name and resu `sentier-diagnostics check` does both when the matrix lies beside its file. A matrix holds up to 200,000 items and 64 MB. +The `"="` keeps a chain of fixes small: most fixes leave most results as they were, and +sentier-bafu's chain of 16 states over 11,947 datasets and 25 impact categories would +otherwise hold every number 16 times. It is a writing of the results, not a finding: a +reader writes each `=` out as the number before it, and `"="` that stands first in an +indicator or after a missing result is refused. + ## 5. The counting rule ### 5.1 One class per pair @@ -278,7 +312,9 @@ The **tolerance** says when two results agree. Default 1e-5, relative to the lar two runners differ by up to 2.8e-7 (measured in sentier-bafu) and two solvers by about 3e-7 (sentier-agribalyse), so differences of 1e-6 agree. Step 0 against published results takes the rounding of what was published (`basis: "published rounding"`, e.g. 5e-4 for four -significant digits). The whole way is counted with the largest tolerance of its steps. +significant digits). The whole way is counted with the largest tolerance of its steps, +and no noise: noise is measured between two builds of one state, and the whole way is not +one step. A range is counted the same way, with the largest tolerance of its own steps. The **noise** is measured, never assumed: the largest relative difference between two builds of one state, per indicator, over the items whose results lie beyond the floor in @@ -503,6 +539,20 @@ them, each closed until a reader opens it: the steps and the whole way (10.2), t values (10.4), the explanations and the rule (10.7). A host's page never offers to open a file; it says only why nothing is drawn. +**Several steps together.** Where the file has ranges, a reader chooses several steps: +Shift-click a second step (or Shift and an arrow key) for the steps from one to the other, +⌘- or Ctrl-click to add a step or take one off at an end, or turn on "Several steps" so +that a plain click does that (for a touch screen). The chips of the run are pressed, and a +step taken in only because it lies between two chosen ones is hatched. The matrix, the +distributions, the worst values and the drawer then show the range: the file's own counts +and classes of it, never a sum of its steps. Its line says which states it goes between, +which steps lie between the chosen ones and why they are taken in, and each step's claim +with what it found in that step alone; it says that a range has no noise and no verdict. +Every step chosen is the whole way. A run the file does not compare is said, with the runs +it does, and nothing changes; a step inside a run cannot be taken off, and the page says +so. The address keeps a range by its id (`#step=first..last`); an address that names a run +the file does not compare, or no comparison at all, opens on the whole way and says why. + The line of the chosen step names every verdict on a move with its count, "as claimed" first ("40 values moved as claimed, 2 off claim ◐"), and "Nothing moved, as claimed" only where every count is zero. It gives them weight, not colour: a verdict is not an approval @@ -639,6 +689,8 @@ the page script (`tests/js/page.test.js`), so the two cannot drift apart unnotic | A25 | A file is local unless its writer says otherwise | sentier-bafu, sentier-bafu-agribalyse | `test_a25` | | A26 | A pair on both sides of the floor that agrees was a zero result, and listed second worst | review of PR 2 | cases A26-* | | A27 | A factor too large for a float: Python and the page ordered the pair differently, the page wrote "×Infinity" | review of PR 2 | case A27 | +| A28 | Choosing several fixes did not change what the matrix and the distributions below it showed | sentier-bafu (Manuel, 17 November 2026) | `tests/test_ranges.py`; node "Shift-click chooses the steps from one to another together", "steps chosen apart take in the steps between them" | +| A29 | A run of steps was judged as the sum of its steps: two moves under the tolerance each, over it together, agreed | ranges | `test_a_range_moves_where_each_of_its_steps_agrees` | Also tested: the validator refuses a class, direction or verdict that contradicts the values, items out of order, counts that do not add up, unknown keys and other formats @@ -746,6 +798,7 @@ sentier-bafu-agribalyse wrote their requirements. What became of each: | Indicators not hardcoded | agribalyse | yes: from the file | | The file's own word for an indicator ("impact category") | bafu | yes: the optional `indicator` | | No step 0 in a chain that does not start from the published results | bafu | yes: its steps are numbered from 1 (section 10.2) | +| Choose any set of fixes at the top; the matrix and everything under it show those | bafu (from Manuel, 17 November 2026) | yes, as a run of steps: a set with a gap takes in the steps between, said on the page (section 3) | | Readable without JavaScript for the counts; 375 px wide | bafu-agribalyse | 375 px: yes, no sideways scroll of the page (tables scroll inside their frame; checked in a browser). Without JavaScript: the summary is Markdown; a no-script page is later | ## 15. Open questions diff --git a/examples/diagnostics.json b/examples/diagnostics.json index ebc727d..b3c9fe8 100644 --- a/examples/diagnostics.json +++ b/examples/diagnostics.json @@ -323,6 +323,60 @@ } } ], + "ranges": [ + { + "id": "step-0..fix-1", + "steps": [ + "step-0", + "fix-1" + ], + "from": "published", + "to": "fix-1", + "tolerance": 0.0005 + }, + { + "id": "step-0..rebuilt", + "steps": [ + "step-0", + "fix-1", + "rebuilt" + ], + "from": "published", + "to": "rebuilt", + "tolerance": 0.0005 + }, + { + "id": "fix-1..rebuilt", + "steps": [ + "fix-1", + "rebuilt" + ], + "from": "repro", + "to": "rebuilt", + "tolerance": 1e-05 + }, + { + "id": "fix-1..mapping-2", + "steps": [ + "fix-1", + "rebuilt", + "mapping-2" + ], + "from": "repro", + "to": "mapping-2", + "tolerance": 1e-05 + }, + { + "id": "rebuilt..mapping-2", + "steps": [ + "rebuilt", + "mapping-2" + ], + "from": "fix-1", + "to": "mapping-2", + "tolerance": 1e-05 + } + ], "counts": { "steps": { "step-0": { @@ -977,6 +1031,588 @@ "closer": null, "further": null } + }, + "ranges": { + "step-0..fix-1": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 2 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 9, + "within noise": 0, + "differs": 0, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 1, + "after": 0, + "both": 0 + }, + "directions": { + "up": 0, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 2, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "step-0..rebuilt": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 2 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 2 + }, + "missing": { + "before": 1, + "after": 1, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 2, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "fix-1..rebuilt": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 2 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 8, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 0, + "after": 1, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 8, + "within noise": 0, + "differs": 0, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 2, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 0, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "fix-1..mapping-2": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 4, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 1, + "sign change": 1, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 0, + "after": 1, + "both": 0 + }, + "directions": { + "up": 2, + "down": 3 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 2, + "beyond 10x": 1, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 3, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 1 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 1, + "zero result": 0, + "sign change": 0, + "near zero": 1, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 1 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "rebuilt..mapping-2": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 0, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 1, + "sign change": 1, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 0, + "after": 1, + "both": 0 + }, + "directions": { + "up": 1, + "down": 1 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 2, + "beyond 10x": 1, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 3, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 1 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 1, + "zero result": 0, + "sign change": 0, + "near zero": 1, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 1 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + } } }, "attribution": { @@ -1015,16 +1651,16 @@ } }, "items": [ - {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, - {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "missing", "missing", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up"], "x:water": [null, null, null, null, "up"], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25"], "x:water": [null, null, null, null, "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p01", "name": "Wheat", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.52, 0.520013, 0.468012, 0.468012, 0.468012], "x:water": [1.2, 1.2, 1.2, 1.2000001, 1.2000001], "x:tox": [2e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "down", null, null, "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.1-1.25", null, null, "down, factor 1.1-1.25"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "as claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": {"fix-1": "p01-fix-1.json"}}, - {"id": "p04", "name": "Oats", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.45, 0.45, 0.45, 0.45, 0.45], "x:water": [1.0, 1.0, 1.0, 1.025, 1.0455], "x:tox": [1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "differs", "within noise", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, "up", null, "up"], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, "up, factor 1-1.1", null, "up, factor 1-1.1"], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "within noise"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p06", "name": "Rye", "place": "PL", "group": "crops", "unit": "kg", "values": {"x:climate": [0.43, 0.43, 0.43, 0.43, null], "x:water": [null, 1.15, 1.15, 1.15, 1.15], "x:tox": [2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "missing", "missing"], "x:water": ["missing", "agrees", "agrees", "agrees", "missing"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not judged"], "x:water": ["not judged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p02", "name": "Maize", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.41, 0.41, 0.41, 0.41, 0.41], "x:water": [2.5, 2.500025, 2.500025, 2.500025, 2.500025], "x:tox": [1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "claimed, not moved"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} + {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change", "agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs", "agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down", "down", null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2", null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference", "near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "up", "up", null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result", "agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down", null, null, null, "down", "down"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x", "agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs", "differs", "differs", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up", "up", "up", null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10", null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1", null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down", "down", "down", "down", "down", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, + {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "missing", "missing", "differs", "agrees", "missing", "missing", "differs", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up", "up", "up", "up", "up", null], "x:water": [null, null, null, null, "up", null, null, null, "up", "up"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", null], "x:water": [null, null, null, null, "up, factor 1.1-1.25", null, null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p01", "name": "Wheat", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.52, 0.520013, 0.468012, 0.468012, 0.468012], "x:water": [1.2, 1.2, 1.2, 1.2000001, 1.2000001], "x:tox": [2e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "down", null, null, "down", "down", "down", "down", "down", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.1-1.25", null, null, "down, factor 1.1-1.25", "down, factor 1.1-1.25", "down, factor 1.1-1.25", "down, factor 1.1-1.25", "down, factor 1.1-1.25", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "as claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": {"fix-1": "p01-fix-1.json"}}, + {"id": "p04", "name": "Oats", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.45, 0.45, 0.45, 0.45, 0.45], "x:water": [1.0, 1.0, 1.0, 1.025, 1.0455], "x:tox": [1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "differs", "within noise", "differs", "agrees", "differs", "differs", "differs", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, "up", null, "up", null, "up", "up", "up", "up"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, "up, factor 1-1.1", null, "up, factor 1-1.1", null, "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "within noise"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p06", "name": "Rye", "place": "PL", "group": "crops", "unit": "kg", "values": {"x:climate": [0.43, 0.43, 0.43, 0.43, null], "x:water": [null, 1.15, 1.15, 1.15, 1.15], "x:tox": [2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "missing", "missing", "agrees", "agrees", "agrees", "missing", "missing"], "x:water": ["missing", "agrees", "agrees", "agrees", "missing", "missing", "missing", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not judged"], "x:water": ["not judged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p02", "name": "Maize", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.41, 0.41, 0.41, 0.41, 0.41], "x:water": [2.5, 2.500025, 2.500025, 2.500025, 2.500025], "x:tox": [1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "claimed, not moved"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} ], "items_count": { "all": 10, diff --git a/examples/local/diagnostics.json b/examples/local/diagnostics.json index def56d0..d07858f 100644 --- a/examples/local/diagnostics.json +++ b/examples/local/diagnostics.json @@ -323,6 +323,60 @@ } } ], + "ranges": [ + { + "id": "step-0..fix-1", + "steps": [ + "step-0", + "fix-1" + ], + "from": "published", + "to": "fix-1", + "tolerance": 0.0005 + }, + { + "id": "step-0..rebuilt", + "steps": [ + "step-0", + "fix-1", + "rebuilt" + ], + "from": "published", + "to": "rebuilt", + "tolerance": 0.0005 + }, + { + "id": "fix-1..rebuilt", + "steps": [ + "fix-1", + "rebuilt" + ], + "from": "repro", + "to": "rebuilt", + "tolerance": 1e-05 + }, + { + "id": "fix-1..mapping-2", + "steps": [ + "fix-1", + "rebuilt", + "mapping-2" + ], + "from": "repro", + "to": "mapping-2", + "tolerance": 1e-05 + }, + { + "id": "rebuilt..mapping-2", + "steps": [ + "rebuilt", + "mapping-2" + ], + "from": "fix-1", + "to": "mapping-2", + "tolerance": 1e-05 + } + ], "counts": { "steps": { "step-0": { @@ -977,6 +1031,588 @@ "closer": null, "further": null } + }, + "ranges": { + "step-0..fix-1": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 2 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 9, + "within noise": 0, + "differs": 0, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 1, + "after": 0, + "both": 0 + }, + "directions": { + "up": 0, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 2, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "step-0..rebuilt": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 2 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 2 + }, + "missing": { + "before": 1, + "after": 1, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 2, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "fix-1..rebuilt": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 2 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 8, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 0, + "after": 1, + "both": 0 + }, + "directions": { + "up": 1, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 8, + "within noise": 0, + "differs": 0, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 2, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 0, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "fix-1..mapping-2": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 4, + "within noise": 0, + "differs": 3, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 1, + "sign change": 1, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 0, + "after": 1, + "both": 0 + }, + "directions": { + "up": 2, + "down": 3 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 1, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 2, + "beyond 10x": 1, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 3, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 1 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 1, + "zero result": 0, + "sign change": 0, + "near zero": 1, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 1 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + }, + "rebuilt..mapping-2": { + "x:climate": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 0, + "beyond 10x": 0, + "zero reference": 0, + "zero result": 1, + "sign change": 1, + "near zero": 0, + "missing": 1 + }, + "missing": { + "before": 0, + "after": 1, + "both": 0 + }, + "directions": { + "up": 1, + "down": 1 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:water": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 2, + "beyond 10x": 1, + "zero reference": 0, + "zero result": 0, + "sign change": 0, + "near zero": 0, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 3, + "down": 0 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 0, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 1, + "up, factor 1.1-1.25": 1, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 1 + }, + "verdicts": null, + "closer": null, + "further": null + }, + "x:tox": { + "pairs": 10, + "classes": { + "agrees": 7, + "within noise": 0, + "differs": 1, + "beyond 10x": 0, + "zero reference": 1, + "zero result": 0, + "sign change": 0, + "near zero": 1, + "missing": 0 + }, + "missing": { + "before": 0, + "after": 0, + "both": 0 + }, + "directions": { + "up": 1, + "down": 1 + }, + "bands": { + "down, factor over 10": 0, + "down, factor 2-10": 0, + "down, factor 1.25-2": 1, + "down, factor 1.1-1.25": 0, + "down, factor 1-1.1": 0, + "up, factor 1-1.1": 0, + "up, factor 1.1-1.25": 0, + "up, factor 1.25-2": 0, + "up, factor 2-10": 0, + "up, factor over 10": 0 + }, + "verdicts": null, + "closer": null, + "further": null + } + } } }, "attribution": { @@ -1015,12 +1651,12 @@ } }, "items": [ - {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, - {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "missing", "missing", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up"], "x:water": [null, null, null, null, "up"], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25"], "x:water": [null, null, null, null, "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} + {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change", "agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs", "agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down", "down", null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2", null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference", "near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "up", "up", null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result", "agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down", null, null, null, "down", "down"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x", "agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs", "differs", "differs", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up", "up", "up", null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10", null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1", null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down", "down", "down", "down", "down", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, + {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "missing", "missing", "differs", "agrees", "missing", "missing", "differs", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up", "up", "up", "up", "up", null], "x:water": [null, null, null, null, "up", null, null, null, "up", "up"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", null], "x:water": [null, null, null, null, "up, factor 1.1-1.25", null, null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} ], "items_count": { "all": 10, diff --git a/examples/local/matrix.json b/examples/local/matrix.json index 7945f66..17e4ef5 100644 --- a/examples/local/matrix.json +++ b/examples/local/matrix.json @@ -1,4 +1,4 @@ -{"format": "sentier-diagnostics-matrix/1", "of": {"title": "A made-up chain: published results to the current build", "states": ["published", "repro", "fix-1", "rebuilt", "mapping-2"], "indicators": ["x:climate", "x:water", "x:tox"], "steps": ["step-0", "fix-1", "rebuilt", "mapping-2"]}, +{"format": "sentier-diagnostics-matrix/1", "of": {"title": "A made-up chain: published results to the current build", "states": ["published", "repro", "fix-1", "rebuilt", "mapping-2"], "indicators": ["x:climate", "x:water", "x:tox"], "steps": ["step-0", "fix-1", "rebuilt", "mapping-2"], "ranges": ["step-0..fix-1", "step-0..rebuilt", "fix-1..rebuilt", "fix-1..mapping-2", "rebuilt..mapping-2"]}, "items": [ ["p08","Compost, used as fertiliser","CH","waste","kg"], ["p09","Machine hour, harvesting","CH","services","h"], @@ -12,28 +12,28 @@ ["p02","Maize","FR","crops","kg"] ], "values": [ - [-0.5,-0.5,-0.5,-0.5,0.2,0.05,0.05,0.05,0.05,0.05,-2e-06,-2e-06,-2e-06,-2e-06,-4e-06], - [42.0,42.00042,42.00042,42.00042,42.00042,0.9,0.9,0.9,0.9,0.9,0.0,0.0,0.0,0.0,4e-07], - [0.03,0.03,0.03,0.03,0.0,0.0004,0.0004,0.0004,0.0004,0.0004,3e-09,3e-09,3e-09,3e-09,3e-09], - [1.3,1.3,1.3,1.3,1.3,0.02,0.02,0.02,0.02,0.5,2.1e-07,2.3e-07,2.3e-07,2.3e-07,2.3e-07], - [1.9,1.9,0.95,0.95,0.95,3.4,3.4,3.4,3.4,3.4,1e-12,1e-12,1e-12,1e-12,3e-12], - [0.48,0.47999,0.575988,0.575988,0.575988,1.1,1.1,1.1,null,1.3,1.9e-07,1.9e-07,1.9e-07,1.9e-07,1.9e-07], - [0.52,0.520013,0.468012,0.468012,0.468012,1.2,1.2,1.2,1.2000001,1.2000001,2e-07,2.0000002e-07,2.0000002e-07,2.0000002e-07,2.0000002e-07], - [0.45,0.45,0.45,0.45,0.45,1.0,1.0,1.0,1.025,1.0455,1.7e-07,1.7e-07,1.7e-07,1.7e-07,1.7e-07], - [0.43,0.43,0.43,0.43,null,null,1.15,1.15,1.15,1.15,2.1e-07,2.1e-07,2.1e-07,2.1e-07,2.1e-07], - [0.41,0.41,0.41,0.41,0.41,2.5,2.500025,2.500025,2.500025,2.500025,1.8e-07,1.8e-07,1.8e-07,1.8e-07,1.8e-07] + [-0.5,"=","=","=",0.2,0.05,"=","=","=","=",-2e-06,"=","=","=",-4e-06], + [42.0,42.00042,"=","=","=",0.9,"=","=","=","=",0.0,"=","=","=",4e-07], + [0.03,"=","=","=",0.0,0.0004,"=","=","=","=",3e-09,"=","=","=","="], + [1.3,"=","=","=","=",0.02,"=","=","=",0.5,2.1e-07,2.3e-07,"=","=","="], + [1.9,"=",0.95,"=","=",3.4,"=","=","=","=",1e-12,"=","=","=",3e-12], + [0.48,0.47999,0.575988,"=","=",1.1,"=","=",null,1.3,1.9e-07,"=","=","=","="], + [0.52,0.520013,0.468012,"=","=",1.2,"=","=",1.2000001,"=",2e-07,2.0000002e-07,"=","=","="], + [0.45,"=","=","=","=",1.0,"=","=",1.025,1.0455,1.7e-07,"=","=","=","="], + [0.43,"=","=","=",null,null,1.15,"=","=","=",2.1e-07,"=","=","=","="], + [0.41,"=","=","=","=",2.5,2.500025,"=","=","=",1.8e-07,"=","=","=","="] ], "classes": [ - "===SS========dd", - "==========000RR", - "===tt==========", - "========BBD===D", - "=d==d=====00000", - "=D==D==--D=====", - "=d==d==========", - "=======D~D=====", - "===---===-=====", - "===============" + "===SS===SS=============dd===dd", + "====================000RR000RR", + "===tt===tt====================", + "=============BB===BBD===DDD===", + "=d==ddddd===========0000000000", + "=D==DDDDD===--D=--DD==========", + "=d==ddddd=====================", + "============D~D=DDDD==========", + "===--===---===---=============", + "==============================" ], "verdicts": [ "==.n==.===.n", diff --git a/src/sentier_diagnostics/chain.py b/src/sentier_diagnostics/chain.py index 905b12a..c15f0dd 100644 --- a/src/sentier_diagnostics/chain.py +++ b/src/sentier_diagnostics/chain.py @@ -17,6 +17,12 @@ steps on either side of that state cannot be measured, and its total is counted as not attributable instead of being split. +**Ranges.** A run of consecutive steps, such as three fixes built one after another, is +compared too where the producer asks for it (`ranges`): the state before its first step +against the state after its last, judged as the whole way is (the largest tolerance of its +steps, no noise, no verdict). A page then shows any run of steps as one comparison of two +built states: what those steps did together, never a sum of steps it cannot see. + `build` writes the whole file and checks it (`fileformat.errors`); `write` stores it. """ @@ -142,6 +148,66 @@ def explanation(text: str, by: dict, *, step: str | None = None, indicator: str } +#: Without a choice, a chain of at most this many steps has every range, and a longer one none: +#: the ranges of n steps are n(n-1)/2 - 1, each a comparison of every item in every indicator. +AUTO_RANGES = 8 + + +def ranges_within(steps: list[dict], first: str, last: str) -> list[tuple[str, str]]: + """Every run of at least two consecutive steps from `first` to `last`, as `(first, last)` + pairs: what `ranges` takes for the steps of one kind, such as the fixes of a build. + + >>> ranges_within([{"id": i} for i in "abcd"], "b", "d") + [('b', 'c'), ('b', 'd'), ('c', 'd')] + """ + ids = [s["id"] for s in steps] + for one in (first, last): + if one not in ids: + raise ValueError(f"ranges within {first!r} and {last!r}: no step {one!r}") + i, j = ids.index(first), ids.index(last) + if j <= i: + raise ValueError(f"ranges within {first!r} and {last!r}: the first step comes after the last") + return [(ids[a], ids[b]) for a in range(i, j + 1) for b in range(a + 1, j + 1)] + + +def _ranges(said, out_steps: list[dict]) -> list[dict]: + """The ranges of a chain, as the file holds them, from what the producer asked for: + "auto", "all", None, or `(first step id, last step id)` pairs.""" + ids = [s["id"] for s in out_steps] + n = len(ids) + if said == "auto": + said = "all" if n <= AUTO_RANGES else None + if said is None: + return [] + if said == "all": + pairs = [(a, b) for a in range(n) for b in range(a + 1, n) if (a, b) != (0, n - 1)] + elif isinstance(said, str): + raise ValueError(f"`ranges` is \"auto\", \"all\", None or a list of (first, last) step ids, not {said!r}") + else: + pairs = [] + for one in said: + if not (isinstance(one, (list, tuple)) and len(one) == 2 and all(x in ids for x in one)): + raise ValueError(f"a range is (first step id, last step id) of this chain, not {one!r}") + a, b = ids.index(one[0]), ids.index(one[1]) + if b <= a: + raise ValueError(f"range {one[0]}..{one[1]}: a range runs over at least two steps, the first first") + if (a, b) == (0, n - 1): + raise ValueError(f"range {one[0]}..{one[1]}: every step is the whole way, counted as the total") + if (a, b) in pairs: + raise ValueError(f"range {one[0]}..{one[1]} is asked for twice") + pairs.append((a, b)) + return [ + { + "id": f"{ids[a]}..{ids[b]}", + "steps": ids[a : b + 1], + "from": out_steps[a]["from"], + "to": out_steps[b]["to"], + "tolerance": max(s["tolerance"]["value"] for s in out_steps[a : b + 1]), + } + for a, b in pairs + ] + + def _indicator(entry) -> dict: if isinstance(entry, Mapping): found = {k: entry.get(k) for k in ("id", "name", "short", "unit")} @@ -212,6 +278,7 @@ def _build( notes: Iterable[str] = (), breakdowns: Mapping[str, Mapping[str, str]] | None = None, matrix_file: str | None = None, + ranges="auto", ) -> tuple[dict, dict | None]: """A whole chain, counted, judged, attributed and checked, and its matrix where `matrix_file` names one. @@ -233,6 +300,10 @@ def _build( says it may be published). The tool checks only that it is one of the two. - `breakdowns`: `{item id: {step id or "total": file name}}`. - `matrix_file`: the name of the full matrix, for a local file of items; None for none. + - `ranges`: the runs of consecutive steps compared as one: "all" (every run of at least + two steps but the whole way), a list of `(first step id, last step id)` pairs + (`ranges_within` gives every run between two steps), None for none, or "auto" (the + default): every run where the chain has at most `AUTO_RANGES` steps, else none. """ if matrix_file is not None and (tier != "items" or audience != "local"): raise ValueError("only a local file of items has a matrix: a public file keeps the listed items only") @@ -291,45 +362,52 @@ def _build( }) # fmt: skip total_tolerance = max(s["tolerance"]["value"] for s in out_steps) published_first = states[0].get("kind") == "published" - - def judged(k, indicator, item): - """Class, direction, band and verdict of one item in one step (k) or the total (None).""" - first, last = (order[0], order[-1]) if k is None else (order[k], order[k + 1]) + out_ranges = _ranges(ranges, out_steps) + nsteps = len(out_steps) + + # every comparison, in the order an item lists them: each step, the whole way, each range; + # as (first state, last state, tolerance, noise by indicator or None, claim or None) + compared = [] + for k, one in enumerate(out_steps): + said = one["noise"] + by = (said["by"] or {}) if said["measured"] else None + compared.append((order[k], order[k + 1], one["tolerance"]["value"], by, steps[k].get("claim"))) + compared.append((order[0], order[-1], total_tolerance, None, None)) + compared += [(r["from"], r["to"], r["tolerance"], None, None) for r in out_ranges] + seen = {} # a judgment is one of a few dozen: every pair refers to one of them + + def judged(c, indicator, item): + """Class, direction, band and verdict of one item in one comparison.""" + first, last, tol, by, said_claim = compared[c] before, after = table[first][indicator].get(item), table[last][indicator].get(item) - if k is None: - level, tol = None, total_tolerance - else: - said = out_steps[k]["noise"] - level = (said["by"] or {}).get(indicator) if said["measured"] else None - tol = out_steps[k]["tolerance"]["value"] + level = by.get(indicator) if by is not None else None floor = floor_table[(indicator, units[item])] kind, way, where = rule.judge(before, after, floor=floor, tolerance=tol, noise=level) said_verdict = None - if k is not None and steps[k].get("claim"): - entries = claims.entries_for(steps[k]["claim"], indicator) - covering = [e for e in entries if claims.covers(e, item, indicator)] + if said_claim: + covering = [e for e in claims.entries_for(said_claim, indicator) if claims.covers(e, item, indicator)] said_verdict = claims.verdict(kind, before, after, way, covering) - return before, after, kind, way, where, said_verdict - - # every pair, once - found = { - (k, indicator, item): judged(k, indicator, item) - for k in [*range(len(out_steps)), None] - for indicator in ids - for item in items - } + key = (kind, way, where, said_verdict) + return seen.setdefault(key, key) + + # every pair, once: `found[(comparison, indicator)][n]` is the judgment of `items[n]` + found = {(c, i): [judged(c, i, item) for item in items] for c in range(len(compared)) for i in ids} - def block(k, indicator): + def ends(c, indicator, item): + return table[compared[c][0]][indicator].get(item), table[compared[c][1]][indicator].get(item) + + def block(c, indicator): classes = dict.fromkeys(rule.CLASSES, 0) missing = dict.fromkeys(fileformat.MISSING_SIDES, 0) bands = dict.fromkeys(rule.BANDS, 0) ways = dict.fromkeys(rule.DIRECTIONS, 0) - verdicts = dict.fromkeys(claims.VERDICTS, 0) if k is not None and steps[k].get("claim") else None + verdicts = dict.fromkeys(claims.VERDICTS, 0) if compared[c][4] else None closer = further = None - if published_first and k not in (None, 0): + if published_first and 0 < c < nsteps: closer = further = 0 - for item in items: - before, after, kind, way, where, said = found[(k, indicator, item)] + for n, item in enumerate(items): + kind, way, where, said = found[(c, indicator)][n] + before, after = ends(c, indicator, item) classes[kind] += 1 if kind == rule.MISSING: missing["both" if before is None and after is None else "before" if before is None else "after"] += 1 @@ -350,19 +428,21 @@ def block(k, indicator): counts = { "steps": {s["id"]: {i: block(k, i) for i in ids} for k, s in enumerate(out_steps)}, - "total": {i: block(None, i) for i in ids}, + "total": {i: block(nsteps, i) for i in ids}, } + if out_ranges: + counts["ranges"] = {r["id"]: {i: block(nsteps + 1 + j, i) for i in ids} for j, r in enumerate(out_ranges)} # attribution: which step carries the largest share of each item's whole difference attribution = {} for indicator in ids: dominant = {s["id"]: 0 for s in out_steps} not_attributable = spread = unexplained_moved = 0 - for item in items: - kinds = [found[(k, indicator, item)][2] for k in range(len(out_steps))] + for n, item in enumerate(items): + kinds = [found[(k, indicator)][n][0] for k in range(nsteps)] if any(not s["explained"] and kinds[k] in rule.MOVES for k, s in enumerate(out_steps)): unexplained_moved += 1 - if found[(None, indicator, item)][2] not in rule.MOVES: + if found[(nsteps, indicator)][n][0] not in rule.MOVES: continue series = [table[s][indicator].get(item) for s in order] if any(v is None for v in series): @@ -376,22 +456,27 @@ def block(k, indicator): attribution[indicator] = {"dominant": dominant, "not_attributable": not_attributable, "spread": spread, "unexplained_moved": unexplained_moved} # fmt: skip - # the items worth a look, the worst first + # the items worth a look, the worst first; a range counts as a step does + at = {item: n for n, item in enumerate(items)} + def worth(item): - for indicator in ids: - for k in [*range(len(out_steps)), None]: - _, _, kind, _, _, said = found[(k, indicator, item)] - if kind not in rule.QUIET or said == claims.NOT_MOVED: - return True - return False + n = at[item] + return any( + found[(c, i)][n][0] not in rule.QUIET or found[(c, i)][n][3] == claims.NOT_MOVED + for i in ids + for c in range(len(compared)) + ) + + ranks = {} def worst(item): - keys = [] - for indicator in ids: - for k in [*range(len(out_steps)), None]: - before, after, kind, *_ = found[(k, indicator, item)] - keys.append(rule.severity(before, after, kind)) - return (min(keys), item) + if item not in ranks: + n = at[item] + ranks[item] = ( + min(rule.severity(*ends(c, i, item), found[(c, i)][n][0]) for i in ids for c in range(len(compared))), + item, + ) + return ranks[item] qualifying = sorted((item for item in items if worth(item)), key=worst) shown = qualifying[: max(0, listed)] if tier == "items" else [] @@ -399,6 +484,7 @@ def worst(item): any_claim = any(s.get("claim") for s in steps) def record_of(item): + n = at[item] about_item = names.get(item) or {} record = { "id": item, @@ -414,12 +500,12 @@ def record_of(item): "breakdowns": dict(breakdowns[item]) if item in breakdowns else None, } for indicator in ids: - row = [found[(k, indicator, item)] for k in [*range(len(out_steps)), None]] - record["classes"][indicator] = [r[2] for r in row] - record["directions"][indicator] = [r[3] for r in row] - record["bands"][indicator] = [r[4] for r in row] + row = [found[(c, indicator)][n] for c in range(len(compared))] + record["classes"][indicator] = [r[0] for r in row] + record["directions"][indicator] = [r[1] for r in row] + record["bands"][indicator] = [r[2] for r in row] if any_claim: - record["verdicts"][indicator] = [r[5] for r in row[:-1]] + record["verdicts"][indicator] = [r[3] for r in row[:nsteps]] return record out_items = [record_of(item) for item in shown] @@ -447,6 +533,7 @@ def record_of(item): for s in states ], # fmt: skip "steps": out_steps, + **({"ranges": out_ranges} if out_ranges else {}), "counts": counts, "attribution": attribution, "items": out_items, diff --git a/src/sentier_diagnostics/fileformat.py b/src/sentier_diagnostics/fileformat.py index e00b03d..ac51df4 100644 --- a/src/sentier_diagnostics/fileformat.py +++ b/src/sentier_diagnostics/fileformat.py @@ -40,7 +40,7 @@ ORIGIN_KINDS = ("person", "code", "model") TOTAL = "total" #: Keys a file may leave out; each is null where it says nothing. -OPTIONAL_KEYS = {"matrix", "indicator"} +OPTIONAL_KEYS = {"matrix", "indicator", "ranges"} #: The largest file a page reads: it holds the whole file. MAX_BYTES = 12 * 1024 * 1024 @@ -48,6 +48,8 @@ #: An entry of a claim may list as many items as a file may. MAX_SCOPE_ITEMS = MAX_ITEMS MAX_EXPLANATIONS, MAX_NOTES, MAX_IDENTITY = 500, 20, 12 +#: Every run of at least two of the 29 steps a file may have, but the whole way. +MAX_RANGES = 29 * 28 // 2 - 1 MAX_ID, MAX_LABEL, MAX_WORD, MAX_TEXT, MAX_LONG = 100, 80, 40, 600, 2000 FILE_NAME = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,99}\.json") @@ -61,6 +63,7 @@ STATE_KEYS = {"id", "label", "about", "kind", "identity", "join"} STEP_KEYS = {"id", "from", "to", "label", "about", "kind", "explained", "link", "claim", "tolerance", "noise"} # fmt: skip +RANGE_KEYS = {"id", "steps", "from", "to", "tolerance"} CLAIM_KEYS = {"text", "by", "reach", "scope"} SCOPE_KEYS = {"indicators", "items", "direction", "largest", "expect"} ORIGIN_KEYS = {"kind", "name", "model", "run_by"} @@ -378,6 +381,51 @@ def _steps(data, found, states, indicators, tier) -> list[dict]: return steps +def _ranges(data, found, steps) -> list[dict] | None: + """The ranges of a file: runs of consecutive steps, each compared as the whole way is + (SPEC section 5.5). None where they cannot be read; nothing where the file has none.""" + said = data.get("ranges") + if said is None: + return [] + if not isinstance(said, list) or not 0 < len(said) <= MAX_RANGES: + found.append(f"`ranges` is a list of 1 to {MAX_RANGES} ranges, or left out") + return None + ids = [s["id"] for s in steps] + seen = set() + for one in said: + if not ( + isinstance(one, dict) + and set(one) == RANGE_KEYS + and is_text(one["id"], 2 * MAX_ID + 2) + and isinstance(one["steps"], list) + and one["steps"] + and all(isinstance(x, str) for x in one["steps"]) + and is_share(one["tolerance"]) + ): + found.append(f"a range is not {{{', '.join(sorted(RANGE_KEYS))}}}") + return None + where, run = f"range {one['id']!r}", one["steps"] + first = ids.index(run[0]) if run[0] in ids else None + if first is None or run != ids[first : first + len(run)]: + found.append(f"{where}: its steps are not consecutive steps of this chain") + return None + last = first + len(run) - 1 + if len(run) < 2: + found.append(f"{where}: a range runs over at least two steps; one step is that step") + if len(run) == len(ids): + found.append(f"{where}: every step is the whole way, counted as the total") + if one["id"] != f"{run[0]}..{run[-1]}": + found.append(f"{where}: the id of a range is its first and last step, {run[0]}..{run[-1]}") + if one["id"] in seen or one["id"] in ids or one["id"] == TOTAL: + found.append(f"{where}: its id is the id of another range, of a step, or of the total") + seen.add(one["id"]) + if (one["from"], one["to"]) != (steps[first]["from"], steps[last]["to"]): + found.append(f"{where}: it does not lead from the state before its first step to the state after its last") + if one["tolerance"] != max(s["tolerance"]["value"] for s in steps[first : last + 1]): + found.append(f"{where}: its tolerance is not the largest tolerance of its steps") + return said + + def _rule(data, found, indicators, states, steps) -> dict | None: said = data.get("rule") if not isinstance(said, dict) or set(said) != RULE_KEYS: @@ -477,20 +525,25 @@ def _block(block, where, step) -> list[str]: return found -def _counts(data, found, indicators, steps, total_pairs): +def _counts(data, found, indicators, steps, ranges, total_pairs): counts = data.get("counts") - if not isinstance(counts, dict) or set(counts) != {"steps", TOTAL}: - found.append("`counts` is not {steps, total}") + keys = {"steps", TOTAL} | ({"ranges"} if ranges else set()) + if not isinstance(counts, dict) or set(counts) != keys: + found.append(f"`counts` is not {{{', '.join(sorted(keys))}}}: ranges are counted where, and only where, the file has them") return {} by_step = counts["steps"] if not isinstance(by_step, dict) or set(by_step) != {s["id"] for s in steps}: found.append("`counts.steps` does not hold every step") return {} + by_range = counts.get("ranges") or {} + if ranges and (not isinstance(by_range, dict) or set(by_range) != {r["id"] for r in ranges}): + found.append("`counts.ranges` does not hold every range") + return {} published_first = data["states"][0]["kind"] == "published" blocks = {} - for k, one in enumerate([*steps, None]): - key = one["id"] if one else TOTAL - table = by_step[key] if one else counts[TOTAL] + compared = [(one["id"], by_step[one["id"]], one) for one in steps] + [(TOTAL, counts[TOTAL], None)] + compared += [(r["id"], by_range[r["id"]], None) for r in ranges] + for k, (key, table, one) in enumerate(compared): if not isinstance(table, dict) or set(table) != set(indicators): found.append(f"counts of {key!r} do not hold every indicator") return {} @@ -540,7 +593,7 @@ def _attribution(data, found, indicators, steps, blocks): found.append(f"{where}: does not account for every item whose total moved") -def _items(data, found, indicators, states, steps, floors, tier, blocks): +def _items(data, found, indicators, states, steps, ranges, floors, tier, blocks): listed = data.get("items") said = data.get("items_count") if not (isinstance(said, dict) and set(said) == COUNT_KEYS and all(map(is_count, said.values()))): @@ -556,6 +609,10 @@ def _items(data, found, indicators, states, steps, floors, tier, blocks): found.append("a file of counts holds no item") return [] nsteps = len(steps) + ncompared = nsteps + 1 + len(ranges) + # a range compares the state before its first step with the state after its last + first_of = {s["id"]: k for k, s in enumerate(steps)} + ends = [(first_of[r["steps"][0]], first_of[r["steps"][0]] + len(r["steps"])) for r in ranges] claims_by_step = [s["claim"] for s in steps] any_claim = any(claims_by_step) published_first = data["states"][0]["kind"] == "published" @@ -606,8 +663,10 @@ def _items(data, found, indicators, states, steps, floors, tier, blocks): and all(v is None or rule.is_value(v) for v in values)): # fmt: skip found.append(f"{where}, {indicator}: the results are not one finite number or null per state") return [] - if not all(isinstance(x, list) and len(x) == nsteps + 1 for x in (kinds, ways, bands)): - found.append(f"{where}, {indicator}: classes, directions and bands are one per step and the total") + if not all(isinstance(x, list) and len(x) == ncompared for x in (kinds, ways, bands)): + found.append( + f"{where}, {indicator}: classes, directions and bands are one per step, the total and each range" + ) return [] floor = floors.get((indicator, item["unit"])) if floor is None: @@ -617,13 +676,20 @@ def _items(data, found, indicators, states, steps, floors, tier, blocks): if any_claim and not (isinstance(verdicts, list) and len(verdicts) == nsteps): found.append(f"{where}, {indicator}: verdicts are one per step") return [] - for k in [*range(nsteps), None]: - at = nsteps if k is None else k - name = TOTAL if k is None else steps[k]["id"] - before, after = (values[0], values[-1]) if k is None else (values[k], values[k + 1]) - if k is None: + for at in range(ncompared): + k = at if at < nsteps else None # the step, or None for the total and a range + if at > nsteps: + one_range = ranges[at - nsteps - 1] + name = one_range["id"] + before, after = values[ends[at - nsteps - 1][0]], values[ends[at - nsteps - 1][1]] + tol, level = one_range["tolerance"], None + elif k is None: + name = TOTAL + before, after = values[0], values[-1] tol, level = data["rule"]["total_tolerance"], None else: + name = steps[k]["id"] + before, after = values[k], values[k + 1] tol = steps[k]["tolerance"]["value"] noise = steps[k]["noise"] level = (noise["by"] or {}).get(indicator) if noise["measured"] else None @@ -849,14 +915,17 @@ def _errors(data, found: list[str]) -> list[str]: steps = _steps(data, found, states, indicators, tier) if not steps: return found + ranges = _ranges(data, found, steps) + if ranges is None: + return found floors = _rule(data, found, indicators, states, steps) count = data["items_count"] total_pairs = count.get("all") if isinstance(count, dict) else None - blocks = _counts(data, found, indicators, steps, total_pairs) + blocks = _counts(data, found, indicators, steps, ranges, total_pairs) if floors is None or not blocks: return found _attribution(data, found, indicators, steps, blocks) - items = _items(data, found, indicators, states, steps, floors, tier, blocks) + items = _items(data, found, indicators, states, steps, ranges, floors, tier, blocks) _explanations(data, found, indicators, steps, set(items), tier) _matrix(data, found) return found diff --git a/src/sentier_diagnostics/from_tables.py b/src/sentier_diagnostics/from_tables.py index 538dd0a..2392431 100644 --- a/src/sentier_diagnostics/from_tables.py +++ b/src/sentier_diagnostics/from_tables.py @@ -20,6 +20,11 @@ "tier": "items" } +`ranges` says which runs of consecutive steps are compared as one: `"all"`, `"none"`, a +list of `[first step, last step]`, or `{"within": [first step, last step]}` for every run +between those two (a chain's fixes, say). Without it, a chain of at most 8 steps has every +run and a longer one none (`chain.AUTO_RANGES`). + A local file of items may also name its matrix of every item (`"matrix": "matrix.json"`, with `"audience": "local"`): `build_with_matrix` then gives it, and `sentier-diagnostics build` writes it beside the file. @@ -38,7 +43,7 @@ from . import chain, claims, fileformat, tables KEYS = {"title", "about", "item", "indicator", "indicators", "items", "states", "steps", "listed", "tier", "audience", - "claim_lists", "explanations", "notes", "floor_factor", "matrix"} # fmt: skip + "claim_lists", "explanations", "notes", "floor_factor", "matrix", "ranges"} # fmt: skip def _origin(said): @@ -141,12 +146,35 @@ def description_errors(spec) -> list[str]: found.append( f"{where}: a noise is {{states: [a, b]}} or {{tables: [{{label, results}}, {{label, results}}]}}" ) + said = spec.get("ranges") + step_ids = [one["id"] for one in steps] + + def run(v): + return isinstance(v, list) and len(v) == 2 and all(isinstance(x, str) and x in step_ids for x in v) + + if said is not None and not ( + said in ("all", "none") + or (isinstance(said, list) and all(map(run, said))) + or (isinstance(said, dict) and set(said) == {"within"} and run(said["within"])) + ): + found.append('`ranges` is "all", "none", a list of [first step, last step] or {"within": [first step, last step]}') explanations = spec.get("explanations", []) if not (isinstance(explanations, list) and all(_table(e, ("text",)) for e in explanations)): found.append("`explanations` is a list of {text, by, ...}") return found +def _ranges(said, steps): + """What `chain.build` takes for the description's `ranges`.""" + if said is None: + return "auto" + if said == "none": + return None + if isinstance(said, dict): + return chain.ranges_within(steps, *said["within"]) + return said if said == "all" else [tuple(one) for one in said] + + def build(path: Path) -> dict: """The diagnostics file a description and its tables give, checked. Every mistake is a ValueError that says what is wrong (`tables.TableError` for a table).""" @@ -289,6 +317,7 @@ def floor_by_item(indicator): floor_factor=floor_factor, explanations=explanations, notes=spec.get("notes", []), + ranges=_ranges(spec.get("ranges"), steps), ) if named is None: return chain.build(spec["title"], **given), None diff --git a/src/sentier_diagnostics/matrix.py b/src/sentier_diagnostics/matrix.py index f7c3e0d..119e067 100644 --- a/src/sentier_diagnostics/matrix.py +++ b/src/sentier_diagnostics/matrix.py @@ -6,7 +6,9 @@ build wants every item: the matrix is that, in a second file the page loads after it has drawn. It is compact (one row per item, the indicators and states named once) and it holds only what the rule gives: the results, and one code per pair for its class and direction, -and per step with a claim one code for its verdict. +and per step with a claim one code for its verdict. A result equal to the one of the state +before it, in the same indicator, is written `"="`: most steps of a chain of fixes leave most +results as they were, and a chain of 16 states would otherwise hold every number 16 times. Only a local file may name a matrix (`"matrix": {"file": ..., "items": n}`); a public file keeps the listed items only. `errors(m)` checks the shape; `against(m, data)` works every @@ -26,14 +28,18 @@ FORMAT = "sentier-diagnostics-matrix/1" FAMILY = "sentier-diagnostics-matrix/" KEYS = {"format", "of", "items", "values", "classes", "verdicts"} -OF_KEYS = {"title", "states", "indicators", "steps"} +OF_KEYS = {"title", "states", "indicators", "steps", "ranges"} + +#: A result written as the same number as the state before it, in the same indicator. +SAME = "=" #: A matrix is loaded after the page is drawn, not held inside it: it may be larger. MAX_BYTES = 64 * 1024 * 1024 MAX_ITEMS = 200_000 #: One character per pair: its class, and for a pair that moved its direction (upper case -#: up, lower case down). +#: up, lower case down). An item has one per indicator and comparison: each step, the whole +#: way, and each range of the file, in that order. CODES = { (rule.AGREES, None): "=", (rule.WITHIN_NOISE, None): "~", @@ -75,6 +81,37 @@ def code_of(kind: str, way: str | None) -> str: return CODES[(kind, way)] +def _same(a, b) -> bool: + """Two results that are the same number, bit for bit (0.0 and -0.0 are not).""" + return a is not None and b is not None and float(a).hex() == float(b).hex() + + +def compact(values: list) -> list: + """One indicator's results over the states, each equal to the one before it as `SAME`. + + >>> compact([1.5, 1.5, None, None, 2.0, 2.0, -0.0, 0.0]) + [1.5, '=', None, None, 2.0, '=', -0.0, 0.0] + """ + return [SAME if n and _same(v, values[n - 1]) else v for n, v in enumerate(values)] + + +def expand(values: list, nstates: int) -> list: + """The results of one item, every `SAME` written out again; raises ValueError where one + stands first in its indicator or after a missing result. + + >>> expand([1.5, "=", None, 2.0], 2) + [1.5, 1.5, None, 2.0] + """ + out = [] + for n, v in enumerate(values): + if v == SAME: + if n % nstates == 0 or out[-1] is None: + raise ValueError("`=` stands first in an indicator, or after a missing result") + v = out[-1] + out.append(v) + return out + + def make(data: Mapping, rows: list[dict]) -> dict: """A matrix of a diagnostics file from its rows, as `chain.build_with_matrix` gives them: `{id, name, place, group, unit, values: {indicator: [per state]}, classes, directions, @@ -88,6 +125,7 @@ def make(data: Mapping, rows: list[dict]) -> dict: "states": [s["id"] for s in data["states"]], "indicators": ids, "steps": [s["id"] for s in steps], + "ranges": [r["id"] for r in data.get("ranges") or []], }, "items": [], "values": [], @@ -96,7 +134,7 @@ def make(data: Mapping, rows: list[dict]) -> dict: } for row in rows: out["items"].append([row["id"], row["name"], row["place"], row["group"], row["unit"]]) - out["values"].append([v for i in ids for v in row["values"][i]]) + out["values"].append([v for i in ids for v in compact(row["values"][i])]) out["classes"].append( "".join( code_of(kind, way) for i in ids for kind, way in zip(row["classes"][i], row["directions"][i]) @@ -195,11 +233,12 @@ def _errors(m) -> list[str]: isinstance(of, dict) and set(of) == OF_KEYS and fileformat.is_text(of["title"], 120) - and all(isinstance(of[k], list) and all(fileformat.is_text(x, fileformat.MAX_ID) for x in of[k]) - for k in ("states", "indicators", "steps")) + and all(isinstance(of[k], list) and all(fileformat.is_text(x, 2 * fileformat.MAX_ID + 2) for x in of[k]) + for k in ("states", "indicators", "steps", "ranges")) ): # fmt: skip - return ["`of` is not {title, states, indicators, steps}"] + return ["`of` is not {title, states, indicators, steps, ranges}"] nstates, nind, nsteps = len(of["states"]), len(of["indicators"]), len(of["steps"]) + ncodes = nsteps + 1 + len(of["ranges"]) if nsteps != nstates - 1 or not nind: return ["`of`: one step fewer than states, and at least one indicator"] items = m["items"] @@ -223,13 +262,15 @@ def _errors(m) -> list[str]: seen.add(row[0]) values = m["values"][at] if not (isinstance(values, list) and len(values) == nind * nstates - and all(v is None or rule.is_value(v) for v in values)): # fmt: skip - return [f"item {row[0]!r}: not one finite number or null per indicator and state"] + and all(v is None or v == SAME or rule.is_value(v) for v in values)): # fmt: skip + return [f"item {row[0]!r}: not one finite number, `=` or null per indicator and state"] + try: + expand(values, nstates) + except ValueError as error: + return [f"item {row[0]!r}: {error}"] codes = m["classes"][at] - if not ( - isinstance(codes, str) and len(codes) == nind * (nsteps + 1) and all(c in DECODE for c in codes) - ): - return [f"item {row[0]!r}: not one class code per indicator, step and the whole way"] + if not (isinstance(codes, str) and len(codes) == nind * ncodes and all(c in DECODE for c in codes)): + return [f"item {row[0]!r}: not one class code per indicator, step, the whole way and range"] if has_claims: said = m["verdicts"][at] if not (isinstance(said, str) and len(said) == nind * nsteps @@ -257,21 +298,26 @@ def _against(m: Mapping, data: Mapping) -> list[str]: ids = [i["id"] for i in data["indicators"]] order = [s["id"] for s in data["states"]] steps = data["steps"] - of = {"title": data["title"], "states": order, "indicators": ids, "steps": [s["id"] for s in steps]} + ranges = data.get("ranges") or [] + of = {"title": data["title"], "states": order, "indicators": ids, "steps": [s["id"] for s in steps], + "ranges": [r["id"] for r in ranges]} # fmt: skip if m["of"] != of: - return ["it is the matrix of another file: its title, states, indicators or steps differ"] + return ["it is the matrix of another file: its title, states, indicators, steps or ranges differ"] n = len(m["items"]) if named["items"] != n: found.append(f"the diagnostics file says {named['items']} items, the matrix holds {n}") if data["items_count"]["all"] != n: found.append(f"the diagnostics file counts {data['items_count']['all']} items, the matrix holds {n}") nstates, nsteps = len(order), len(steps) + ncodes = nsteps + 1 + len(ranges) + first_of = {s["id"]: k for k, s in enumerate(steps)} + ends = [(first_of[r["steps"][0]], first_of[r["steps"][0]] + len(r["steps"])) for r in ranges] floors = {(f["indicator"], f["unit"]): f["value"] for f in data["rule"]["floors"]} published_first = data["states"][0]["kind"] == "published" listed = {item["id"]: item for item in data["items"]} # what the counts and attribution must be, counted from every item - def empty(k): + def empty(k): # k: the step, or None for the total and a range return { "pairs": 0, "classes": dict.fromkeys(rule.CLASSES, 0), @@ -283,7 +329,7 @@ def empty(k): "further": 0 if published_first and k not in (None, 0) else None, } - counted = {(k, i): empty(k) for k in [*range(nsteps), None] for i in ids} + counted = {(at, i): empty(at if at < nsteps else None) for at in range(ncodes) for i in ids} attributed = { i: { "dominant": {s["id"]: 0 for s in steps}, @@ -296,7 +342,7 @@ def empty(k): qualifying = 0 for at, (item_id, name, place, group, unit) in enumerate(m["items"]): where = f"item {item_id!r}" - flat, codes = m["values"][at], m["classes"][at] + flat, codes = expand(m["values"][at], nstates), m["classes"][at] said_verdicts = m["verdicts"][at] if m["verdicts"] is not None else None worth = False values_of = {} @@ -307,24 +353,29 @@ def empty(k): if floor is None: return [f"{where}, {indicator}: the file holds no floor for unit {unit!r}"] kinds = [] - for k in [*range(nsteps), None]: - at_k = nsteps if k is None else k - before, after = (values[0], values[-1]) if k is None else (values[k], values[k + 1]) - if k is None: + for at_k in range(ncodes): + k = at_k if at_k < nsteps else None + if at_k > nsteps: + one_range = ranges[at_k - nsteps - 1] + before, after = values[ends[at_k - nsteps - 1][0]], values[ends[at_k - nsteps - 1][1]] + tol, level = one_range["tolerance"], None + elif k is None: + before, after = values[0], values[-1] tol, level = data["rule"]["total_tolerance"], None else: + before, after = values[k], values[k + 1] tol = steps[k]["tolerance"]["value"] noise = steps[k]["noise"] level = (noise["by"] or {}).get(indicator) if noise["measured"] else None kind, way, band = rule.judge(before, after, floor=floor, tolerance=tol, noise=level) - code = codes[x * (nsteps + 1) + at_k] + code = codes[x * ncodes + at_k] if code != code_of(kind, way): - step_name = "the whole way" if k is None else steps[k]["id"] + step_name = steps[k]["id"] if k is not None else "the whole way" if at_k == nsteps else ranges[at_k - nsteps - 1]["id"] return [ f"{where}, {indicator}, {step_name}: written as {DECODE[code]}, the rule gives {kind}/{way}" ] kinds.append(kind) - block = counted[(k, indicator)] + block = counted[(at_k, indicator)] block["pairs"] += 1 block["classes"][kind] += 1 if kind == rule.MISSING: @@ -397,13 +448,16 @@ def empty(k): f"the diagnostics file counts {data['items_count']['qualifying']} items worth a look, " f"the matrix holds {qualifying}" ) - for (k, indicator), block in counted.items(): - name = fileformat.TOTAL if k is None else steps[k]["id"] - written = ( - data["counts"][fileformat.TOTAL][indicator] - if k is None - else data["counts"]["steps"][name][indicator] - ) + for (at, indicator), block in counted.items(): + if at < nsteps: + name = steps[at]["id"] + written = data["counts"]["steps"][name][indicator] + elif at == nsteps: + name = fileformat.TOTAL + written = data["counts"][fileformat.TOTAL][indicator] + else: + name = ranges[at - nsteps - 1]["id"] + written = data["counts"]["ranges"][name][indicator] for key in block: if block[key] != written[key]: found.append(f"counts of {name!r} in {indicator!r}: `{key}` is not what the matrix holds") diff --git a/src/sentier_diagnostics/page/body.html b/src/sentier_diagnostics/page/body.html index 0c8b053..508b9f3 100644 --- a/src/sentier_diagnostics/page/body.html +++ b/src/sentier_diagnostics/page/body.html @@ -21,6 +21,10 @@

Open a file

Comparison
+

Each cell is the result after divided by the result before, for one item and indicator, in the comparison chosen above; diff --git a/src/sentier_diagnostics/page/diagnostics.css b/src/sentier_diagnostics/page/diagnostics.css index 53d0361..cab8f51 100644 --- a/src/sentier_diagnostics/page/diagnostics.css +++ b/src/sentier_diagnostics/page/diagnostics.css @@ -77,6 +77,17 @@ .sentier-diagnostics .sd-chip-flag { font-weight: 800; color: var(--sd-fail); } .sentier-diagnostics .sd-chip[aria-pressed="true"] .sd-chip-flag { color: inherit; } .sentier-diagnostics .sd-chip-mark { font-size: var(--sd-t-xs); } +.sentier-diagnostics .sd-chip { user-select: none; -webkit-user-select: none; } +/* a step taken into a run only because it lies between two chosen ones: pressed, and hatched */ +.sentier-diagnostics .sd-chip.sd-between[aria-pressed="true"] { border-style: dashed; + background: repeating-linear-gradient(135deg, var(--sd-accent) 0 6px, color-mix(in srgb, var(--sd-accent) 72%, var(--sd-surface)) 6px 12px); } +.sentier-diagnostics .sd-pick { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sd-s2) var(--sd-s3); margin: 0; font-size: var(--sd-t-xs); } +.sentier-diagnostics .sd-pick[hidden] { display: none; } +.sentier-diagnostics .sd-switch { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 600; cursor: pointer; } +.sentier-diagnostics .sd-notice { padding: 0.2rem 0.5rem; border-left: 3px solid var(--sd-line-strong); background: var(--sd-surface); } +.sentier-diagnostics .sd-claims { margin: 0.25rem 0; padding-left: 1.2rem; } +.sentier-diagnostics .sd-claims > li + li { margin-top: 0.2rem; } +.sentier-diagnostics .sd-drawer tr.sd-in-run > * { background: var(--sd-paper-deep); } /* the line of the chosen step: what it compares, its claim and what the claim found, its rule */ .sentier-diagnostics .sd-step { margin: 0 0 var(--sd-s3); padding: var(--sd-s2) var(--sd-s4); border-left: 3px solid var(--sd-accent); border-radius: 0 var(--sd-radius) var(--sd-radius) 0; background: var(--sd-paper-deep); font-size: var(--sd-t-sm); } diff --git a/src/sentier_diagnostics/page/diagnostics.js b/src/sentier_diagnostics/page/diagnostics.js index 90ac829..7625974 100644 --- a/src/sentier_diagnostics/page/diagnostics.js +++ b/src/sentier_diagnostics/page/diagnostics.js @@ -59,6 +59,7 @@ '~': 'within noise', '=': 'unchanged', '?': 'not judged' }; var NO_CLAIM = '.'; + var SAME = '='; // matrix.SAME: a result equal to the one of the state before it // ------------------------------------------------------------------ pure helpers @@ -359,9 +360,32 @@ typeof d.indicator.many === 'string')) return 'the indicator word of the file is not {one, many}'; if (d.steps.length !== d.states.length - 1) return 'the file has not one step fewer than states'; if (!d.counts.steps || !d.counts.total) return 'the counts of the file are not {steps, total}'; + if (d.ranges !== undefined && d.ranges !== null) { + if (!Array.isArray(d.ranges)) return 'the ranges of the file are not a list'; + if (!d.counts.ranges || typeof d.counts.ranges !== 'object') return 'the file has ranges and no counts of them'; + for (var r = 0; r < d.ranges.length; r++) { + var one = d.ranges[r]; + if (!one || typeof one.id !== 'string' || !Array.isArray(one.steps) || one.steps.length < 2 || !d.counts.ranges[one.id]) return 'a range of the file is not {id, steps, from, to, tolerance} with its counts'; + } + } return null; } + // one item's results from a matrix row, each `=` written out as the result before it; + // null where a `=` stands first in an indicator or after a missing result + function expandValues(values, ns) { + var out = []; + for (var i = 0; i < values.length; i++) { + var v = values[i]; + if (v === SAME) { + if (i % ns === 0 || out[i - 1] === null) return null; + v = out[i - 1]; + } + out.push(v); + } + return out; + } + function sameList(a, b) { if (!Array.isArray(a) || a.length !== b.length) return false; for (var i = 0; i < a.length; i++) if (a[i] !== b[i]) return false; @@ -377,8 +401,9 @@ var of = m.of || {}; var ids = d.indicators.map(function (i) { return i.id; }); if (of.title !== d.title || !sameList(of.states, d.states.map(function (s) { return s.id; })) || - !sameList(of.indicators, ids) || !sameList(of.steps, d.steps.map(function (s) { return s.id; }))) { - return 'it is the matrix of another file: its title, states, indicators or steps differ'; + !sameList(of.indicators, ids) || !sameList(of.steps, d.steps.map(function (s) { return s.id; })) || + !sameList(of.ranges, (d.ranges || []).map(function (r) { return r.id; }))) { + return 'it is the matrix of another file: its title, states, indicators, steps or ranges differ'; } if (!Array.isArray(m.items) || m.items.length > MATRIX_MAX_ITEMS) return 'its items are not a list of at most ' + groupThousands(MATRIX_MAX_ITEMS); var n = m.items.length; @@ -386,15 +411,16 @@ var claimed = d.steps.some(function (s) { return !!s.claim; }); if (!Array.isArray(m.values) || m.values.length !== n || !Array.isArray(m.classes) || m.classes.length !== n) return 'its values or classes are not one row per item'; if (claimed ? !Array.isArray(m.verdicts) || m.verdicts.length !== n : m.verdicts !== null) return 'its verdicts are not one row per item, or null where no step has a claim'; - var ns = d.states.length, nk = d.steps.length, ni = ids.length; + var ns = d.states.length, nk = d.steps.length, ni = ids.length, nc = nk + 1 + (d.ranges || []).length; for (var at = 0; at < n; at++) { var row = m.items[at]; if (!Array.isArray(row) || row.length !== 5 || typeof row[0] !== 'string' || typeof row[1] !== 'string') return 'item ' + at + ' is not [id, name, place, group, unit]'; var values = m.values[at]; if (!Array.isArray(values) || values.length !== ni * ns) return 'item ' + row[0] + ': not one result per indicator and state'; - for (var v = 0; v < values.length; v++) if (values[v] !== null && (typeof values[v] !== 'number' || !isFinite(values[v]))) return 'item ' + row[0] + ': a result that is not a number'; + for (var v = 0; v < values.length; v++) if (values[v] !== null && values[v] !== SAME && (typeof values[v] !== 'number' || !isFinite(values[v]))) return 'item ' + row[0] + ': a result that is not a number'; + if (!expandValues(values, ns)) return 'item ' + row[0] + ': "=" first in ' + 'an indicator, or after a missing result'; var codes = m.classes[at]; - if (typeof codes !== 'string' || codes.length !== ni * (nk + 1)) return 'item ' + row[0] + ': not one class code per indicator and comparison'; + if (typeof codes !== 'string' || codes.length !== ni * nc) return 'item ' + row[0] + ': not one class code per indicator and comparison'; for (var c = 0; c < codes.length; c++) if (!CODES.hasOwnProperty(codes[c])) return 'item ' + row[0] + ': an unknown class code'; if (claimed) { var said = m.verdicts[at]; @@ -409,15 +435,16 @@ // and verdicts per indicator. A listed item keeps its own record beside the row. function matrixRows(m, d) { var ids = d.indicators.map(function (i) { return i.id; }); - var ns = d.states.length, nk = d.steps.length; + var ns = d.states.length, nk = d.steps.length, nc = nk + 1 + (d.ranges || []).length; var listed = {}; d.items.forEach(function (item) { listed[item.id] = item; }); return m.items.map(function (row, at) { var out = { id: row[0], name: row[1], place: row[2], group: row[3], unit: row[4], values: {}, classes: {}, directions: {}, bands: null, verdicts: m.verdicts ? {} : null, item: listed[row[0]] || null }; + var values = expandValues(m.values[at], ns); ids.forEach(function (id, x) { - out.values[id] = m.values[at].slice(x * ns, (x + 1) * ns); - var codes = m.classes[at].slice(x * (nk + 1), (x + 1) * (nk + 1)).split(''); + out.values[id] = values.slice(x * ns, (x + 1) * ns); + var codes = m.classes[at].slice(x * nc, (x + 1) * nc).split(''); out.classes[id] = codes.map(function (c) { return CODES[c][0]; }); out.directions[id] = codes.map(function (c) { return CODES[c][1]; }); if (m.verdicts) { @@ -447,7 +474,7 @@ var D = null, B = {}, LISTED = [], M = null; var matrix = { state: 'none', said: '' }; - var view = { comp: null, worstN: 20, worstIndicator: '', find: '', cls: '', verdict: '', group: '', limit: PAGE, size: 0, sort: 'worst', open: null, distScale: 'card' }; + var view = { comp: null, picked: [], anchor: null, several: false, notice: '', worstN: 20, worstIndicator: '', find: '', cls: '', verdict: '', group: '', limit: PAGE, size: 0, sort: 'worst', open: null, distScale: 'card' }; var lastFocus = null; function q(name) { return root.querySelector('[data-sd="' + name + '"]'); } @@ -482,10 +509,65 @@ return id; } function indicatorIds() { return D.indicators.map(function (i) { return i.id; }); } + // the comparisons of a file, in the order an item lists them: each step, the whole way, + // then each range (a run of steps compared as one: the state before its first step + // against the state after its last) + function ranges() { return D.ranges || []; } + function rangeAt(id) { + var all = ranges(); + for (var j = 0; j < all.length; j++) if (all[j].id === id) return j; + return -1; + } function stepIndex(comp) { // the position of a comparison in an item's lists of classes if (comp === 'total') return D.steps.length; for (var i = 0; i < D.steps.length; i++) if (D.steps[i].id === comp) return i; - return D.steps.length; + var j = rangeAt(comp); + return j >= 0 ? D.steps.length + 1 + j : D.steps.length; + } + function isComp(comp) { + if (comp === 'total' || rangeAt(comp) >= 0) return true; + return D.steps.some(function (s) { return s.id === comp; }); + } + // the states (their positions) a comparison at position k of an item's lists compares + function stateEnds(k) { + var nk = D.steps.length; + if (k < nk) return [k, k + 1]; + if (k === nk) return [0, D.states.length - 1]; + var run = runOf(ranges()[k - nk - 1].id); + return [run[0], run[1] + 1]; + } + // the steps (their positions, first and last) a comparison takes in + function runOf(comp) { + if (comp === 'total') return [0, D.steps.length - 1]; + var j = rangeAt(comp); + if (j < 0) { var k = stepIndex(comp); return [k, k]; } + var first = stepIndex(ranges()[j].steps[0]); + return [first, first + ranges()[j].steps.length - 1]; + } + // the comparison of the steps a to b: one step, the whole way, or a range the file has; + // null where its producer did not compare those steps together + function compOfRun(a, b) { + if (a === b) return D.steps[a].id; + if (a === 0 && b === D.steps.length - 1) return 'total'; + var id = D.steps[a].id + '..' + D.steps[b].id; + var j = rangeAt(id); + return j >= 0 && sameList(ranges()[j].steps, D.steps.slice(a, b + 1).map(function (s) { return s.id; })) ? id : null; + } + function blocksOf(comp) { + if (comp === 'total') return D.counts.total; + return rangeAt(comp) >= 0 ? D.counts.ranges[comp] : D.counts.steps[comp]; + } + // which runs the file compares, in words, for a page that is asked for one it has not + function rangesSaid() { + var all = ranges(); + if (!all.length) return 'This file compares no run of steps: choose one step, or the whole way.'; + var lo = D.steps.length, hi = -1, counted = {}; + all.forEach(function (r) { var run = runOf(r.id); lo = Math.min(lo, run[0]); hi = Math.max(hi, run[1]); counted[run[0] + ':' + run[1]] = true; }); + var every = true; + for (var a = lo; a <= hi; a++) for (var b = a + 1; b <= hi; b++) if (!(a === 0 && b === D.steps.length - 1) && !counted[a + ':' + b]) every = false; + return every + ? 'It compares every run of steps within steps ' + stepNo(lo) + ' to ' + stepNo(hi) + '.' + : 'It compares ' + groupThousands(all.length) + ' runs of steps, chosen by its writer, within steps ' + stepNo(lo) + ' to ' + stepNo(hi) + '.'; } function stateIndex(stateId) { for (var i = 0; i < D.states.length; i++) if (D.states[i].id === stateId) return i; @@ -493,6 +575,10 @@ } function compLabel(comp) { if (comp === 'total') return 'The whole way: ' + D.states[0].label + ' → ' + D.states[D.states.length - 1].label; + if (rangeAt(comp) >= 0) { + var run = runOf(comp); + return 'Steps ' + stepNo(run[0]) + ' to ' + stepNo(run[1]) + ' together: ' + D.states[run[0]].label + ' → ' + D.states[run[1] + 1].label; + } var k = stepIndex(comp); return 'Step ' + stepNo(k) + ': ' + D.steps[k].label; } @@ -505,8 +591,8 @@ return many ? word.many : word.one; } function pairOf(row, indicator, k) { - var values = row.values[indicator]; - return k === D.steps.length ? [values[0], values[values.length - 1]] : [values[k], values[k + 1]]; + var values = row.values[indicator], ends = stateEnds(k); + return [values[ends[0]], values[ends[1]]]; } function verdictOf(row, indicator, k) { if (!row.verdicts || k >= D.steps.length) return null; @@ -600,7 +686,9 @@ } // the comparison is chosen from a row of chips: the whole way, then each step with its - // number, the values that moved in it and a mark for each verdict worth a look + // number, the values that moved in it and a mark for each verdict worth a look. Several + // steps chosen together are a run, its chips pressed; a step taken in only because it lies + // between two chosen ones is marked so (`markChips`) function renderChips() { var row = clear(q('comparison')); var chip = function (value, parts, title) { @@ -627,19 +715,59 @@ }); chip(s.id, parts, said.join('. ') + '.'); }); + var pick = q('pick'); + if (pick) { + pick.hidden = !ranges().length; + q('pick-several').checked = view.several; + pickSaid(); + } + markChips(); + } + function pickSaid() { + var node = q('pick-said'); + if (node) node.textContent = view.several + ? 'A click adds a step to those chosen, or takes one off at an end; the steps between are taken in.' + : 'Shift-click a second step to see the steps from one to the other together; ⌘- or Ctrl-click adds a step or takes one off.'; + } + + // what a step claims, who claimed it, and what the claim found in that step: every verdict + // on a move, "as claimed" first, each with its count; the ones worth a look carry their + // mark, as on the chips. No colour: a verdict is not an approval (ADR 0010). + function claimParts(s) { + if (!s.claim) return [el('span', { cls: 'sd-quiet', text: 'none: what moves here is counted, not judged.' })]; + var claim = [s.claim.text, ' ', badge(s.claim.by)]; + var found = ['as claimed'].concat(LOOK).map(function (name) { return [name, sumOver(s.id, function (b) { return b.verdicts[name]; })]; }) + .filter(function (p) { return p[1]; }); + claim.push(el('span', { cls: 'sd-verdicts', text: found.length + ? ' ' + found.map(function (p) { return n(p[1]) + ' ' + (p[1] === 1 ? 'value' : 'values') + ' ' + (p[0] === 'as claimed' ? 'moved as claimed' : p[0]) + (LOOK_MARK[p[0]] ? ' ' + LOOK_MARK[p[0]] : ''); }).join(', ') + '.' + : ' Nothing moved, as claimed.' })); + if (s.claim.scope.some(function (e) { return e.items === null; })) { + claim.push(el('span', { cls: 'sd-quiet', text: ' Its list of ' + D.item.many + ' is not in this file' + (s.claim.reach !== null ? ' (' + n(s.claim.reach) + ')' : '') + ': its verdicts were worked out by its writer.' })); + } + return claim; + } + + function stepList(ks) { + var nos = ks.map(function (k) { return String(stepNo(k)); }); + return nos.length === 1 ? nos[0] : nos.slice(0, -1).join(', ') + ' and ' + nos[nos.length - 1]; } // under the chips: what the chosen comparison is, the claim of its step and who made it, - // and its rule, so that a reviewer reads what a step said beside what it did + // and its rule, so that a reviewer reads what a step said beside what it did. For a run of + // steps: what they did together, each step's claim with what it found in that step alone function renderStepSaid() { var node = q('step-said'); if (!node) return; clear(node); + if (view.notice) node.appendChild(el('p', { cls: 'sd-notice', text: view.notice })); if (view.comp === 'total') { node.appendChild(el('p', null, [el('strong', { text: 'The whole way: ' }), D.states[0].label + ' → ' + D.states[D.states.length - 1].label + '. ', - el('span', { cls: 'sd-quiet', text: 'Each cell holds the last result divided by the first. Choose a step to see what one change did; "Steps and the whole way" below splits the whole difference between them.' })])); + el('span', { cls: 'sd-quiet', text: 'Each cell holds the last result divided by the first. Choose a step to see what one change did' + + (ranges().length ? ', or several to see what they did together' : '') + '; "Steps and the whole way" below splits the whole difference between them.' })])); return; } + var j = rangeAt(view.comp); + if (j >= 0) { renderRunSaid(node, ranges()[j]); return; } var k = stepIndex(view.comp); var s = D.steps[k]; var line = [el('strong', { text: 'Step ' + stepNo(k) + ': ' + s.label + '. ' }), el('span', { cls: 'sd-quiet', text: D.states[k].label + ' → ' + D.states[k + 1].label + '. ' })]; @@ -649,29 +777,46 @@ node.appendChild(el('p', { cls: 'sd-quiet', text: 'What moves here was not reproduced within the tolerance: the residual the chain starts from, not a regression.' })); } if (!s.explained) node.appendChild(el('p', { cls: 'sd-error', text: 'Nothing explains this step.' })); - var claim = [el('span', { cls: 'sd-claim-label', text: 'Claim' })]; - if (s.claim) { - claim.push(s.claim.text, ' ', badge(s.claim.by)); - // every verdict on a move, "as claimed" first, each with its count; the ones worth a - // look carry their mark, as on the chips. No colour: a verdict is not an approval. - var found = ['as claimed'].concat(LOOK).map(function (name) { return [name, sumOver(s.id, function (b) { return b.verdicts[name]; })]; }) - .filter(function (p) { return p[1]; }); - claim.push(el('span', { cls: 'sd-verdicts', text: found.length - ? ' ' + found.map(function (p) { return n(p[1]) + ' ' + (p[1] === 1 ? 'value' : 'values') + ' ' + (p[0] === 'as claimed' ? 'moved as claimed' : p[0]) + (LOOK_MARK[p[0]] ? ' ' + LOOK_MARK[p[0]] : ''); }).join(', ') + '.' - : ' Nothing moved, as claimed.' })); - if (s.claim.scope.some(function (e) { return e.items === null; })) { - claim.push(el('span', { cls: 'sd-quiet', text: ' Its list of ' + D.item.many + ' is not in this file' + (s.claim.reach !== null ? ' (' + n(s.claim.reach) + ')' : '') + ': its verdicts were worked out by its writer.' })); - } - } else { - claim.push(el('span', { cls: 'sd-quiet', text: 'none: what moves here is counted, not judged.' })); - } - node.appendChild(el('p', { cls: 'sd-claim' }, claim)); + node.appendChild(el('p', { cls: 'sd-claim' }, [el('span', { cls: 'sd-claim-label', text: 'Claim' })].concat(claimParts(s)))); node.appendChild(el('p', { cls: 'sd-quiet', text: 'Tolerance ' + s.tolerance.value + ' (' + s.tolerance.basis + '). Noise ' + noiseText(s.noise, indicatorIds(), indWord(true)) + '.' })); } + function renderRunSaid(node, r) { + var run = runOf(r.id); + var between = []; + for (var k = run[0] + 1; k < run[1]; k++) if (view.picked.indexOf(k) < 0) between.push(k); + node.appendChild(el('p', null, [el('strong', { text: 'Steps ' + stepNo(run[0]) + ' to ' + stepNo(run[1]) + ' together. ' }), + el('span', { cls: 'sd-quiet', text: D.states[run[0]].label + ' → ' + D.states[run[1] + 1].label + '. Each cell holds the result after the last of these steps divided by the result before the first: what they did together.' })])); + if (between.length) { + node.appendChild(el('p', { cls: 'sd-quiet', text: (between.length === 1 ? 'Step ' : 'Steps ') + stepList(between) + (between.length === 1 ? ' lies' : ' lie') + + ' between the steps chosen and ' + (between.length === 1 ? 'is' : 'are') + ' taken in: each state is built on the one before it, so steps are compared together only as a run.' })); + } + var list = el('ul', { cls: 'sd-claims' }); + for (k = run[0]; k <= run[1]; k++) { + var s = D.steps[k]; + var alone = sumOver(s.id, moved); + list.appendChild(el('li', null, [el('strong', { text: 'Step ' + stepNo(k) + ': ' + s.label + '. ' }), + s.explained ? null : el('span', { cls: 'sd-error', text: 'Nothing explains it. ' }), + el('span', { cls: 'sd-claim-label', text: 'Claim' })].concat(claimParts(s), + [el('span', { cls: 'sd-quiet', text: ' In this step alone: ' + (alone === 1 ? '1 value' : n(alone) + ' values') + ' moved.' })]))); + } + node.appendChild(list); + node.appendChild(el('p', { cls: 'sd-quiet', text: 'Tolerance ' + r.tolerance + ', the largest of these steps; no noise, and no verdict: a run is judged as the whole way is, and each claim is judged in its own step.' })); + } + function markChips() { + var run = view.comp === 'total' ? null : runOf(view.comp); var chips = q('comparison').querySelectorAll('button[data-comp]'); - for (var i = 0; i < chips.length; i++) chips[i].setAttribute('aria-pressed', chips[i].getAttribute('data-comp') === view.comp ? 'true' : 'false'); + for (var i = 0; i < chips.length; i++) { + var comp = chips[i].getAttribute('data-comp'); + var k = comp === 'total' ? -1 : stepIndex(comp); + var on = comp === 'total' ? view.comp === 'total' : !!run && k >= run[0] && k <= run[1]; + var between = !!run && on && k > run[0] && k < run[1] && view.picked.indexOf(k) < 0; + chips[i].setAttribute('aria-pressed', on ? 'true' : 'false'); + chips[i].className = 'sd-chip' + (between ? ' sd-between' : ''); + if (between) chips[i].setAttribute('data-between', ''); + else if (chips[i].removeAttribute) chips[i].removeAttribute('data-between'); + } } // what the page holds of the items: the listed ones, or every one once the matrix is here @@ -688,7 +833,7 @@ } function sumOver(comp, fn) { - var blocks = comp === 'total' ? D.counts.total : D.counts.steps[comp]; + var blocks = blocksOf(comp); return Object.keys(blocks).reduce(function (acc, key) { return acc + fn(blocks[key]); }, 0); } function moved(block) { return MOVES.reduce(function (a, k) { return a + block.classes[k]; }, 0); } @@ -836,7 +981,7 @@ function renderDistributions() { var comp = view.comp; var k = stepIndex(comp); - var blocks = comp === 'total' ? D.counts.total : D.counts.steps[comp]; + var blocks = blocksOf(comp); var held = M || (D.items_count.listed === D.items_count.all && D.tier !== 'counts'); q('dist-said').textContent = 'How many ' + D.item.many + ' fall in each band of after ÷ before, in the comparison chosen above, one card per ' + indWord(false) + ' in the order of the matrix: from across zero, through down by more than ten times, the band around 1 (dark), to up by more than ten times; then the values with no ratio. ' + @@ -996,7 +1141,7 @@ // that what a step did is in view without scrolling; the file's order among equals, and // an indicator in which nothing moved last, quietened function columns(comp) { - var blocks = comp === 'total' ? D.counts.total : D.counts.steps[comp]; + var blocks = blocksOf(comp); // a missing value is a finding, not stillness: it counts with what moved return D.indicators.map(function (ind, at) { var block = blocks[ind.id]; @@ -1119,7 +1264,8 @@ var body = clear(q('rule-body')); body.appendChild(el('p', null, ['Every value is put into one class by one rule, in this order: missing, near zero, agrees, within noise (both only where the two share a sign), zero reference, zero result, sign change, beyond 10x, differs. ' + 'Direction is up where the result after is larger as a signed number, down otherwise; colour follows the direction only. ' + - 'Beyond 10x: one size more than ' + D.rule.beyond + ' times the other. The whole way is counted with a tolerance of ' + D.rule.total_tolerance + ', the largest of the steps. ' + + 'Beyond 10x: one size more than ' + D.rule.beyond + ' times the other. The whole way is counted with a tolerance of ' + D.rule.total_tolerance + ', the largest of the steps, and no noise; ' + + 'so is a run of steps chosen together, with the largest tolerance of its steps. ' + rangesSaid() + ' ' + 'The matrix shows the result after divided by the result before; the ratio and the strength of its colour are a display, and change no class.'])); var stepsTable = el('table', null, [el('thead', null, [el('tr', null, ['Step', 'Tolerance', 'Basis', 'Note', 'Noise'].map(function (h) { return el('th', { scope: 'col', text: h }); }))])]); var tb = el('tbody'); @@ -1177,10 +1323,11 @@ var table = el('table', { 'data-indicator': ind.id }, [el('thead', null, [el('tr', null, ['Step', 'Before', 'After', 'Change', 'Verdict', 'Share of the whole difference'].map(function (h) { return el('th', { scope: 'col', text: h }); }))])]); var tb = el('tbody'); var split = splitOf(values, D.steps.map(function (s) { return s.explained; }), totalCls); + var run = view.comp === 'total' ? null : runOf(view.comp); D.steps.forEach(function (s, k) { var b = values[k], a = values[k + 1]; var share = split.state === 'split' ? shareText(split.shares[k]) : '—'; - tb.appendChild(el('tr', null, [ + tb.appendChild(el('tr', { cls: run && k >= run[0] && k <= run[1] ? 'sd-in-run' : null }, [ el('td', null, ['Step ' + stepNo(k) + ': ' + s.label, s.explained ? null : el('div', { cls: 'sd-error', text: 'nothing explains it' })]), el('td', { cls: 'num', text: formatNumber(b), title: String(b) }), el('td', { cls: 'num', text: formatNumber(a), title: String(a) }), @@ -1197,11 +1344,23 @@ el('td', { text: '—' }), el('td', { cls: 'num', text: splitText(split) }) ])); + var j = rangeAt(view.comp); + if (j >= 0) { + var at = D.steps.length + 1 + j, pair = pairOf(row, ind.id, at); + tb.appendChild(el('tr', { cls: 'sd-in-run' }, [ + el('th', { scope: 'row', text: 'Steps ' + stepNo(run[0]) + ' to ' + stepNo(run[1]) + ' together' }), + el('td', { cls: 'num', text: formatNumber(pair[0]), title: String(pair[0]) }), + el('td', { cls: 'num', text: formatNumber(pair[1]), title: String(pair[1]) }), + valueCell(row, ind.id, at, false), + el('td', { text: '—' }), + el('td', { text: '' }) + ])); + } table.appendChild(tb); return el('div', { cls: 'sd-wrap' }, [table]); } - function renderItem(id) { + function renderItem(id, quiet) { var row = rowById(id); var drawer = q('item'); if (!row) { closeItem(); return; } @@ -1246,7 +1405,7 @@ }); markOpen(); var title = q('item-title'); - if (title.focus) title.focus(); + if (!quiet && title.focus) title.focus(); } function markOpen() { @@ -1459,18 +1618,79 @@ return true; } - function choose(comp) { - if (comp === view.comp) return; - view.comp = comp; view.cls = ''; view.verdict = ''; view.limit = PAGE; view.sort = 'worst'; + // `picked`: the steps chosen by hand, of a run; the others of it lie between. Without + // it, a new comparison has its ends picked and the same one keeps what it had + function choose(comp, picked) { + var same = comp === view.comp; + if (picked) view.picked = picked; + else if (!same) view.picked = comp === 'total' ? [] : runOf(comp); + view.comp = comp; markChips(); renderStepSaid(); + if (same) return; + view.cls = ''; view.verdict = ''; view.limit = PAGE; view.sort = 'worst'; renderComparison(); + if (view.open) renderItem(view.open, true); + } + + // a click on a step's chip ("one"): that step alone. "to" (Shift, or a second click with + // "Several steps" on): the steps from the one chosen before to this one. "toggle" (⌘ or + // Ctrl): the chosen steps grown to this one or, where it is an end of them, shrunk by it. + // Steps chosen together are a run: what lies between them is taken in, and the step line + // says so. A run the file does not compare is said, and nothing changes. + function pick(k, how) { + var run = view.comp === 'total' ? null : runOf(view.comp); + var a = k, b = k, picked = [k]; + if (how === 'to' && view.anchor !== null) { + a = Math.min(view.anchor, k); b = Math.max(view.anchor, k); picked = [view.anchor, k]; + } else if (how === 'toggle' && run) { + if (k < run[0] || k > run[1]) { + a = Math.min(run[0], k); b = Math.max(run[1], k); picked = view.picked.concat([k]); + } else if (run[0] === run[1]) { + view.notice = ''; view.anchor = null; + choose('total'); + setHash({ step: view.comp, item: view.open }); + return; + } else if (k === run[0] || k === run[1]) { + a = k === run[0] ? k + 1 : run[0]; b = k === run[1] ? k - 1 : run[1]; + picked = view.picked.filter(function (x) { return x !== k; }); + } else { + view.notice = 'Step ' + stepNo(k) + ' lies inside the steps ' + stepNo(run[0]) + ' to ' + stepNo(run[1]) + ', which are compared as a whole: take off a step at one of their ends, or click a step alone.'; + renderStepSaid(); + return; + } + } + var comp = compOfRun(a, b); + if (comp === null) { + view.notice = 'Steps ' + stepNo(a) + ' to ' + stepNo(b) + ' together are not compared in this file. ' + rangesSaid(); + renderStepSaid(); + return; + } + view.notice = ''; + if (how === 'one' || view.anchor === null) view.anchor = k; + choose(comp, picked.filter(function (x) { return x >= a && x <= b; }).concat([a, b])); + setHash({ step: view.comp, item: view.open }); + } + + // what the page says of an address that names no comparison of this file + function unknownSaid(said) { + for (var a = 0; a < D.steps.length; a++) { + for (var b = a + 1; b < D.steps.length; b++) { + if (D.steps[a].id + '..' + D.steps[b].id === said) { + return 'The address asks for steps ' + stepNo(a) + ' to ' + stepNo(b) + ' together, which this file does not compare. ' + rangesSaid() + ' The whole way is shown.'; + } + } + } + return 'The address asks for "' + said + '", which is no step and no run of steps of this file. The whole way is shown.'; } function route() { if (!D) return; var parts = hashParts(); - var step = parts.step && stepIndex(parts.step) < D.steps.length ? parts.step : 'total'; + var said = parts.step || 'total'; + var step = isComp(said) ? said : 'total'; + view.notice = step === said ? '' : unknownSaid(said); + if (step !== view.comp) view.anchor = step === 'total' ? null : runOf(step)[0]; choose(step); if (parts.item) renderItem(parts.item); else closeItem(); @@ -1492,21 +1712,43 @@ function start() { q('comparison').addEventListener('click', function (e) { var chip = e.target.closest ? e.target.closest('button[data-comp]') : null; - if (!chip || chip.getAttribute('data-comp') === view.comp) return; - choose(chip.getAttribute('data-comp')); - setHash({ step: view.comp, item: view.open }); + if (!chip || !D) return; + var comp = chip.getAttribute('data-comp'); + if (comp === 'total') { + view.notice = ''; view.anchor = null; + choose('total'); + setHash({ step: view.comp, item: view.open }); + return; + } + pick(stepIndex(comp), e.shiftKey ? 'to' : e.metaKey || e.ctrlKey || view.several ? 'toggle' : 'one'); }); - // the arrow keys move between the chips + // the arrow keys move between the chips; with Shift they grow or shrink the run at the + // end away from where it started q('comparison').addEventListener('keydown', function (e) { if (!D || (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft')) return; + var step = e.key === 'ArrowRight' ? 1 : -1; var comps = ['total'].concat(D.steps.map(function (s) { return s.id; })); - var at = comps.indexOf(view.comp) + (e.key === 'ArrowRight' ? 1 : -1); - if (at < 0 || at >= comps.length) return; - choose(comps[at]); - setHash({ step: view.comp, item: view.open }); - var next = q('comparison').querySelector('button[data-comp="' + comps[at] + '"]'); + var to; + if (e.shiftKey && view.comp !== 'total') { + var run = runOf(view.comp); + var k = (view.anchor === run[0] ? run[1] : run[0]) + step; + if (k < 0 || k >= D.steps.length) return; + pick(k, 'to'); + to = D.steps[k].id; + } else { + var at = (view.comp === 'total' ? 0 : 1 + runOf(view.comp)[step > 0 ? 1 : 0]) + step; + if (at < 0 || at >= comps.length) return; + to = comps[at]; + if (to === 'total') { view.anchor = null; view.notice = ''; choose('total'); setHash({ step: view.comp, item: view.open }); } + else pick(stepIndex(to), 'one'); + } + if (e.preventDefault) e.preventDefault(); + var next = q('comparison').querySelector('button[data-comp="' + to + '"]'); if (next && next.focus) next.focus(); }); + if (q('pick-several')) { + q('pick-several').addEventListener('change', function (e) { view.several = !!e.target.checked; pickSaid(); }); + } q('size').addEventListener('change', function (e) { view.size = +e.target.value; view.limit = PAGE; renderWorst(); renderGrid(); }); q('worst-n').addEventListener('change', function (e) { view.worstN = +e.target.value; renderWorst(); }); q('dist-scale').addEventListener('change', function (e) { view.distScale = e.target.value === 'one' ? 'one' : 'card'; renderDistributions(); }); @@ -1574,7 +1816,7 @@ } } - var api = { formatNumber: formatNumber, percentText: percentText, shareText: shareText, ratioText: ratioText, ratioShort: ratioShort, noiseText: noiseText, + var api = { expandValues: expandValues, formatNumber: formatNumber, percentText: percentText, shareText: shareText, ratioText: ratioText, ratioShort: ratioShort, noiseText: noiseText, sizeAtLeast: sizeAtLeast, cellView: cellView, ratioView: ratioView, severityKey: severityKey, compareKeys: compareKeys, bandStep: bandStep, bandOf: bandOf, checkShape: checkShape, checkMatrix: checkMatrix, matrixRows: matrixRows, safeLink: safeLink, safeName: safeName, splitOf: splitOf, splitText: splitText, distance: distance, quantileTexts: quantileTexts, RANK: RANK, diff --git a/tests/js/page.test.js b/tests/js/page.test.js index 8512743..4476661 100644 --- a/tests/js/page.test.js +++ b/tests/js/page.test.js @@ -815,3 +815,129 @@ test('a card says over how many ratios its median is, how many have none, and wh assert.match(card.childNodes[1].textContent, /^tallest bar: \d/); } }); + +// ------------------------------------------------------------------ several steps: a run + +const pressed = (drawn) => chips(drawn).filter((c) => c.getAttribute('aria-pressed') === 'true').map((c) => c.getAttribute('data-comp')); +const chipOf = (drawn, id) => chips(drawn).find((c) => c.getAttribute('data-comp') === id); + +test('Shift-click chooses the steps from one to another together: the range the file compares', () => { + const data = example(); + const [a, b] = [data.steps[1], data.steps[2]]; + const id = a.id + '..' + b.id; + assert.ok(data.ranges.some((r) => r.id === id)); + const drawn = dom.page(data); + assert.equal(drawn.byId.pick.hidden, false); + chipOf(drawn, a.id).dispatch('click', {}); + chipOf(drawn, b.id).dispatch('click', { shiftKey: true }); + assert.deepEqual(pressed(drawn), [a.id, b.id]); + assert.equal(drawn.context.location.hash, 'step=' + encodeURIComponent(id)); + const said = drawn.byId['step-said'].textContent; + assert.match(said, /^Steps 1 to 2 together\. /); + for (const s of [a, b]) assert.ok(said.includes('Step ' + data.steps.indexOf(s) + ': ' + s.label), s.id); + assert.match(said, /no verdict: a run is judged as the whole way is/); + // every card shows the file's counts of the range, never a sum of its steps + for (const card of cards(drawn)) { + const block = data.counts.ranges[id][card.getAttribute('data-indicator')]; + const total = card.childNodes[2].childNodes.reduce((sum, bar) => sum + Number(/: ([\d\s]+) of [\d\s]+$/.exec(bar.getAttribute('title'))[1].replace(/\s/g, '')), 0); + assert.equal(total, block.pairs); + } + // a grid cell is the range's own class, after the last step against before the first + const at = data.steps.length + 1 + data.ranges.findIndex((r) => r.id === id); + const row = gridRows(drawn)[0]; + const item = data.items.find((i) => i.id === row.getAttribute('data-item')); + const cls = row.childNodes.filter((n) => n.tagName === 'TD').slice(1).map((td) => td.getAttribute('data-class')); + const heads = drawn.byId['grid-table'].querySelectorAll('th[scope="col"]').slice(2) + .map((th) => data.indicators.find((i) => th.getAttribute('title').indexOf(i.name) === 0).id); + heads.forEach((ind, k) => assert.equal(cls[k], item.classes[ind][at], ind)); +}); + +test('steps chosen apart take in the steps between them, and the page says so', () => { + const data = example(); + const drawn = dom.page(data); + chipOf(drawn, data.steps[0].id).dispatch('click', {}); + chipOf(drawn, data.steps[2].id).dispatch('click', { metaKey: true }); + assert.deepEqual(pressed(drawn), data.steps.slice(0, 3).map((s) => s.id)); + assert.match(chipOf(drawn, data.steps[1].id).className, /sd-between/); + assert.doesNotMatch(chipOf(drawn, data.steps[2].id).className, /sd-between/); + assert.match(drawn.byId['step-said'].textContent, /Step 1 lies between the steps chosen and is taken in: each state is built on the one before it/); + // an end taken off shrinks the run; a step inside cannot be taken off, and nothing changes + chipOf(drawn, data.steps[1].id).dispatch('click', { metaKey: true }); + assert.match(drawn.byId['step-said'].textContent, /^Step 1 lies inside the steps 0 to 2, which are compared as a whole/); + assert.deepEqual(pressed(drawn), data.steps.slice(0, 3).map((s) => s.id)); + chipOf(drawn, data.steps[0].id).dispatch('click', { ctrlKey: true }); + assert.deepEqual(pressed(drawn), data.steps.slice(1, 3).map((s) => s.id)); + assert.equal(drawn.context.location.hash, 'step=' + encodeURIComponent(data.steps[1].id + '..' + data.steps[2].id)); + // with "Several steps" on, a plain click does what ⌘-click does + drawn.byId['pick-several'].checked = true; + drawn.byId['pick-several'].dispatch('change', {}); + chipOf(drawn, data.steps[3].id).dispatch('click', {}); + assert.deepEqual(pressed(drawn), data.steps.slice(1, 4).map((s) => s.id)); +}); + +test('every step chosen is the whole way, and a run the file does not compare is said and not shown', () => { + const data = example(); + const drawn = dom.page(data); + chipOf(drawn, data.steps[0].id).dispatch('click', {}); + chipOf(drawn, data.steps[3].id).dispatch('click', { shiftKey: true }); + assert.deepEqual(pressed(drawn), ['total']); + // a file that compares fewer runs + const fewer = example(); + const gone = fewer.ranges.pop(); + delete fewer.counts.ranges[gone.id]; + const shown = dom.page(fewer); + chipOf(shown, gone.steps[0]).dispatch('click', {}); + chipOf(shown, gone.steps[gone.steps.length - 1]).dispatch('click', { shiftKey: true }); + assert.deepEqual(pressed(shown), [gone.steps[0]]); + assert.match(shown.byId['step-said'].textContent, /together are not compared in this file\. It compares 4 runs of steps, chosen by its writer/); +}); + +test('an address names a run of steps, and one the file does not compare falls back to the whole way, said', () => { + const data = example(); + const range = data.ranges[2]; + const drawn = dom.page(data); + drawn.open('step=' + encodeURIComponent(range.id) + '&item=' + encodeURIComponent(data.items[0].id)); + assert.deepEqual(pressed(drawn), range.steps); + // the drawer holds the run's own row + assert.ok(drawn.byId['item-body'].textContent.includes('together'), 'a row of the run'); + drawn.open('step=' + encodeURIComponent(data.steps[0].id + '..' + data.steps[3].id + 'x')); + assert.deepEqual(pressed(drawn), ['total']); + assert.match(drawn.byId['step-said'].textContent, /no step and no run of steps of this file\. The whole way is shown/); + const fewer = example(); + const gone = fewer.ranges.pop(); + delete fewer.counts.ranges[gone.id]; + const shown = dom.page(fewer); + shown.open('step=' + encodeURIComponent(gone.id)); + assert.match(shown.byId['step-said'].textContent, /^The address asks for steps \d to \d together, which this file does not compare/); +}); + +test('Shift and an arrow key grow the run, and a file without ranges offers no several steps', () => { + const data = example(); + const drawn = dom.page(data); + chipOf(drawn, data.steps[1].id).dispatch('click', {}); + drawn.byId.comparison.dispatch('keydown', { key: 'ArrowRight', shiftKey: true }); + assert.deepEqual(pressed(drawn), data.steps.slice(1, 3).map((s) => s.id)); + drawn.byId.comparison.dispatch('keydown', { key: 'ArrowLeft', shiftKey: true }); + assert.deepEqual(pressed(drawn), [data.steps[1].id]); + const none = example(); + delete none.ranges; + delete none.counts.ranges; + const shown = dom.page(none); + assert.equal(shown.byId.pick.hidden, true); + chipOf(shown, none.steps[1].id).dispatch('click', {}); + chipOf(shown, none.steps[2].id).dispatch('click', { shiftKey: true }); + assert.match(shown.byId['step-said'].textContent, /This file compares no run of steps/); +}); + +test('a matrix result written "=" is the result before it, and a "=" that stands first is refused', () => { + assert.deepEqual(page.expandValues([1.5, '=', null, 2, '=', '='], 3), [1.5, 1.5, null, 2, 2, 2]); + assert.equal(page.expandValues(['=', 1], 2), null); + assert.equal(page.expandValues([1, null, '='], 3), null); + assert.equal(page.expandValues([1, 2, '=', 4], 2), null); // first of the second indicator + const m = full(); + assert.ok(m.values.some((row) => row.includes('=')), 'the local example has repeated results'); + const broken = full(); + const at = broken.values.findIndex((row) => row.includes('=')); + broken.values[at][0] = '='; + assert.match(page.checkMatrix(broken, local()), /"=" first in an indicator/); +}); diff --git a/tests/test_matrix_page.py b/tests/test_matrix_page.py index bc59985..9c7e9c0 100644 --- a/tests/test_matrix_page.py +++ b/tests/test_matrix_page.py @@ -40,11 +40,18 @@ def test_a_matrix_survives_its_own_text(self): self.assertEqual(json.loads(matrix.dumps(full)), full) def test_every_changed_code_is_found(self): + def written_out(m, at): + """A result written as a number after the first state: changing it changes a step. + (Changing the first, where the states after it are `=`, changes every state alike.)""" + nstates = len(m["of"]["states"]) + n = next(n for n, v in enumerate(m["values"][at]) if n % nstates and isinstance(v, float) and v) + return n, m["values"][at][n] * 3 + data, full = local() cases = { "a class code": lambda m: m["classes"].__setitem__(0, ("=" if m["classes"][0][0] != "=" else "D") + m["classes"][0][1:]), "a direction": lambda m: m["classes"].__setitem__(0, m["classes"][0].swapcase()), - "a result": lambda m: m["values"][7].__setitem__(0, (m["values"][7][0] or 1.0) * 3), + "a result": lambda m: m["values"][7].__setitem__(*written_out(m, 7)), "a verdict": lambda m: m["verdicts"].__setitem__( 6, "".join("o" if c == "a" else "a" if c == "o" else c for c in m["verdicts"][6])), "a name of a listed item": lambda m: m["items"][0].__setitem__(1, "Another name"), diff --git a/tests/test_modules.py b/tests/test_modules.py index d60d215..3e45263 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -20,6 +20,7 @@ HERE = Path(__file__).parent FIXTURES = HERE / "fixtures" / "tables" +TOTAL_AT = None MODULES = ["rule", "claims", "chain", "fileformat", "breakdown", "tables", "summary", "page", "from_tables", "matrix"] @@ -34,6 +35,8 @@ class Validator(unittest.TestCase): def setUp(self): self.data = example.build() + global TOTAL_AT + TOTAL_AT = len(self.data["steps"]) # an item lists each step, then the total, then each range def refuses(self, change, says=None): found = fileformat.errors(helpers.mutated(self.data, change)) @@ -53,8 +56,8 @@ def test_the_word_for_an_indicator_is_optional_and_checked(self): def test_a_class_that_contradicts_the_rule(self): def change(d): - item = next(i for i in d["items"] if i["classes"]["x:climate"][-1] == rule.DIFFERS) - item["classes"]["x:climate"][-1] = rule.AGREES + item = next(i for i in d["items"] if i["classes"]["x:climate"][TOTAL_AT] == rule.DIFFERS) + item["classes"]["x:climate"][TOTAL_AT] = rule.AGREES self.refuses(change) def test_a_verdict_that_contradicts_the_claim(self): @@ -66,8 +69,8 @@ def change(d): def test_a_direction_that_contradicts_the_values(self): def change(d): - item = next(i for i in d["items"] if i["directions"]["x:climate"][-1] == "down") - item["directions"]["x:climate"][-1] = "up" + item = next(i for i in d["items"] if i["directions"]["x:climate"][TOTAL_AT] == "down") + item["directions"]["x:climate"][TOTAL_AT] = "up" self.refuses(change) def test_items_out_of_order(self): diff --git a/tests/test_ranges.py b/tests/test_ranges.py new file mode 100644 index 0000000..7d9c9ad --- /dev/null +++ b/tests/test_ranges.py @@ -0,0 +1,301 @@ +"""Ranges: runs of consecutive steps, each compared as the whole way is (SPEC section 5.5).""" + +from __future__ import annotations + +import json +import tempfile +import unittest +from pathlib import Path + +from sentier_diagnostics import chain, claims, fileformat, from_tables, matrix, rule + +from . import helpers +from .helpers import A, B + +STEPS = ("one", "two", "three", "four") +#: `q` moves by 0.8% a step, under the 1% tolerance of each, up twice and down twice: no +#: step and not the whole way moves it, and the runs one..two and three..four do, by 1.6%. +Q = [1.0, 1.008, 1.016, 1.008, 1.0] +#: `p` moves once, in step two, by half. +P = [2.0, 2.0, 1.0, 1.0, 1.0] +#: `r` does not move. +R = [3.0, 3.0, 3.0, 3.0, 3.0] + + +def five_states(ranges="all", claim=None, **more): + """A chain of five states and four steps, each with a tolerance of 1%.""" + states = [chain.state(f"s{n}", f"State {n}", kind="published" if n == 0 else "build") for n in range(5)] + steps = [ + chain.step(sid, f"Step {sid}", kind="fix", tolerance=chain.tolerance(0.01 if sid != "three" else 0.02), + claim=claim if sid == "two" else None) + for sid in STEPS + ] # fmt: skip + values = { + f"s{n}": {A: {"p": P[n], "q": Q[n], "r": R[n]}, B: {"p": R[n], "q": R[n], "r": R[n]}} for n in range(5) + } + return chain._build( + "Five states", + indicators=helpers.INDICATORS, + states=states, + steps=steps, + values=values, + units=dict.fromkeys("pqr", "kg"), + ranges=ranges, + **more, + ) + + +def at(data, range_id): + """Where a range stands in an item's lists: after the steps and the total.""" + return len(data["steps"]) + 1 + [r["id"] for r in data["ranges"]].index(range_id) + + +class Build(unittest.TestCase): + def setUp(self): + self.data, _ = five_states() + + def test_every_run_of_two_or_more_steps_but_the_whole_way(self): + self.assertEqual( + [r["id"] for r in self.data["ranges"]], + ["one..two", "one..three", "two..three", "two..four", "three..four"], + ) + first = self.data["ranges"][1] + self.assertEqual(first["steps"], ["one", "two", "three"]) + self.assertEqual((first["from"], first["to"]), ("s0", "s3")) + + def test_a_range_takes_the_largest_tolerance_of_its_steps_and_no_noise(self): + tolerance = {r["id"]: r["tolerance"] for r in self.data["ranges"]} + self.assertEqual(tolerance, {"one..two": 0.01, "one..three": 0.02, "two..three": 0.02, + "two..four": 0.02, "three..four": 0.02}) # fmt: skip + + def test_a_range_moves_where_each_of_its_steps_agrees(self): + q = next(i for i in self.data["items"] if i["id"] == "q") + steps_and_total = q["classes"][A][: len(STEPS) + 1] + self.assertEqual(set(steps_and_total), {rule.AGREES}) + self.assertEqual(q["classes"][A][at(self.data, "one..two")], rule.DIFFERS) + self.assertEqual(q["directions"][A][at(self.data, "one..two")], rule.UP) + self.assertEqual(q["directions"][A][at(self.data, "two..four")], None) # 1.008 to 1.0: under 2% + # q is worth a look for its ranges alone, and listed; p moves in one..two by its step two + self.assertEqual(self.data["counts"]["ranges"]["one..two"][A]["classes"][rule.DIFFERS], 2) + + def test_a_range_has_no_verdict_and_no_closer_or_further(self): + claim = claims.claim("p goes down.", [claims.scope([A], {"p"}, "down", None, claims.MUST)], + by=claims.origin("person", "A. Author")) # fmt: skip + data, _ = five_states(claim=claim) + for block in data["counts"]["ranges"]["two..three"].values(): + self.assertEqual((block["verdicts"], block["closer"], block["further"]), (None, None, None)) + self.assertIsNotNone(data["counts"]["steps"]["two"][A]["verdicts"]) + p = next(i for i in data["items"] if i["id"] == "p") + self.assertEqual(len(p["verdicts"][A]), len(STEPS)) + + def test_no_ranges_leaves_the_file_as_it_was(self): + data, _ = five_states(ranges=None) + self.assertNotIn("ranges", data) + self.assertNotIn("ranges", data["counts"]) + self.assertEqual(len(data["items"][0]["classes"][A]), len(STEPS) + 1) + self.assertNotIn("q", [i["id"] for i in data["items"]]) # nothing moved it without its ranges + + def test_auto_is_every_range_up_to_eight_steps_and_none_beyond(self): + def steps(n): + return [{"id": f"k{k}", "from": f"s{k}", "to": f"s{k + 1}", "tolerance": {"value": 0.01}} + for k in range(n)] # fmt: skip + + self.assertEqual(len(chain._ranges("auto", steps(chain.AUTO_RANGES))), 8 * 7 // 2 - 1) + self.assertEqual(chain._ranges("auto", steps(chain.AUTO_RANGES + 1)), []) + self.assertEqual(chain._ranges("auto", steps(1)), []) + self.assertEqual(chain._ranges("auto", steps(2)), []) # the one run of two is the whole way + + def test_ranges_within_two_steps(self): + steps = [{"id": s} for s in STEPS] + self.assertEqual(chain.ranges_within(steps, "two", "four"), + [("two", "three"), ("two", "four"), ("three", "four")]) # fmt: skip + data, _ = five_states(ranges=chain.ranges_within(steps, "two", "four")) + self.assertEqual([r["id"] for r in data["ranges"]], ["two..three", "two..four", "three..four"]) + + def test_ranges_asked_for_wrongly_are_refused(self): + for said, words in ( + ([("one", "one")], "at least two steps"), + ([("three", "two")], "at least two steps"), + ([("one", "four")], "the whole way"), + ([("one", "five")], "of this chain"), + ([("one", "two"), ("one", "two")], "twice"), + ("some", "not 'some'"), + ): + with self.subTest(said): + with self.assertRaises(ValueError) as caught: + five_states(ranges=said) + self.assertIn(words, str(caught.exception)) + + +class Validator(unittest.TestCase): + """Every change a range can suffer is found, and none stops the check.""" + + def setUp(self): + self.data, _ = five_states() + self.assertEqual(fileformat.errors(self.data), []) + + def finds(self, change, words): + found = fileformat.errors(helpers.mutated(self.data, change)) + self.assertTrue(found, "nothing found") + self.assertFalse([e for e in found if e.startswith(fileformat.STOPPED)], found) + self.assertTrue(any(words in e for e in found), found) + + def test_changes_to_a_range(self): + def item(d, name): + return next(i for i in d["items"] if i["id"] == name) + + def recount(d, range_id): + """One pair that differs, counted as one that agrees, consistently: only the + listed items can say it is wrong.""" + block = d["counts"]["ranges"][range_id][A] + q = item(d, "q") + block["classes"][rule.DIFFERS] -= 1 + block["classes"][rule.AGREES] += 1 + block["directions"][q["directions"][A][at(d, range_id)]] -= 1 + block["bands"][q["bands"][A][at(d, range_id)]] -= 1 + + cases = { + "an id that is not its steps": (lambda d: d["ranges"][0].update(id="one..three"), "first and last step"), + "steps that are not consecutive": (lambda d: d["ranges"][1].update(steps=["one", "three"]), "consecutive"), + "a state it does not lead from": (lambda d: d["ranges"][0].update(**{"from": "s1"}), "does not lead"), + "a tolerance that is not its steps'": (lambda d: d["ranges"][0].update(tolerance=0.5), "largest tolerance"), + "a tolerance that is not a share": (lambda d: d["ranges"][0].update(tolerance=[]), "a range is not"), + "a range of one step": (lambda d: d["ranges"][0].update(id="one..one", steps=["one"]), "at least two"), + "a range of every step": ( + lambda d: d["ranges"][0].update(id="one..four", steps=list(STEPS), to="s4", tolerance=0.02), + "the whole way", + ), + "a range twice": (lambda d: d["ranges"].append(dict(d["ranges"][0])), "another range"), + "counts without a range": (lambda d: d["counts"]["ranges"].pop("two..three"), "every range"), + "counts of ranges the file does not have": (lambda d: d.pop("ranges"), "only where"), + "a range class rewritten": ( + lambda d: item(d, "q")["classes"][A].__setitem__(at(d, "one..two"), rule.AGREES), + "the rule gives", + ), + "a range count moved": (lambda d: recount(d, "one..two"), "in the listed items"), + "verdicts in a range": ( + lambda d: d["counts"]["ranges"]["one..two"][A].update(verdicts=dict.fromkeys(claims.VERDICTS, 0)), + "verdicts without a claim", + ), + "closer in a range": ( + lambda d: d["counts"]["ranges"]["one..two"][A].update(closer=0, further=0), + "null everywhere else", + ), + "an item one range short": (lambda d: [item(d, "q")[k][A].pop() for k in ("classes", "directions", "bands")], + "each range"), # fmt: skip + } + for name, (change, words) in cases.items(): + with self.subTest(name): + self.finds(change, words) + + def test_values_of_any_type_in_a_range_never_stop_the_check(self): + odd = ([], {}, [[]], {"a": 1}, "x", -1, 1.5, True, None, 10**400, [None]) + data = json.loads(json.dumps(self.data)) + for n in range(len(data["ranges"])): + for key in fileformat.RANGE_KEYS: + kept = data["ranges"][n][key] + for value in odd: + data["ranges"][n][key] = value + found = fileformat.errors(data) + self.assertFalse([e for e in found if e.startswith(fileformat.STOPPED)], (key, value, found)) + data["ranges"][n][key] = kept + for value in odd: + data["ranges"] = value + found = fileformat.errors(data) + self.assertFalse([e for e in found if e.startswith(fileformat.STOPPED)], (value, found)) + + +class Matrix(unittest.TestCase): + def setUp(self): + self.data, self.full = five_states(matrix_file="matrix.json") + + def test_the_matrix_holds_each_range_and_agrees_with_its_file(self): + self.assertEqual(self.full["of"]["ranges"], [r["id"] for r in self.data["ranges"]]) + ncodes = len(STEPS) + 1 + len(self.data["ranges"]) + self.assertTrue(all(len(c) == 2 * ncodes for c in self.full["classes"])) + self.assertEqual(matrix.errors(self.full), []) + self.assertEqual(matrix.against(self.full, self.data), []) + + def test_a_result_equal_to_the_one_before_is_written_as_the_same(self): + r = self.full["values"][[row[0] for row in self.full["items"]].index("r")] + self.assertEqual(r, [3.0, "=", "=", "=", "=", 3.0, "=", "=", "=", "="]) + with tempfile.TemporaryDirectory() as tmp: + path = matrix.write(self.full, Path(tmp) / "matrix.json") + self.assertEqual(matrix.read(path, self.data), self.full) + + def test_changes_are_found(self): + q = [row[0] for row in self.full["items"]].index("q") + + def flip(m): + codes = m["classes"][q] + where = len(STEPS) + 1 # the first range of the first indicator + m["classes"][q] = codes[:where] + ("=" if codes[where] != "=" else "D") + codes[where + 1 :] + + cases = { + "a range code": (flip, matrix.against), + "the ranges named in another order": (lambda m: m["of"]["ranges"].reverse(), matrix.against), + "one range code too few": (lambda m: m["classes"].__setitem__(q, m["classes"][q][:-1]), matrix.errors), + "= first in an indicator": (lambda m: m["values"][q].__setitem__(5, "="), matrix.errors), + "= after a missing result": ( + lambda m: m["values"][q].__setitem__(1, None) or m["values"][q].__setitem__(2, "="), + matrix.errors, + ), + } + for name, (change, check) in cases.items(): + with self.subTest(name): + changed = helpers.mutated(self.full, change) + found = check(changed, self.data) if check is matrix.against else check(changed) + self.assertNotEqual(found, [], name) + self.assertNotIn(fileformat.STOPPED, found) + + def test_counts_of_a_range_are_what_the_matrix_holds(self): + def moved(d): + block = d["counts"]["ranges"]["three..four"][B]["classes"] + block[rule.AGREES] -= 1 + block[rule.NEAR_ZERO] += 1 + + changed = helpers.mutated(self.data, moved) + self.assertIn("counts of 'three..four' in 'x:b': `classes` is not what the matrix holds", + matrix.against(self.full, changed)) # fmt: skip + + +class Description(unittest.TestCase): + def write(self, tmp, ranges): + here = Path(tmp) + (here / "items.csv").write_text("item,unit\np,kg\nq,kg\n", encoding="utf-8") + for n in range(4): + (here / f"s{n}.csv").write_text(f"item,{A}\np,{P[n]}\nq,{Q[n]}\n", encoding="utf-8") + spec = { + "title": "Four states", + "indicators": [{"id": A, "name": "Indicator A"}], + "items": "items.csv", + "states": [{"id": f"s{n}", "label": f"State {n}", "results": f"s{n}.csv"} for n in range(4)], + "steps": [{"id": s, "label": s, "kind": "fix"} for s in STEPS[:3]], + } + if ranges is not None: + spec["ranges"] = ranges + path = here / "description.json" + path.write_text(json.dumps(spec), encoding="utf-8") + return path + + def test_a_description_chooses_its_ranges(self): + for said, ids in ( + (None, ["one..two", "two..three"]), + ("none", None), + ([["two", "three"]], ["two..three"]), + ({"within": ["one", "two"]}, ["one..two"]), + ): + with self.subTest(said), tempfile.TemporaryDirectory() as tmp: + data = from_tables.build(self.write(tmp, said)) + self.assertEqual([r["id"] for r in data["ranges"]] if "ranges" in data else None, ids) + + def test_a_wrong_choice_is_a_sentence(self): + for said in ("every", [["one"]], [["one", "nine"]], {"within": ["one"]}, {"from": ["one", "two"]}): + with self.subTest(said), tempfile.TemporaryDirectory() as tmp: + path = self.write(tmp, said) + spec = json.loads(path.read_text()) + self.assertTrue(any("`ranges`" in e for e in from_tables.description_errors(spec))) + + +if __name__ == "__main__": + unittest.main() From 5eee8c6f62f2f5bbc7bf27b6ef9a30d53902bd49 Mon Sep 17 00:00:00 2001 From: Manuel Klarmann Date: Tue, 17 Nov 2026 04:11:38 +0100 Subject: [PATCH 2/9] Page: Shift chooses every step of a run; quiet steps of a run fold into one line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Shift-click chose only the two ends of a run, so the steps between were hatched as if taken in, and so did a run opened from an address. Now Shift and an address choose every step of the run; only steps between two chosen with ⌘ or Ctrl are hatched. In a run's line, two or more steps with a claim where nothing moved and nothing was judged fold into one line that opens to each. A run of twelve fixes where one moves something now reads as that one, and one line for the rest. Co-Authored-By: Claude Opus 5.5 --- SPEC.md | 5 +- src/sentier_diagnostics/page/diagnostics.css | 2 + src/sentier_diagnostics/page/diagnostics.js | 48 ++++++++++++++------ tests/js/page.test.js | 43 ++++++++++++++++++ 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/SPEC.md b/SPEC.md index c350b50..3ad7492 100644 --- a/SPEC.md +++ b/SPEC.md @@ -547,7 +547,10 @@ step taken in only because it lies between two chosen ones is hatched. The matri distributions, the worst values and the drawer then show the range: the file's own counts and classes of it, never a sum of its steps. Its line says which states it goes between, which steps lie between the chosen ones and why they are taken in, and each step's claim -with what it found in that step alone; it says that a range has no noise and no verdict. +with what it found in that step alone (two or more steps with a claim where nothing moved +fold into one line, each still there to open); it says that a range has no noise and no +verdict. An address names a run, not how it was chosen: opened from one, every step of the +run is chosen. Every step chosen is the whole way. A run the file does not compare is said, with the runs it does, and nothing changes; a step inside a run cannot be taken off, and the page says so. The address keeps a range by its id (`#step=first..last`); an address that names a run diff --git a/src/sentier_diagnostics/page/diagnostics.css b/src/sentier_diagnostics/page/diagnostics.css index cab8f51..bb3066a 100644 --- a/src/sentier_diagnostics/page/diagnostics.css +++ b/src/sentier_diagnostics/page/diagnostics.css @@ -87,6 +87,8 @@ .sentier-diagnostics .sd-notice { padding: 0.2rem 0.5rem; border-left: 3px solid var(--sd-line-strong); background: var(--sd-surface); } .sentier-diagnostics .sd-claims { margin: 0.25rem 0; padding-left: 1.2rem; } .sentier-diagnostics .sd-claims > li + li { margin-top: 0.2rem; } +.sentier-diagnostics .sd-quiet-steps { margin: 0.25rem 0; } +.sentier-diagnostics .sd-quiet-steps > summary { cursor: pointer; color: var(--sd-muted); font-size: var(--sd-t-sm); padding-left: 1.2rem; } .sentier-diagnostics .sd-drawer tr.sd-in-run > * { background: var(--sd-paper-deep); } /* the line of the chosen step: what it compares, its claim and what the claim found, its rule */ diff --git a/src/sentier_diagnostics/page/diagnostics.js b/src/sentier_diagnostics/page/diagnostics.js index 7625974..0646b74 100644 --- a/src/sentier_diagnostics/page/diagnostics.js +++ b/src/sentier_diagnostics/page/diagnostics.js @@ -733,11 +733,16 @@ // what a step claims, who claimed it, and what the claim found in that step: every verdict // on a move, "as claimed" first, each with its count; the ones worth a look carry their // mark, as on the chips. No colour: a verdict is not an approval (ADR 0010). + // each verdict on a step's moves with its count, the ones with none left out + function verdictsOf(s) { + return ['as claimed'].concat(LOOK).map(function (name) { return [name, sumOver(s.id, function (b) { return b.verdicts[name]; })]; }) + .filter(function (p) { return p[1]; }); + } + function claimParts(s) { if (!s.claim) return [el('span', { cls: 'sd-quiet', text: 'none: what moves here is counted, not judged.' })]; var claim = [s.claim.text, ' ', badge(s.claim.by)]; - var found = ['as claimed'].concat(LOOK).map(function (name) { return [name, sumOver(s.id, function (b) { return b.verdicts[name]; })]; }) - .filter(function (p) { return p[1]; }); + var found = verdictsOf(s); claim.push(el('span', { cls: 'sd-verdicts', text: found.length ? ' ' + found.map(function (p) { return n(p[1]) + ' ' + (p[1] === 1 ? 'value' : 'values') + ' ' + (p[0] === 'as claimed' ? 'moved as claimed' : p[0]) + (LOOK_MARK[p[0]] ? ' ' + LOOK_MARK[p[0]] : ''); }).join(', ') + '.' : ' Nothing moved, as claimed.' })); @@ -791,16 +796,26 @@ node.appendChild(el('p', { cls: 'sd-quiet', text: (between.length === 1 ? 'Step ' : 'Steps ') + stepList(between) + (between.length === 1 ? ' lies' : ' lie') + ' between the steps chosen and ' + (between.length === 1 ? 'is' : 'are') + ' taken in: each state is built on the one before it, so steps are compared together only as a run.' })); } + // the steps where something moved or was judged come first; the quiet ones (a claim, + // nothing moved, no verdict) fold into one line, each still there to open var list = el('ul', { cls: 'sd-claims' }); + var quiet = [], folded = el('ul', { cls: 'sd-claims' }); for (k = run[0]; k <= run[1]; k++) { var s = D.steps[k]; var alone = sumOver(s.id, moved); - list.appendChild(el('li', null, [el('strong', { text: 'Step ' + stepNo(k) + ': ' + s.label + '. ' }), + var row = el('li', null, [el('strong', { text: 'Step ' + stepNo(k) + ': ' + s.label + '. ' }), s.explained ? null : el('span', { cls: 'sd-error', text: 'Nothing explains it. ' }), el('span', { cls: 'sd-claim-label', text: 'Claim' })].concat(claimParts(s), - [el('span', { cls: 'sd-quiet', text: ' In this step alone: ' + (alone === 1 ? '1 value' : n(alone) + ' values') + ' moved.' })]))); + [el('span', { cls: 'sd-quiet', text: ' In this step alone: ' + (alone === 1 ? '1 value' : n(alone) + ' values') + ' moved.' })])); + if (s.claim && s.explained && !alone && !verdictsOf(s).length) { quiet.push(k); folded.appendChild(row); } + else list.appendChild(row); + } + if (quiet.length < 2) { while (folded.childNodes.length) list.appendChild(folded.childNodes[0]); quiet = []; } + if (list.childNodes.length) node.appendChild(list); + if (quiet.length) { + node.appendChild(el('details', { cls: 'sd-quiet-steps' }, [el('summary', { text: 'Steps ' + stepList(quiet) + + ': nothing moved in any of them, as each claims.' }), folded])); } - node.appendChild(list); node.appendChild(el('p', { cls: 'sd-quiet', text: 'Tolerance ' + r.tolerance + ', the largest of these steps; no noise, and no verdict: a run is judged as the whole way is, and each claim is judged in its own step.' })); } @@ -1618,12 +1633,19 @@ return true; } + // every step of the steps a to b + function stepsFrom(a, b) { + var out = []; + for (var k = a; k <= b; k++) out.push(k); + return out; + } + // `picked`: the steps chosen by hand, of a run; the others of it lie between. Without - // it, a new comparison has its ends picked and the same one keeps what it had + // it, a new comparison has every step of it picked and the same one keeps what it had function choose(comp, picked) { var same = comp === view.comp; if (picked) view.picked = picked; - else if (!same) view.picked = comp === 'total' ? [] : runOf(comp); + else if (!same) view.picked = comp === 'total' ? [] : stepsFrom(runOf(comp)[0], runOf(comp)[1]); view.comp = comp; markChips(); renderStepSaid(); @@ -1633,16 +1655,16 @@ if (view.open) renderItem(view.open, true); } - // a click on a step's chip ("one"): that step alone. "to" (Shift, or a second click with - // "Several steps" on): the steps from the one chosen before to this one. "toggle" (⌘ or - // Ctrl): the chosen steps grown to this one or, where it is an end of them, shrunk by it. - // Steps chosen together are a run: what lies between them is taken in, and the step line - // says so. A run the file does not compare is said, and nothing changes. + // a click on a step's chip ("one"): that step alone. "to" (Shift): every step from the one + // chosen before to this one. "toggle" (⌘ or Ctrl, or a plain click with "Several steps" + // on): the chosen steps grown to this one or, where it is an end of them, shrunk by it; + // what lies between steps chosen apart is taken in, and the step line says so. A run the + // file does not compare is said, and nothing changes. function pick(k, how) { var run = view.comp === 'total' ? null : runOf(view.comp); var a = k, b = k, picked = [k]; if (how === 'to' && view.anchor !== null) { - a = Math.min(view.anchor, k); b = Math.max(view.anchor, k); picked = [view.anchor, k]; + a = Math.min(view.anchor, k); b = Math.max(view.anchor, k); picked = stepsFrom(a, b); } else if (how === 'toggle' && run) { if (k < run[0] || k > run[1]) { a = Math.min(run[0], k); b = Math.max(run[1], k); picked = view.picked.concat([k]); diff --git a/tests/js/page.test.js b/tests/js/page.test.js index 4476661..058cbf9 100644 --- a/tests/js/page.test.js +++ b/tests/js/page.test.js @@ -852,6 +852,49 @@ test('Shift-click chooses the steps from one to another together: the range the heads.forEach((ind, k) => assert.equal(cls[k], item.classes[ind][at], ind)); }); +test('Shift-click chooses every step of the run: none of them lies between', () => { + const data = example(); + const id = data.steps[1].id + '..' + data.steps[3].id; + assert.ok(data.ranges.some((r) => r.id === id)); + const drawn = dom.page(data); + chipOf(drawn, data.steps[1].id).dispatch('click', {}); + chipOf(drawn, data.steps[3].id).dispatch('click', { shiftKey: true }); + assert.deepEqual(pressed(drawn), data.steps.slice(1, 4).map((s) => s.id)); + for (const s of data.steps.slice(1, 4)) assert.doesNotMatch(chipOf(drawn, s.id).className, /sd-between/, s.id); + assert.doesNotMatch(drawn.byId['step-said'].textContent, /between the steps chosen/); + // an address names a run, not how it was chosen: every step of it is chosen + drawn.open('step=' + encodeURIComponent(data.steps[0].id + '..' + data.steps[2].id)); + for (const s of data.steps.slice(0, 3)) assert.doesNotMatch(chipOf(drawn, s.id).className, /sd-between/, s.id); +}); + +test('in a run, the steps where nothing moved and nothing was judged fold into one line', () => { + const tagged = (node, tag) => (node.tagName === tag ? [node] : []).concat(...(node.childNodes || []).map((c) => tagged(c, tag))); + const data = example(); + const range = data.ranges.find((r) => r.steps.length === 3); + const at = range.steps.map((id) => data.steps.findIndex((s) => s.id === id)); + const drawn = dom.page(data); + drawn.open('step=' + encodeURIComponent(range.id)); + // the example's steps move something: nothing folds, every step has its own line + assert.equal(tagged(drawn.byId['step-said'], 'DETAILS').length, 0); + for (const k of at) assert.ok(drawn.byId['step-said'].textContent.includes('Step ' + k + ': ' + data.steps[k].label), k); + // the first two steps made quiet in the file's counts: a claim, nothing moved, no verdict + const calm = example(); + for (const id of range.steps.slice(0, 2)) { + for (const block of Object.values(calm.counts.steps[id])) { + for (const name of Object.keys(block.classes)) block.classes[name] = 0; + for (const name of Object.keys(block.verdicts)) block.verdicts[name] = 0; + } + } + const shown = dom.page(calm); + shown.open('step=' + encodeURIComponent(range.id)); + const folded = tagged(shown.byId['step-said'], 'DETAILS'); + assert.equal(folded.length, 1); + assert.match(folded[0].textContent, new RegExp('^Steps ' + at[0] + ' and ' + at[1] + ': nothing moved in any of them, as each claims\\.')); + for (const k of at.slice(0, 2)) assert.ok(folded[0].textContent.includes('Step ' + k + ': ' + calm.steps[k].label), 'each is still there to open'); + assert.ok(!folded[0].textContent.includes('Step ' + at[2] + ': '), 'the step that moved stays outside'); + assert.ok(shown.byId['step-said'].textContent.includes('Step ' + at[2] + ': ' + calm.steps[at[2]].label)); +}); + test('steps chosen apart take in the steps between them, and the page says so', () => { const data = example(); const drawn = dom.page(data); From 193c74570ee6cbbbf52e77ea14daf14ada9180d7 Mon Sep 17 00:00:00 2001 From: Manuel Klarmann Date: Tue, 17 Nov 2026 04:17:10 +0100 Subject: [PATCH 3/9] Ranges: none asked for is [], apart from a file made before ranges; the default warns Two states had collapsed into one silence: a file whose producer asked for no ranges and a file made before ranges existed both left the key out. Now a file holds `ranges: []` (and `counts.ranges: {}`) where none was asked for, and only an older file leaves the key out. The page says which of the two it is when a reader asks for several steps. A chain that gained a ninth step lost every range under the default without anyone choosing it. The build now warns when the default leaves a chain without ranges, naming the ways to ask for them. Both points from the sentier-diagnostics session's review. Co-Authored-By: Claude Opus 5.5 --- SPEC.md | 11 +++--- src/sentier_diagnostics/chain.py | 15 +++++++-- src/sentier_diagnostics/fileformat.py | 20 ++++++----- src/sentier_diagnostics/page/diagnostics.js | 6 ++-- tests/js/page.test.js | 15 +++++++-- tests/test_ranges.py | 37 +++++++++++++++++---- 6 files changed, 76 insertions(+), 28 deletions(-) diff --git a/SPEC.md b/SPEC.md index 91ebfcd..92151b2 100644 --- a/SPEC.md +++ b/SPEC.md @@ -108,8 +108,11 @@ combination is the producer's business: 11 fixes have 2,047 of them. `(first step, last step)` pairs (`chain.ranges_within` gives every run between two steps, such as the fixes of a build), or none. Without a choice, a chain of at most 8 steps has every range and a longer one none (`chain.AUTO_RANGES`): n steps have n(n-1)/2 - 1 ranges, -and each is a comparison of every item in every indicator. A description of CSV tables -says the same in its `ranges` key. +and each is a comparison of every item in every indicator. A chain that the default leaves +without ranges is built with a warning that says so, so a chain that gains a ninth step does +not lose its ranges unseen. A description of CSV tables says the same in its `ranges` key. +A file where none was asked for holds `ranges: []`; only a file made before ranges leaves +the key out, and the page says which of the two it is. **One chain per reference.** A database with two references (sentier-bafu-agribalyse has ADEME's published results on ecoinvent and its own build on ecoinvent) gets one file per @@ -147,8 +150,8 @@ control characters, bounded lengths. | `rule` | The floors and the tolerance of the whole way (section 5) | | `states` | `[{id, label, about, kind, identity, join}]` in order. `identity` is a short table of texts (commit, release, machine); `join` is what the reader counted when it matched its rows to items: `{compared, unmatched, ambiguous, note}`, or null | | `steps` | `[{id, from, to, label, about, kind, explained, link, claim, tolerance, noise}]`, one fewer than the states, each from one state to the next | -| `ranges` | Optional. `[{id, steps, from, to, tolerance}]`: the runs of consecutive steps compared as one (section 3). `id` is `first..last`, `from` the state before the first step, `to` the state after the last, `tolerance` the largest of its steps. Absent where the file has none | -| `counts` | `{steps: {step: {indicator: block}}, total: {indicator: block}}`, and `ranges: {range: {indicator: block}}` where, and only where, the file has ranges | +| `ranges` | Optional. `[{id, steps, from, to, tolerance}]`: the runs of consecutive steps compared as one (section 3). `id` is `first..last`, `from` the state before the first step, `to` the state after the last, `tolerance` the largest of its steps. `[]` where none was asked for; absent only in a file made before ranges | +| `counts` | `{steps: {step: {indicator: block}}, total: {indicator: block}}`, and `ranges: {range: {indicator: block}}` where, and only where, the file has its `ranges` key (`{}` for `[]`) | | `attribution` | `{indicator: {dominant: {step: n}, not_attributable: n, spread: n, unexplained_moved: n}}` (section 7) | | `items` | The listed items, worst first (section 10.4) | | `items_count` | `{all, qualifying, listed, not_listed}` | diff --git a/src/sentier_diagnostics/chain.py b/src/sentier_diagnostics/chain.py index c15f0dd..17aa755 100644 --- a/src/sentier_diagnostics/chain.py +++ b/src/sentier_diagnostics/chain.py @@ -29,6 +29,7 @@ from __future__ import annotations import json +import warnings from collections.abc import Iterable, Mapping from pathlib import Path @@ -177,6 +178,14 @@ def _ranges(said, out_steps: list[dict]) -> list[dict]: n = len(ids) if said == "auto": said = "all" if n <= AUTO_RANGES else None + if said is None: + # a chain that grows past the limit loses its ranges: never without a word + warnings.warn( + f"a chain of {n} steps has no ranges unless asked (more than {AUTO_RANGES} steps): " + "pass ranges=\"all\", chain.ranges_within(steps, first, last) or (first, last) pairs, " + "or ranges=None to say that none is wanted", + stacklevel=4, + ) if said is None: return [] if said == "all": @@ -430,8 +439,7 @@ def block(c, indicator): "steps": {s["id"]: {i: block(k, i) for i in ids} for k, s in enumerate(out_steps)}, "total": {i: block(nsteps, i) for i in ids}, } - if out_ranges: - counts["ranges"] = {r["id"]: {i: block(nsteps + 1 + j, i) for i in ids} for j, r in enumerate(out_ranges)} + counts["ranges"] = {r["id"]: {i: block(nsteps + 1 + j, i) for i in ids} for j, r in enumerate(out_ranges)} # attribution: which step carries the largest share of each item's whole difference attribution = {} @@ -533,7 +541,8 @@ def record_of(item): for s in states ], # fmt: skip "steps": out_steps, - **({"ranges": out_ranges} if out_ranges else {}), + # [] where none was asked for: only a file made before ranges leaves the key out + "ranges": out_ranges, "counts": counts, "attribution": attribution, "items": out_items, diff --git a/src/sentier_diagnostics/fileformat.py b/src/sentier_diagnostics/fileformat.py index ac51df4..79632d4 100644 --- a/src/sentier_diagnostics/fileformat.py +++ b/src/sentier_diagnostics/fileformat.py @@ -383,12 +383,14 @@ def _steps(data, found, states, indicators, tier) -> list[dict]: def _ranges(data, found, steps) -> list[dict] | None: """The ranges of a file: runs of consecutive steps, each compared as the whole way is - (SPEC section 5.5). None where they cannot be read; nothing where the file has none.""" - said = data.get("ranges") - if said is None: + (SPEC section 5.5). None where they cannot be read; nothing where the file has none: + `[]` where none was asked for, the key left out in a file made before ranges.""" + if "ranges" not in data: return [] - if not isinstance(said, list) or not 0 < len(said) <= MAX_RANGES: - found.append(f"`ranges` is a list of 1 to {MAX_RANGES} ranges, or left out") + said = data["ranges"] + if not isinstance(said, list) or len(said) > MAX_RANGES: + found.append(f"`ranges` is a list of at most {MAX_RANGES} ranges ([] where none was asked for), " + "or left out in a file made before ranges") return None ids = [s["id"] for s in steps] seen = set() @@ -527,16 +529,16 @@ def _block(block, where, step) -> list[str]: def _counts(data, found, indicators, steps, ranges, total_pairs): counts = data.get("counts") - keys = {"steps", TOTAL} | ({"ranges"} if ranges else set()) + keys = {"steps", TOTAL} | ({"ranges"} if "ranges" in data else set()) if not isinstance(counts, dict) or set(counts) != keys: - found.append(f"`counts` is not {{{', '.join(sorted(keys))}}}: ranges are counted where, and only where, the file has them") + found.append(f"`counts` is not {{{', '.join(sorted(keys))}}}: ranges are counted where, and only where, the file has its key") return {} by_step = counts["steps"] if not isinstance(by_step, dict) or set(by_step) != {s["id"] for s in steps}: found.append("`counts.steps` does not hold every step") return {} - by_range = counts.get("ranges") or {} - if ranges and (not isinstance(by_range, dict) or set(by_range) != {r["id"] for r in ranges}): + by_range = counts.get("ranges", {}) + if not isinstance(by_range, dict) or set(by_range) != {r["id"] for r in ranges}: found.append("`counts.ranges` does not hold every range") return {} published_first = data["states"][0]["kind"] == "published" diff --git a/src/sentier_diagnostics/page/diagnostics.js b/src/sentier_diagnostics/page/diagnostics.js index 3eb437c..b90ff22 100644 --- a/src/sentier_diagnostics/page/diagnostics.js +++ b/src/sentier_diagnostics/page/diagnostics.js @@ -364,7 +364,7 @@ typeof d.indicator.many === 'string')) return 'the indicator word of the file is not {one, many}'; if (d.steps.length !== d.states.length - 1) return 'the file has not one step fewer than states'; if (!d.counts.steps || !d.counts.total) return 'the counts of the file are not {steps, total}'; - if (d.ranges !== undefined && d.ranges !== null) { + if (d.ranges !== undefined) { if (!Array.isArray(d.ranges)) return 'the ranges of the file are not a list'; if (!d.counts.ranges || typeof d.counts.ranges !== 'object') return 'the file has ranges and no counts of them'; for (var r = 0; r < d.ranges.length; r++) { @@ -564,7 +564,9 @@ // which runs the file compares, in words, for a page that is asked for one it has not function rangesSaid() { var all = ranges(); - if (!all.length) return 'This file compares no run of steps: choose one step, or the whole way.'; + // a file made before ranges, and one whose writer asked for none, are said apart + if (!('ranges' in D)) return 'This file was made before runs of steps could be compared: choose one step, or the whole way.'; + if (!all.length) return 'This file compares no run of steps: none was asked for when it was made. Choose one step, or the whole way.'; var lo = D.steps.length, hi = -1, counted = {}; all.forEach(function (r) { var run = runOf(r.id); lo = Math.min(lo, run[0]); hi = Math.max(hi, run[1]); counted[run[0] + ':' + run[1]] = true; }); var every = true; diff --git a/tests/js/page.test.js b/tests/js/page.test.js index aeb691c..62cca1c 100644 --- a/tests/js/page.test.js +++ b/tests/js/page.test.js @@ -966,14 +966,23 @@ test('Shift and an arrow key grow the run, and a file without ranges offers no s assert.deepEqual(pressed(drawn), data.steps.slice(1, 3).map((s) => s.id)); drawn.byId.comparison.dispatch('keydown', { key: 'ArrowLeft', shiftKey: true }); assert.deepEqual(pressed(drawn), [data.steps[1].id]); + // none asked for, and a file made before ranges: both offer no several steps, said apart const none = example(); - delete none.ranges; - delete none.counts.ranges; + none.ranges = []; + none.counts.ranges = {}; const shown = dom.page(none); assert.equal(shown.byId.pick.hidden, true); chipOf(shown, none.steps[1].id).dispatch('click', {}); chipOf(shown, none.steps[2].id).dispatch('click', { shiftKey: true }); - assert.match(shown.byId['step-said'].textContent, /This file compares no run of steps/); + assert.match(shown.byId['step-said'].textContent, /This file compares no run of steps: none was asked for when it was made/); + const older = example(); + delete older.ranges; + delete older.counts.ranges; + const old = dom.page(older); + assert.equal(old.byId.pick.hidden, true); + chipOf(old, older.steps[1].id).dispatch('click', {}); + chipOf(old, older.steps[2].id).dispatch('click', { shiftKey: true }); + assert.match(old.byId['step-said'].textContent, /This file was made before runs of steps could be compared/); }); test('a matrix result written "=" is the result before it, and a "=" that stands first is refused', () => { diff --git a/tests/test_ranges.py b/tests/test_ranges.py index 7d9c9ad..8287976 100644 --- a/tests/test_ranges.py +++ b/tests/test_ranges.py @@ -5,6 +5,7 @@ import json import tempfile import unittest +import warnings from pathlib import Path from sentier_diagnostics import chain, claims, fileformat, from_tables, matrix, rule @@ -88,10 +89,25 @@ def test_a_range_has_no_verdict_and_no_closer_or_further(self): p = next(i for i in data["items"] if i["id"] == "p") self.assertEqual(len(p["verdicts"][A]), len(STEPS)) - def test_no_ranges_leaves_the_file_as_it_was(self): + def test_no_ranges_says_none_was_asked_for(self): data, _ = five_states(ranges=None) - self.assertNotIn("ranges", data) - self.assertNotIn("ranges", data["counts"]) + self.assertEqual(data["ranges"], []) # not left out: that is a file made before ranges + self.assertEqual(data["counts"]["ranges"], {}) + self.assertEqual(fileformat.errors(data), []) + + def test_a_file_made_before_ranges_and_one_that_asked_for_none_are_kept_apart(self): + data, _ = five_states(ranges=None) + before = json.loads(json.dumps(data)) + del before["ranges"], before["counts"]["ranges"] + self.assertEqual(fileformat.errors(before), []) # a file made before ranges still reads + for broken, says in ( + (lambda d: d.update(ranges=None), "`ranges` is a list"), + (lambda d: d["counts"].pop("ranges"), "`counts` is not"), # [] without its counts + (lambda d: d.pop("ranges"), "`counts` is not"), # counts of ranges, and no key + ): + one = json.loads(json.dumps(data)) + broken(one) + self.assertTrue(any(says in e for e in fileformat.errors(one)), says) self.assertEqual(len(data["items"][0]["classes"][A]), len(STEPS) + 1) self.assertNotIn("q", [i["id"] for i in data["items"]]) # nothing moved it without its ranges @@ -100,8 +116,15 @@ def steps(n): return [{"id": f"k{k}", "from": f"s{k}", "to": f"s{k + 1}", "tolerance": {"value": 0.01}} for k in range(n)] # fmt: skip - self.assertEqual(len(chain._ranges("auto", steps(chain.AUTO_RANGES))), 8 * 7 // 2 - 1) - self.assertEqual(chain._ranges("auto", steps(chain.AUTO_RANGES + 1)), []) + with warnings.catch_warnings(): + warnings.simplefilter("error") # every range up to the limit, and not a word + self.assertEqual(len(chain._ranges("auto", steps(chain.AUTO_RANGES))), 8 * 7 // 2 - 1) + # past the limit none, and the build says so: a ninth step does not drop them unseen + with self.assertWarnsRegex(UserWarning, r"a chain of 9 steps has no ranges unless asked"): + self.assertEqual(chain._ranges("auto", steps(chain.AUTO_RANGES + 1)), []) + with warnings.catch_warnings(): + warnings.simplefilter("error") # asked for none: nothing to warn of + self.assertEqual(chain._ranges(None, steps(chain.AUTO_RANGES + 1)), []) self.assertEqual(chain._ranges("auto", steps(1)), []) self.assertEqual(chain._ranges("auto", steps(2)), []) # the one run of two is the whole way @@ -281,13 +304,13 @@ def write(self, tmp, ranges): def test_a_description_chooses_its_ranges(self): for said, ids in ( (None, ["one..two", "two..three"]), - ("none", None), + ("none", []), ([["two", "three"]], ["two..three"]), ({"within": ["one", "two"]}, ["one..two"]), ): with self.subTest(said), tempfile.TemporaryDirectory() as tmp: data = from_tables.build(self.write(tmp, said)) - self.assertEqual([r["id"] for r in data["ranges"]] if "ranges" in data else None, ids) + self.assertEqual([r["id"] for r in data["ranges"]], ids) def test_a_wrong_choice_is_a_sentence(self): for said in ("every", [["one"]], [["one", "nine"]], {"within": ["one"]}, {"from": ["one", "two"]}): From cd51bb3fbda77e8a97a6e574bbe964ba54b3362e Mon Sep 17 00:00:00 2001 From: Manuel Klarmann Date: Tue, 17 Nov 2026 04:24:27 +0100 Subject: [PATCH 4/9] Matrix: of.ranges as the file's ranges, so a matrix made before ranges reads with its file A file made before ranges was accepted, its matrix refused: of.ranges was required. Now a matrix mirrors its file: of.ranges is [] where none was asked for and left out where the file was made before ranges, and a matrix of one kind is never taken for a file of the other. Found in review by the sentier-diagnostics session. Co-Authored-By: Claude Opus 5.5 --- SPEC.md | 3 +++ src/sentier_diagnostics/matrix.py | 13 +++++++------ src/sentier_diagnostics/page/diagnostics.js | 3 ++- tests/js/page.test.js | 5 +++++ tests/test_ranges.py | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/SPEC.md b/SPEC.md index 92151b2..1579c63 100644 --- a/SPEC.md +++ b/SPEC.md @@ -239,6 +239,9 @@ writes it beside the file. "verdicts": ["a.==", ...]} ``` +`of.ranges` is as the file's `ranges`: `[]` where none was asked for, left out in a matrix +made before ranges, as its file was. A matrix and its file always agree on which. + One row per item, in the order of the listed items (worst first): `[id, name, place, group, unit]`; the results per indicator and state, indicator after indicator, a result that is the same number as the state before it (bit for bit) written `"="`; per indicator diff --git a/src/sentier_diagnostics/matrix.py b/src/sentier_diagnostics/matrix.py index 119e067..0f7f09a 100644 --- a/src/sentier_diagnostics/matrix.py +++ b/src/sentier_diagnostics/matrix.py @@ -125,7 +125,8 @@ def make(data: Mapping, rows: list[dict]) -> dict: "states": [s["id"] for s in data["states"]], "indicators": ids, "steps": [s["id"] for s in steps], - "ranges": [r["id"] for r in data.get("ranges") or []], + # as the file: [] where none was asked for, left out where it was made before ranges + **({"ranges": [r["id"] for r in data["ranges"]]} if "ranges" in data else {}), }, "items": [], "values": [], @@ -231,14 +232,14 @@ def _errors(m) -> list[str]: of = m["of"] if not ( isinstance(of, dict) - and set(of) == OF_KEYS + and set(of) in (OF_KEYS, OF_KEYS - {"ranges"}) and fileformat.is_text(of["title"], 120) and all(isinstance(of[k], list) and all(fileformat.is_text(x, 2 * fileformat.MAX_ID + 2) for x in of[k]) - for k in ("states", "indicators", "steps", "ranges")) + for k in ("states", "indicators", "steps", "ranges") if k in of) ): # fmt: skip - return ["`of` is not {title, states, indicators, steps, ranges}"] + return ["`of` is not {title, states, indicators, steps, ranges} (ranges left out only before ranges)"] nstates, nind, nsteps = len(of["states"]), len(of["indicators"]), len(of["steps"]) - ncodes = nsteps + 1 + len(of["ranges"]) + ncodes = nsteps + 1 + len(of.get("ranges", [])) if nsteps != nstates - 1 or not nind: return ["`of`: one step fewer than states, and at least one indicator"] items = m["items"] @@ -300,7 +301,7 @@ def _against(m: Mapping, data: Mapping) -> list[str]: steps = data["steps"] ranges = data.get("ranges") or [] of = {"title": data["title"], "states": order, "indicators": ids, "steps": [s["id"] for s in steps], - "ranges": [r["id"] for r in ranges]} # fmt: skip + **({"ranges": [r["id"] for r in ranges]} if "ranges" in data else {})} # fmt: skip if m["of"] != of: return ["it is the matrix of another file: its title, states, indicators, steps or ranges differ"] n = len(m["items"]) diff --git a/src/sentier_diagnostics/page/diagnostics.js b/src/sentier_diagnostics/page/diagnostics.js index b90ff22..1cd46d9 100644 --- a/src/sentier_diagnostics/page/diagnostics.js +++ b/src/sentier_diagnostics/page/diagnostics.js @@ -406,7 +406,8 @@ var ids = d.indicators.map(function (i) { return i.id; }); if (of.title !== d.title || !sameList(of.states, d.states.map(function (s) { return s.id; })) || !sameList(of.indicators, ids) || !sameList(of.steps, d.steps.map(function (s) { return s.id; })) || - !sameList(of.ranges, (d.ranges || []).map(function (r) { return r.id; }))) { + ('ranges' in of) !== ('ranges' in d) || + ('ranges' in d && !sameList(of.ranges, d.ranges.map(function (r) { return r.id; })))) { return 'it is the matrix of another file: its title, states, indicators, steps or ranges differ'; } if (!Array.isArray(m.items) || m.items.length > MATRIX_MAX_ITEMS) return 'its items are not a list of at most ' + groupThousands(MATRIX_MAX_ITEMS); diff --git a/tests/js/page.test.js b/tests/js/page.test.js index 62cca1c..0ef6e23 100644 --- a/tests/js/page.test.js +++ b/tests/js/page.test.js @@ -335,6 +335,11 @@ test('a matrix of another file, or of another shape, is refused', () => { assert.match(page.checkMatrix(wrong, data), /not a number/); const fewer = full(); fewer.items.pop(); fewer.values.pop(); fewer.classes.pop(); fewer.verdicts.pop(); assert.match(page.checkMatrix(fewer, data), /says 10 items/); + // a matrix made before ranges belongs to a file made before ranges, and only to one + const before = full(); delete before.of.ranges; + assert.match(page.checkMatrix(before, data), /another file/); + const older = local(); delete older.ranges; delete older.counts.ranges; + assert.match(page.checkMatrix(full(), older), /another file/); }); test('the grid shows the listed items, says so, and every item once the matrix is here', () => { diff --git a/tests/test_ranges.py b/tests/test_ranges.py index 8287976..64ee45f 100644 --- a/tests/test_ranges.py +++ b/tests/test_ranges.py @@ -282,6 +282,21 @@ def moved(d): matrix.against(self.full, changed)) # fmt: skip +class BeforeRanges(unittest.TestCase): + def test_a_file_and_its_matrix_made_before_ranges_still_read_together(self): + data, m = five_states(ranges=None, matrix_file="matrix.json") + self.assertEqual(m["of"]["ranges"], []) # none asked for: said, as the file says it + self.assertEqual(matrix.errors(m) + matrix.against(m, data), []) + before = json.loads(json.dumps(data)) + del before["ranges"], before["counts"]["ranges"] + old = json.loads(json.dumps(m)) + del old["of"]["ranges"] + self.assertEqual(matrix.errors(old) + matrix.against(old, before), []) + # one made before ranges and one made after are not each other's + self.assertTrue(any("another file" in e for e in matrix.against(old, data))) + self.assertTrue(any("another file" in e for e in matrix.against(m, before))) + + class Description(unittest.TestCase): def write(self, tmp, ranges): here = Path(tmp) From 304c0bada6fda9aac2c44cf20b65a49f767850a5 Mon Sep 17 00:00:00 2001 From: Manuel Klarmann Date: Tue, 17 Nov 2026 05:37:15 +0100 Subject: [PATCH 5/9] Any set of steps, composed by the page; the whole way takes the noise of its steps Precomputed ranges are gone from the file and the matrix. The page composes any set of steps from every item's results instead: an item's pair is its result before the first chosen step and that result with each run's difference added; a single run is exactly its two states. It judges the pair with the rule ported from rule.py, after holding every chosen step to the file's own classes, and refuses a set whose steps disagree. together.py is the Python reference, and tests/fixtures/together.json holds the counts the page is held to. The whole way (and any set) takes, per indicator, the largest noise measured in its steps: rule.total_noise, checked by the validator and the matrix. A file made before has none and is judged as it was written. The chips are replaced by a strip (one thin cell per step, Shift for a run, Cmd or Ctrl to add one) and a list to find and tick steps by number, name or kind, grouped by kind, with "only steps where something moved". The address names any set: #steps=:,. The matrix writes a result equal to the one before it as "=". Co-Authored-By: Claude Opus 5.5 --- GLOSSARY.md | 3 +- SPEC.md | 189 ++-- examples/diagnostics.json | 661 +------------ examples/local/diagnostics.json | 653 +------------ examples/local/matrix.json | 22 +- src/sentier_diagnostics/chain.py | 196 +--- src/sentier_diagnostics/fileformat.py | 142 ++- src/sentier_diagnostics/from_tables.py | 31 +- src/sentier_diagnostics/matrix.py | 73 +- src/sentier_diagnostics/page/body.html | 27 +- src/sentier_diagnostics/page/diagnostics.css | 67 +- src/sentier_diagnostics/page/diagnostics.js | 945 +++++++++++++------ src/sentier_diagnostics/together.py | 122 +++ tests/fixtures/together.json | 876 +++++++++++++++++ tests/js/page.test.js | 437 ++++++--- tests/test_modules.py | 13 +- tests/test_ranges.py | 339 ------- tests/test_together.py | 241 +++++ 18 files changed, 2506 insertions(+), 2531 deletions(-) create mode 100644 src/sentier_diagnostics/together.py create mode 100644 tests/fixtures/together.json delete mode 100644 tests/test_ranges.py create mode 100644 tests/test_together.py diff --git a/GLOSSARY.md b/GLOSSARY.md index dc52f2f..afc918b 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -9,7 +9,8 @@ The words this repository uses, each in one line. [SPEC.md](SPEC.md) says the re - **Step**: from one state to the next, with its kind, claim, tolerance and noise. - **Step 0**: the reproduction of the published results. The start, never the target. A chain that does not start from the published results has no step 0: its steps are numbered from 1. - **Chain**: the states in order and the steps between them. -- **Range**: a run of at least two consecutive steps, short of every step, compared as one: the state before its first step against the state after its last, judged as the whole way is. Its producer chooses which ranges a file holds. On the page, choosing several steps chooses a range. +- **Whole way**: from the first state to the last, every step together. +- **Set of steps**: any steps chosen together that are neither one step nor the whole way; the page composes it from every item's results. A **run** is a span of chosen steps that follow each other. - **Pair**: one item in one indicator, before and after a step. - **Class**: what a pair is, by one rule: agrees, within noise, differs, beyond 10x, zero reference, zero result, sign change, near zero, missing. - **Moved**: a pair of class differs, beyond 10x, zero reference, zero result or sign change. Only these have a direction. diff --git a/SPEC.md b/SPEC.md index 1579c63..a666e22 100644 --- a/SPEC.md +++ b/SPEC.md @@ -88,31 +88,26 @@ that step, made up, and a test holds what it shows. **Order matters.** Where two steps touch the same results, each one's share depends on the order they were applied in. The file keeps the order; the page says so. -**Ranges: several steps together.** A reviewer of a chain of fixes asks what some of them -did together, not only what each did. A **range** is a run of at least two consecutive -steps, short of every step (that is the whole way): it compares the state before its first -step with the state after its last, and is judged as the whole way is (section 5.3): the -largest tolerance of its steps, no noise, and no verdict, since each claim is judged in its -own step. Its classes are worked out by the rule from those two states, never added up -from its steps: steps that each move 0.8 % under a tolerance of 1 % agree one by one, and -two of them together differ. - -**Decision: a run, not any set.** Each state is built on the one before it, so the only -comparisons a chain holds are between two of its states, and a set of steps with a gap, -such as the first and the third fix, was never built on its own. A page that is asked for -steps apart takes in the steps between them and says so; it never sums steps it cannot -see, and it never claims what a combination nobody built would give. Building every -combination is the producer's business: 11 fixes have 2,047 of them. - -**The producer chooses its ranges** (`ranges` of `chain.build`): `"all"`, a list of -`(first step, last step)` pairs (`chain.ranges_within` gives every run between two steps, -such as the fixes of a build), or none. Without a choice, a chain of at most 8 steps has -every range and a longer one none (`chain.AUTO_RANGES`): n steps have n(n-1)/2 - 1 ranges, -and each is a comparison of every item in every indicator. A chain that the default leaves -without ranges is built with a warning that says so, so a chain that gains a ninth step does -not lose its ranges unseen. A description of CSV tables says the same in its `ranges` key. -A file where none was asked for holds `ranges: []`; only a file made before ranges leaves -the key out, and the page says which of the two it is. +**Several steps together.** A file holds one comparison per step and one for the whole way. +Any other set of steps (steps 2 and 5, steps 3 to 9, every step but 6) is not in the file: +the page composes it from every item's results (`together.py` is the reference). A **run** +is a span of chosen steps that follow each other. An item's pair is its result before the +first chosen step, and that result with each run's difference added (the result after the +run less the result before it). A single run is exactly the two states it lies between. The +pair is judged by the one rule (section 5) with the largest tolerance of the chosen steps +and, per indicator, the largest noise measured in any of them. A set has no verdict: each +claim is judged in its own step. + +Steps apart are an approximation, and the page says so. Each step's difference was made on +top of every step before it, the left-out ones too, so where steps change the same results +the sum is not what the chosen steps would do alone (see "order matters" below). Building +the chosen steps alone is the only exact answer, and the tool computes no LCA (section 12). +A set is never precomputed: there are 2^n − n − 1 of them for n steps, so a file holds the +n steps and the whole way, and the page composes the one a reader asks for: 0.2 to 0.65 s +over 11,947 items and 25 indicators, measured in a browser. It needs every item, so it needs the matrix, +or a file that lists every item. Before it draws a set, the page judges every chosen step on +its own from the same results and holds that to the file's class and direction of the step +for every item; a set whose steps disagree with the file is refused, not drawn. **One chain per reference.** A database with two references (sentier-bafu-agribalyse has ADEME's published results on ecoinvent and its own build on ecoinvent) gets one file per @@ -147,11 +142,10 @@ control characters, bounded lengths. | `item` | `{"one": "product", "many": "products"}`: the word for an item | | `indicator` | Optional. `{"one": "impact category", "many": "impact categories"}`: the word for an indicator, which the page and the summary use; null or absent for "indicator" | | `indicators` | `[{id, name, short, unit}]`. An indicator is matched by its exact id, never by a prefix | -| `rule` | The floors and the tolerance of the whole way (section 5) | +| `rule` | The floors, the tolerance of the whole way and its noise, `total_noise` (section 5.3) | | `states` | `[{id, label, about, kind, identity, join}]` in order. `identity` is a short table of texts (commit, release, machine); `join` is what the reader counted when it matched its rows to items: `{compared, unmatched, ambiguous, note}`, or null | | `steps` | `[{id, from, to, label, about, kind, explained, link, claim, tolerance, noise}]`, one fewer than the states, each from one state to the next | -| `ranges` | Optional. `[{id, steps, from, to, tolerance}]`: the runs of consecutive steps compared as one (section 3). `id` is `first..last`, `from` the state before the first step, `to` the state after the last, `tolerance` the largest of its steps. `[]` where none was asked for; absent only in a file made before ranges | -| `counts` | `{steps: {step: {indicator: block}}, total: {indicator: block}}`, and `ranges: {range: {indicator: block}}` where, and only where, the file has its `ranges` key (`{}` for `[]`) | +| `counts` | `{steps: {step: {indicator: block}}, total: {indicator: block}}` | | `attribution` | `{indicator: {dominant: {step: n}, not_attributable: n, spread: n, unexplained_moved: n}}` (section 7) | | `items` | The listed items, worst first (section 10.4) | | `items_count` | `{all, qualifying, listed, not_listed}` | @@ -173,16 +167,15 @@ A **block** counts one indicator in one step, or over the whole way: "closer": 12, "further": 9} ``` -`verdicts` is null for a step without a claim, for the whole way and for a range. `closer` and +`verdicts` is null for a step without a claim and for the whole way. `closer` and `further` count, for a step after step 0, the moved values that came closer to or went -further from the published results. They are null for step 0, the whole way and a range, null for +further from the published results. They are null for step 0 and the whole way, null for every step of a chain whose first state is not the published results (there is nothing to come closer to), and no page shows them as better or worse. An **item** holds `id, name, place, group, unit` (its reference unit), `values` (per indicator, one result per state, `null` where missing), and per indicator one class, -direction and band per step, then one for the whole way, then one per range in the order of -`ranges`; the verdicts per step (or null +direction and band per step plus one for the whole way, the verdicts per step (or null when no step has a claim), and `breakdowns` (`{step or "total": file name}`, or null). ### 4.3 The validator @@ -199,8 +192,7 @@ many were left out. A file that disagrees with its own rule is refused, not show It also **works the counts out again from the listed items.** Only a pair worth a look adds to the classes that moved, to missing (by side), to directions, bands, the verdicts "as claimed", "off claim", "not claimed" and "claimed, not moved", to `closer` and -`further`, and to the attribution; and every item with such a pair, in a step, the whole -way or a range, is worth a look. So +`further`, and to the attribution; and every item with such a pair is worth a look. So where nothing worth a look is left out (`not_listed` 0), these counts must equal what the listed items hold, and where some are left out, no count may be smaller than what the listed items hold. What only quiet pairs add to (agrees, within noise, near zero, and the @@ -220,6 +212,10 @@ many items as a file may (5,000); a state's identity has up to 12 entries. Ids a 100 characters, labels 80, texts 600 and an explanation's text 2,000. The limits are in `fileformat.py`, and a refusal names the limit it met. +Thirty states is 29 steps. A chain of hundreds of fixes does not fit in one file: each step +adds its counts to the file and its results and codes to every row of the matrix. Raising +the limit is a format decision, open in section 15 (question 7). + ### 4.5 The matrix of every item A file lists the items worth a look, up to `listed`. A project looking at its own build @@ -231,23 +227,21 @@ writes it beside the file. ```json {"format": "sentier-diagnostics-matrix/1", - "of": {"title": "...", "states": ["a", "b", "c"], "indicators": ["x:climate", "x:water"], "steps": ["s0", "s1"], - "ranges": []}, + "of": {"title": "...", "states": ["a", "b", "c"], "indicators": ["x:climate", "x:water"], "steps": ["s0", "s1"]}, "items": [["p01", "Wheat", "FR", "crops", "kg"], ...], - "values": [[0.52, 0.53, 0.47, 1.2, "=", null], ...], + "values": [[0.52, 0.53, 0.47, 1.2, 1.2, null], ...], "classes": ["=Dd===", ...], "verdicts": ["a.==", ...]} ``` -`of.ranges` is as the file's `ranges`: `[]` where none was asked for, left out in a matrix -made before ranges, as its file was. A matrix and its file always agree on which. - One row per item, in the order of the listed items (worst first): `[id, name, place, -group, unit]`; the results per indicator and state, indicator after indicator, a result -that is the same number as the state before it (bit for bit) written `"="`; per indicator -one code per step, one for the whole way and one per range of `of.ranges`; and, where a step has a claim, per +group, unit]`; the results per indicator and state, indicator after indicator; per +indicator one code per step and one for the whole way; and, where a step has a claim, per indicator one verdict code per step (`.` for a step without a claim; `verdicts` is null when -no step has one). The class codes are `=` agrees, `~` within noise, `0` near zero, `-` +no step has one). A result equal to the one before it in the same indicator, bit for bit, is +written `"="`: in a chain of many steps most results do not change, and this keeps the +matrix small. A `"="` that stands first in an indicator or after a missing result is +refused. The class codes are `=` agrees, `~` within noise, `0` near zero, `-` missing, and for a pair that moved its class in upper case up and lower case down: `D` differs, `B` beyond 10x, `R` zero reference, `T` zero result, `S` sign change. The verdict codes are `a` as claimed, `o` off claim, `n` not claimed, `c` claimed, not moved, `~` within @@ -261,12 +255,6 @@ exactly, and every listed item must be in the matrix with the same name and resu `sentier-diagnostics check` does both when the matrix lies beside its file. A matrix holds up to 200,000 items and 64 MB. -The `"="` keeps a chain of fixes small: most fixes leave most results as they were, and -sentier-bafu's chain of 16 states over 11,947 datasets and 25 impact categories would -otherwise hold every number 16 times. It is a writing of the results, not a finding: a -reader writes each `=` out as the number before it, and `"="` that stands first in an -indicator or after a missing result is refused. - ## 5. The counting rule ### 5.1 One class per pair @@ -318,9 +306,7 @@ The **tolerance** says when two results agree. Default 1e-5, relative to the lar two runners differ by up to 2.8e-7 (measured in sentier-bafu) and two solvers by about 3e-7 (sentier-agribalyse), so differences of 1e-6 agree. Step 0 against published results takes the rounding of what was published (`basis: "published rounding"`, e.g. 5e-4 for four -significant digits). The whole way is counted with the largest tolerance of its steps, -and no noise: noise is measured between two builds of one state, and the whole way is not -one step. A range is counted the same way, with the largest tolerance of its own steps. +significant digits). The whole way is counted with the largest tolerance of its steps. The **noise** is measured, never assumed: the largest relative difference between two builds of one state, per indicator, over the items whose results lie beyond the floor in @@ -335,6 +321,16 @@ it. Two words, two jobs: tolerance (agreement by rule) and noise (measured instability). A third, the reader's **size filter**, hides small changes on the page and changes no count (section 10.5). +**The whole way takes the noise of its steps** (`rule.total_noise`): per indicator, the +largest noise measured in any step. Only measured steps count; an indicator no step measured +has no noise over the whole way, and the page says "not measured", never "identical". A set +of steps takes the same: the largest of its steps (section 3). Decided by Manuel on 17 and +18 November 2026, after sentier-agribalyse found a move within the noise of its step +counted as "differs" over the whole way, which no step had found. The cost: one unstable +step widens "within noise" for the whole way in that indicator. The validator holds +`total_noise` to the steps' noise; a file made before it has none and is judged without +noise over the whole way, as it was written. + One number per indicator is coarse: a few unstable items make every smaller difference of that indicator "within noise". Two builds that are identical are a finding, shown as "identical", and never as "not measured". Large noise is a defect to fix (sentier-agribalyse's @@ -516,11 +512,14 @@ would. It opens from disk; no build step, no server, no network, no font or scri elsewhere. Where the file names a matrix that lies beside it, the page writes it as `matrix.js`, which loads from disk too; a site serving `matrix.json` needs nothing else, as the page fetches it over HTTP. Served over HTTP the page can also read `?file=...`, and it -opens a file a reader chooses (read in the browser, sent nowhere). **The page works out no -class, no direction and no count of its own.** It reads them from the file, which the -validator has checked, and only adds the file's counts up: the classes that moved into -"moved", and a step's counts over its indicators. The one number it works out itself is -the median and percentiles of a distribution (10.3), and only from every item. A file read by `?file=` or chosen by a +opens a file a reader chooses (read in the browser, sent nowhere). **For one step and the whole way, the page works out no class, no direction and no count +of its own.** It reads them from the file, which the validator has checked, and only adds +the file's counts up: the classes that moved into "moved", and a step's counts over its +indicators. Two things it works out itself, and only from every item: the median and +percentiles of a distribution (10.3), and a set of steps (section 3), with the rule ported +from `rule.py` (the shared acceptance cases hold the two equal) after holding every chosen +step to the file's own classes. `tests/fixtures/together.json` holds the counts `together.py` +gives for sets of the local example, and the page is held to them. A file read by `?file=` or chosen by a reader has not passed through the validator: the page checks its shape only, says so above everything it draws, and refuses a file it cannot draw instead of drawing part of it. A matrix is held to the file it says it is of (title, states, indicators, steps, number of @@ -531,37 +530,23 @@ items, the length of every row) before a row of it is drawn; its codes are check The text a page renders comes from the file or from words chosen to be neutral: it avoids stage, triage, ledger, layer, upstream, provider and candidate (a test holds this). -**The page is a matrix page.** From the top: the header (10.1); a row of chips that -chooses the comparison, the whole way first and then each step with its number, the values -that moved in it, a `!` where nothing explains it and a mark for each verdict worth a look -(the arrow keys move between them); under the chips one line for the chosen step: the -states it goes between, what it is, its claim with who made it, what the claim found, its -tolerance and its noise; one row of controls (name, group, class, verdict, the size +**The page is a matrix page.** From the top: the header (10.1); the steps (10.1a), which +choose what is compared: the whole way, one step, or any set of steps; under them one line +for what is chosen: for a step, the states it goes between, what it is, its claim with who +made it, what the claim found, its tolerance and its noise; for a set, how it was composed, +the steps it leaves out, each chosen step's claim and what moved in it alone (the quiet +ones folded into one line), its tolerance and its noise; one row of controls (name, group, class, verdict, the size filter) with the count and the legend in the row under it; then the matrix (10.5), which opens an item in a drawer (10.6); directly under it, always open, the distributions of the -chosen comparison (10.3). The address keeps the chosen step and an open item -(`#step=&item=`), so that a reviewer can send someone to exactly that view. Below +chosen comparison (10.3). The address keeps what is chosen and an open item, so that a +reviewer can send someone to exactly that view: nothing for the whole way, `#step=` for +one step, `#steps=:,` for a set (a run as its first and last step, each id +URL-encoded), and `&item=`. An address naming a step the file does not have, or a set +the page cannot compose (no matrix), says so and shows the whole way. Below them, each closed until a reader opens it: the steps and the whole way (10.2), the worst values (10.4), the explanations and the rule (10.7). A host's page never offers to open a file; it says only why nothing is drawn. -**Several steps together.** Where the file has ranges, a reader chooses several steps: -Shift-click a second step (or Shift and an arrow key) for the steps from one to the other, -⌘- or Ctrl-click to add a step or take one off at an end, or turn on "Several steps" so -that a plain click does that (for a touch screen). The chips of the run are pressed, and a -step taken in only because it lies between two chosen ones is hatched. The matrix, the -distributions, the worst values and the drawer then show the range: the file's own counts -and classes of it, never a sum of its steps. Its line says which states it goes between, -which steps lie between the chosen ones and why they are taken in, and each step's claim -with what it found in that step alone (two or more steps with a claim where nothing moved -fold into one line, each still there to open); it says that a range has no noise and no -verdict. An address names a run, not how it was chosen: opened from one, every step of the -run is chosen. -Every step chosen is the whole way. A run the file does not compare is said, with the runs -it does, and nothing changes; a step inside a run cannot be taken off, and the page says -so. The address keeps a range by its id (`#step=first..last`); an address that names a run -the file does not compare, or no comparison at all, opens on the whole way and says why. - The line of the chosen step names every verdict on a move with its count, "as claimed" first ("40 values moved as claimed, 2 off claim ◐"), and "Nothing moved, as claimed" only where every count is zero. It gives them weight, not colour: a verdict is not an approval @@ -573,6 +558,23 @@ it holds of how many worth a look, and, for a local file, that its writer has no may be published (a quiet part of the line, as a site's own notice, not a box). The states in order, with their identity and join counts, head the steps (10.2). +### 10.1a Choosing steps +Built for hundreds of steps, though a file holds 29 for now (4.4). **A strip**: "The whole +way", then one thin cell per step whose height is how many values moved in it alone (on a +log scale, so one value still shows), red at the top where nothing explains it, a dot where +a verdict is worth a look; numbered up to 40 steps, 2 px wide past 60, and scrolling inside +its frame. A click chooses one step, Shift a run from the step chosen before, ⌘ or Ctrl adds +or takes off one; the arrow keys move a step at a time, with Shift they grow or shrink the +run. Chosen steps are filled and underlined, so that a set reads as bands along the strip. + +**A list**, opened by "Find and choose steps": every step with its number, label, kind and +what moved in it, a box to tick and "only" to choose it alone; consecutive steps of one kind +under one heading whose box takes or leaves the whole group; a search by number, name or +kind; "Only steps where something moved"; "Every step: the whole way" and "The steps where +something moved" as one click each. Shift on a box ticks every step shown from the one ticked +before. One step always stays chosen. Without every item the list says why a set cannot be +chosen yet and offers one step at a time. + ### 10.2 Steps and the whole way Steps are numbered from 0 where the first state is `published`: step 0 is then the reproduction (rule 1 of section 1). A chain that starts from a build of its own has no @@ -584,8 +586,8 @@ every class, up, down, the step that carries most of the difference (section 7), over steps, not attributable, and moved by what nothing explains. ### 10.3 Distributions -One card per indicator, in the order of the matrix's columns (10.5), for the comparison the -chips have chosen: a histogram of the file's own counts, from left to right a sign change, +One card per indicator, in the order of the matrix's columns (10.5), for the comparison +chosen above (one step, a set of steps or the whole way): a histogram of the file's own counts, from left to right a sign change, the bands down from far to near, agrees and within noise (two bars, the band around 1), the bands up from near to far, then zero reference, zero result, near zero and missing. Every count is in its bar's title. @@ -620,7 +622,7 @@ ratio). The page always says how many it shows of how many, and how many items w look the file does not hold. ### 10.5 Matrix -Items by indicator for the comparison the chips have chosen. **The indicators in which that +Items by indicator for the comparison chosen above. **The indicators in which that comparison moved most come first**, so that what a step did is in view without scrolling; an indicator in which it moved nothing and nothing is missing comes last, quietened, and keeps its column (a missing value counts with what moved: it is a finding, not stillness). @@ -700,8 +702,8 @@ the page script (`tests/js/page.test.js`), so the two cannot drift apart unnotic | A25 | A file is local unless its writer says otherwise | sentier-bafu, sentier-bafu-agribalyse | `test_a25` | | A26 | A pair on both sides of the floor that agrees was a zero result, and listed second worst | review of PR 2 | cases A26-* | | A27 | A factor too large for a float: Python and the page ordered the pair differently, the page wrote "×Infinity" | review of PR 2 | case A27 | -| A28 | Choosing several fixes did not change what the matrix and the distributions below it showed | sentier-bafu (Manuel, 17 November 2026) | `tests/test_ranges.py`; node "Shift-click chooses the steps from one to another together", "steps chosen apart take in the steps between them" | -| A29 | A run of steps was judged as the sum of its steps: two moves under the tolerance each, over it together, agreed | ranges | `test_a_range_moves_where_each_of_its_steps_agrees` | +| A28 | A move within the noise of its step was counted as "differs" over the whole way, which judged without noise | sentier-agribalyse | `TotalNoise`, node "the whole way takes the largest noise" | +| A29 | A set of steps composed by the page must have the classes and counts of the Python reference, item by item, and is refused where its steps disagree with the file | review of PR 22 | `Together`, `tests/fixtures/together.json`, node "a set composed by the page", "refuses a set" | Also tested: the validator refuses a class, direction or verdict that contradicts the values, items out of order, counts that do not add up, unknown keys and other formats @@ -809,7 +811,6 @@ sentier-bafu-agribalyse wrote their requirements. What became of each: | Indicators not hardcoded | agribalyse | yes: from the file | | The file's own word for an indicator ("impact category") | bafu | yes: the optional `indicator` | | No step 0 in a chain that does not start from the published results | bafu | yes: its steps are numbered from 1 (section 10.2) | -| Choose any set of fixes at the top; the matrix and everything under it show those | bafu (from Manuel, 17 November 2026) | yes, as a run of steps: a set with a gap takes in the steps between, said on the page (section 3) | | Readable without JavaScript for the counts; 375 px wide | bafu-agribalyse | 375 px: yes, no sideways scroll of the page (tables scroll inside their frame; checked in a browser). Without JavaScript: the summary is Markdown; a no-script page is later | ## 15. Open questions @@ -834,3 +835,13 @@ For Manuel, unless he names someone else: did, and the migration of the ADEME dashboard goes with him. sentier-agribalyse relays that Manuel wants his dashboard built on, not replaced; this plan retires its page and keeps his scorer. Which of the two Manuel means is for him and Laurenz to settle. +7. **Hundreds of steps.** A file holds 29 steps (4.4), and Manuel expects hundreds of + patches, chosen in many combinations. The page composes any set already; the file and + the matrix grow by one comparison per step. Raising `MAX_STATES` needs the size measured + first: per step, the file adds a block per indicator and one class, direction and band per + listed item and indicator, and the matrix one result (mostly `"="`) and one code per item + and indicator. A run-length form (`"=n"`) would keep a matrix of mostly unchanged + results small. +8. **What steps do to each other.** A set of steps apart is an approximation where they + touch the same results (section 3). Only building them alone measures it; that is a + build tool's work (sentier-bafu), whose results this tool can then compare as a chain. diff --git a/examples/diagnostics.json b/examples/diagnostics.json index b3c9fe8..a94529e 100644 --- a/examples/diagnostics.json +++ b/examples/diagnostics.json @@ -33,6 +33,11 @@ "floors_from": "published", "beyond": 10.0, "total_tolerance": 0.0005, + "total_noise": { + "x:climate": 0.0, + "x:water": 0.02439024390243894, + "x:tox": 0.0 + }, "floors": [ { "indicator": "x:climate", @@ -323,60 +328,6 @@ } } ], - "ranges": [ - { - "id": "step-0..fix-1", - "steps": [ - "step-0", - "fix-1" - ], - "from": "published", - "to": "fix-1", - "tolerance": 0.0005 - }, - { - "id": "step-0..rebuilt", - "steps": [ - "step-0", - "fix-1", - "rebuilt" - ], - "from": "published", - "to": "rebuilt", - "tolerance": 0.0005 - }, - { - "id": "fix-1..rebuilt", - "steps": [ - "fix-1", - "rebuilt" - ], - "from": "repro", - "to": "rebuilt", - "tolerance": 1e-05 - }, - { - "id": "fix-1..mapping-2", - "steps": [ - "fix-1", - "rebuilt", - "mapping-2" - ], - "from": "repro", - "to": "mapping-2", - "tolerance": 1e-05 - }, - { - "id": "rebuilt..mapping-2", - "steps": [ - "rebuilt", - "mapping-2" - ], - "from": "fix-1", - "to": "mapping-2", - "tolerance": 1e-05 - } - ], "counts": { "steps": { "step-0": { @@ -1031,588 +982,6 @@ "closer": null, "further": null } - }, - "ranges": { - "step-0..fix-1": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 2 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 9, - "within noise": 0, - "differs": 0, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 1, - "after": 0, - "both": 0 - }, - "directions": { - "up": 0, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 2, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "step-0..rebuilt": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 2 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 2 - }, - "missing": { - "before": 1, - "after": 1, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 2, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "fix-1..rebuilt": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 2 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 8, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 0, - "after": 1, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 8, - "within noise": 0, - "differs": 0, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 2, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 0, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "fix-1..mapping-2": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 4, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 1, - "sign change": 1, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 0, - "after": 1, - "both": 0 - }, - "directions": { - "up": 2, - "down": 3 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 2, - "beyond 10x": 1, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 3, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 1 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 1, - "zero result": 0, - "sign change": 0, - "near zero": 1, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 1 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "rebuilt..mapping-2": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 0, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 1, - "sign change": 1, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 0, - "after": 1, - "both": 0 - }, - "directions": { - "up": 1, - "down": 1 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 2, - "beyond 10x": 1, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 3, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 1 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 1, - "zero result": 0, - "sign change": 0, - "near zero": 1, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 1 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - } } }, "attribution": { @@ -1651,16 +1020,16 @@ } }, "items": [ - {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change", "agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs", "agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down", "down", null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2", null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference", "near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "up", "up", null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result", "agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down", null, null, null, "down", "down"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x", "agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs", "differs", "differs", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up", "up", "up", null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10", null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1", null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down", "down", "down", "down", "down", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, - {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "missing", "missing", "differs", "agrees", "missing", "missing", "differs", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up", "up", "up", "up", "up", null], "x:water": [null, null, null, null, "up", null, null, null, "up", "up"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", null], "x:water": [null, null, null, null, "up, factor 1.1-1.25", null, null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p01", "name": "Wheat", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.52, 0.520013, 0.468012, 0.468012, 0.468012], "x:water": [1.2, 1.2, 1.2, 1.2000001, 1.2000001], "x:tox": [2e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "down", null, null, "down", "down", "down", "down", "down", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.1-1.25", null, null, "down, factor 1.1-1.25", "down, factor 1.1-1.25", "down, factor 1.1-1.25", "down, factor 1.1-1.25", "down, factor 1.1-1.25", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "as claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": {"fix-1": "p01-fix-1.json"}}, - {"id": "p04", "name": "Oats", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.45, 0.45, 0.45, 0.45, 0.45], "x:water": [1.0, 1.0, 1.0, 1.025, 1.0455], "x:tox": [1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "differs", "within noise", "differs", "agrees", "differs", "differs", "differs", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, "up", null, "up", null, "up", "up", "up", "up"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, "up, factor 1-1.1", null, "up, factor 1-1.1", null, "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "within noise"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p06", "name": "Rye", "place": "PL", "group": "crops", "unit": "kg", "values": {"x:climate": [0.43, 0.43, 0.43, 0.43, null], "x:water": [null, 1.15, 1.15, 1.15, 1.15], "x:tox": [2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "missing", "missing", "agrees", "agrees", "agrees", "missing", "missing"], "x:water": ["missing", "agrees", "agrees", "agrees", "missing", "missing", "missing", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not judged"], "x:water": ["not judged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p02", "name": "Maize", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.41, 0.41, 0.41, 0.41, 0.41], "x:water": [2.5, 2.500025, 2.500025, 2.500025, 2.500025], "x:tox": [1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "claimed, not moved"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} + {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, + {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "missing", "missing", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up"], "x:water": [null, null, null, null, "up"], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25"], "x:water": [null, null, null, null, "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p01", "name": "Wheat", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.52, 0.520013, 0.468012, 0.468012, 0.468012], "x:water": [1.2, 1.2, 1.2, 1.2000001, 1.2000001], "x:tox": [2e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07, 2.0000002e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "down", null, null, "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.1-1.25", null, null, "down, factor 1.1-1.25"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "as claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": {"fix-1": "p01-fix-1.json"}}, + {"id": "p04", "name": "Oats", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.45, 0.45, 0.45, 0.45, 0.45], "x:water": [1.0, 1.0, 1.0, 1.025, 1.0455], "x:tox": [1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07, 1.7e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "differs", "within noise", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, "up", null, "up"], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, "up, factor 1-1.1", null, "up, factor 1-1.1"], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "within noise"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p06", "name": "Rye", "place": "PL", "group": "crops", "unit": "kg", "values": {"x:climate": [0.43, 0.43, 0.43, 0.43, null], "x:water": [null, 1.15, 1.15, 1.15, 1.15], "x:tox": [2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07, 2.1e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "missing", "missing"], "x:water": ["missing", "agrees", "agrees", "agrees", "missing"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not judged"], "x:water": ["not judged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p02", "name": "Maize", "place": "FR", "group": "crops", "unit": "kg", "values": {"x:climate": [0.41, 0.41, 0.41, 0.41, 0.41], "x:water": [2.5, 2.500025, 2.500025, 2.500025, 2.500025], "x:tox": [1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07, 1.8e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "claimed, not moved"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} ], "items_count": { "all": 10, diff --git a/examples/local/diagnostics.json b/examples/local/diagnostics.json index d07858f..148669d 100644 --- a/examples/local/diagnostics.json +++ b/examples/local/diagnostics.json @@ -33,6 +33,11 @@ "floors_from": "published", "beyond": 10.0, "total_tolerance": 0.0005, + "total_noise": { + "x:climate": 0.0, + "x:water": 0.02439024390243894, + "x:tox": 0.0 + }, "floors": [ { "indicator": "x:climate", @@ -323,60 +328,6 @@ } } ], - "ranges": [ - { - "id": "step-0..fix-1", - "steps": [ - "step-0", - "fix-1" - ], - "from": "published", - "to": "fix-1", - "tolerance": 0.0005 - }, - { - "id": "step-0..rebuilt", - "steps": [ - "step-0", - "fix-1", - "rebuilt" - ], - "from": "published", - "to": "rebuilt", - "tolerance": 0.0005 - }, - { - "id": "fix-1..rebuilt", - "steps": [ - "fix-1", - "rebuilt" - ], - "from": "repro", - "to": "rebuilt", - "tolerance": 1e-05 - }, - { - "id": "fix-1..mapping-2", - "steps": [ - "fix-1", - "rebuilt", - "mapping-2" - ], - "from": "repro", - "to": "mapping-2", - "tolerance": 1e-05 - }, - { - "id": "rebuilt..mapping-2", - "steps": [ - "rebuilt", - "mapping-2" - ], - "from": "fix-1", - "to": "mapping-2", - "tolerance": 1e-05 - } - ], "counts": { "steps": { "step-0": { @@ -1031,588 +982,6 @@ "closer": null, "further": null } - }, - "ranges": { - "step-0..fix-1": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 2 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 9, - "within noise": 0, - "differs": 0, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 1, - "after": 0, - "both": 0 - }, - "directions": { - "up": 0, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 2, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "step-0..rebuilt": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 2 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 2 - }, - "missing": { - "before": 1, - "after": 1, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 2, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "fix-1..rebuilt": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 2 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 8, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 0, - "after": 1, - "both": 0 - }, - "directions": { - "up": 1, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 8, - "within noise": 0, - "differs": 0, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 2, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 0, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "fix-1..mapping-2": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 4, - "within noise": 0, - "differs": 3, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 1, - "sign change": 1, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 0, - "after": 1, - "both": 0 - }, - "directions": { - "up": 2, - "down": 3 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 1, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 2, - "beyond 10x": 1, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 3, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 1 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 1, - "zero result": 0, - "sign change": 0, - "near zero": 1, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 1 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - }, - "rebuilt..mapping-2": { - "x:climate": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 0, - "beyond 10x": 0, - "zero reference": 0, - "zero result": 1, - "sign change": 1, - "near zero": 0, - "missing": 1 - }, - "missing": { - "before": 0, - "after": 1, - "both": 0 - }, - "directions": { - "up": 1, - "down": 1 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:water": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 2, - "beyond 10x": 1, - "zero reference": 0, - "zero result": 0, - "sign change": 0, - "near zero": 0, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 3, - "down": 0 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 0, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 1, - "up, factor 1.1-1.25": 1, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 1 - }, - "verdicts": null, - "closer": null, - "further": null - }, - "x:tox": { - "pairs": 10, - "classes": { - "agrees": 7, - "within noise": 0, - "differs": 1, - "beyond 10x": 0, - "zero reference": 1, - "zero result": 0, - "sign change": 0, - "near zero": 1, - "missing": 0 - }, - "missing": { - "before": 0, - "after": 0, - "both": 0 - }, - "directions": { - "up": 1, - "down": 1 - }, - "bands": { - "down, factor over 10": 0, - "down, factor 2-10": 0, - "down, factor 1.25-2": 1, - "down, factor 1.1-1.25": 0, - "down, factor 1-1.1": 0, - "up, factor 1-1.1": 0, - "up, factor 1.1-1.25": 0, - "up, factor 1.25-2": 0, - "up, factor 2-10": 0, - "up, factor over 10": 0 - }, - "verdicts": null, - "closer": null, - "further": null - } - } } }, "attribution": { @@ -1651,12 +1020,12 @@ } }, "items": [ - {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change", "agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs", "agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down", "down", null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2", null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference", "near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, "up", "up", null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, - {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result", "agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down", null, null, null, "down", "down"], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x", "agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs", "differs", "differs", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up", "up", null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up", "up", "up", null, null, null]}, "bands": {"x:climate": [null, null, null, null, null, null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10", null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1", "up, factor 1-1.1", "up, factor 1-1.1", null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, - {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down", "down", "down", "down", "down", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", "down, factor 1.25-2", null], "x:water": [null, null, null, null, null, null, null, null, null, null], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, - {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs", "differs", "differs", "differs", "differs", "agrees"], "x:water": ["agrees", "agrees", "missing", "missing", "differs", "agrees", "missing", "missing", "differs", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up", "up", "up", "up", "up", null], "x:water": [null, null, null, null, "up", null, null, null, "up", "up"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", "up, factor 1.1-1.25", null], "x:water": [null, null, null, null, "up, factor 1.1-1.25", null, null, null, "up, factor 1.1-1.25", "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null, null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} + {"id": "p08", "name": "Compost, used as fertiliser", "place": "CH", "group": "waste", "unit": "kg", "values": {"x:climate": [-0.5, -0.5, -0.5, -0.5, 0.2], "x:water": [0.05, 0.05, 0.05, 0.05, 0.05], "x:tox": [-2e-06, -2e-06, -2e-06, -2e-06, -4e-06]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "sign change", "sign change"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "differs", "differs"]}, "directions": {"x:climate": [null, null, null, "up", "up"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down", "down"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "down, factor 1.25-2", "down, factor 1.25-2"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p09", "name": "Machine hour, harvesting", "place": "CH", "group": "services", "unit": "h", "values": {"x:climate": [42.0, 42.00042, 42.00042, 42.00042, 42.00042], "x:water": [0.9, 0.9, 0.9, 0.9, 0.9], "x:tox": [0.0, 0.0, 0.0, 0.0, 4e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "zero reference", "zero reference"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, "up", "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not claimed"]}, "breakdowns": null}, + {"id": "p07", "name": "Heat from wood chips", "place": "CH", "group": "energy", "unit": "MJ", "values": {"x:climate": [0.03, 0.03, 0.03, 0.03, 0.0], "x:water": [0.0004, 0.0004, 0.0004, 0.0004, 0.0004], "x:tox": [3e-09, 3e-09, 3e-09, 3e-09, 3e-09]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "zero result", "zero result"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, null, null, "down", "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "not claimed"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p10", "name": "Tomato, greenhouse", "place": "NL", "group": "crops", "unit": "kg", "values": {"x:climate": [1.3, 1.3, 1.3, 1.3, 1.3], "x:water": [0.02, 0.02, 0.02, 0.02, 0.5], "x:tox": [2.1e-07, 2.3e-07, 2.3e-07, 2.3e-07, 2.3e-07]}, "classes": {"x:climate": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:water": ["agrees", "agrees", "agrees", "beyond 10x", "beyond 10x"], "x:tox": ["differs", "agrees", "agrees", "agrees", "differs"]}, "directions": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up", "up"], "x:tox": ["up", null, null, null, "up"]}, "bands": {"x:climate": [null, null, null, null, null], "x:water": [null, null, null, "up, factor over 10", "up, factor over 10"], "x:tox": ["up, factor 1-1.1", null, null, null, "up, factor 1-1.1"]}, "verdicts": {"x:climate": ["unchanged", "unchanged", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "as claimed"], "x:tox": ["not claimed", "unchanged", null, "unchanged"]}, "breakdowns": null}, + {"id": "p05", "name": "Rice", "place": "IT", "group": "crops", "unit": "kg", "values": {"x:climate": [1.9, 1.9, 0.95, 0.95, 0.95], "x:water": [3.4, 3.4, 3.4, 3.4, 3.4], "x:tox": [1e-12, 1e-12, 1e-12, 1e-12, 3e-12]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "agrees", "agrees", "agrees"], "x:tox": ["near zero", "near zero", "near zero", "near zero", "near zero"]}, "directions": {"x:climate": [null, "down", null, null, "down"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "down, factor 1.25-2", null, null, "down, factor 1.25-2"], "x:water": [null, null, null, null, null], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "off claim", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "unchanged"], "x:tox": ["not judged", "not judged", null, "not judged"]}, "breakdowns": null}, + {"id": "p03", "name": "Barley", "place": "DE", "group": "crops", "unit": "kg", "values": {"x:climate": [0.48, 0.47999, 0.575988, 0.575988, 0.575988], "x:water": [1.1, 1.1, 1.1, null, 1.3], "x:tox": [1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07, 1.9e-07]}, "classes": {"x:climate": ["agrees", "differs", "agrees", "agrees", "differs"], "x:water": ["agrees", "agrees", "missing", "missing", "differs"], "x:tox": ["agrees", "agrees", "agrees", "agrees", "agrees"]}, "directions": {"x:climate": [null, "up", null, null, "up"], "x:water": [null, null, null, null, "up"], "x:tox": [null, null, null, null, null]}, "bands": {"x:climate": [null, "up, factor 1.1-1.25", null, null, "up, factor 1.1-1.25"], "x:water": [null, null, null, null, "up, factor 1.1-1.25"], "x:tox": [null, null, null, null, null]}, "verdicts": {"x:climate": ["unchanged", "not claimed", null, "unchanged"], "x:water": ["unchanged", "unchanged", null, "not judged"], "x:tox": ["unchanged", "unchanged", null, "unchanged"]}, "breakdowns": null} ], "items_count": { "all": 10, diff --git a/examples/local/matrix.json b/examples/local/matrix.json index 17e4ef5..40fc6ba 100644 --- a/examples/local/matrix.json +++ b/examples/local/matrix.json @@ -1,4 +1,4 @@ -{"format": "sentier-diagnostics-matrix/1", "of": {"title": "A made-up chain: published results to the current build", "states": ["published", "repro", "fix-1", "rebuilt", "mapping-2"], "indicators": ["x:climate", "x:water", "x:tox"], "steps": ["step-0", "fix-1", "rebuilt", "mapping-2"], "ranges": ["step-0..fix-1", "step-0..rebuilt", "fix-1..rebuilt", "fix-1..mapping-2", "rebuilt..mapping-2"]}, +{"format": "sentier-diagnostics-matrix/1", "of": {"title": "A made-up chain: published results to the current build", "states": ["published", "repro", "fix-1", "rebuilt", "mapping-2"], "indicators": ["x:climate", "x:water", "x:tox"], "steps": ["step-0", "fix-1", "rebuilt", "mapping-2"]}, "items": [ ["p08","Compost, used as fertiliser","CH","waste","kg"], ["p09","Machine hour, harvesting","CH","services","h"], @@ -24,16 +24,16 @@ [0.41,"=","=","=","=",2.5,2.500025,"=","=","=",1.8e-07,"=","=","=","="] ], "classes": [ - "===SS===SS=============dd===dd", - "====================000RR000RR", - "===tt===tt====================", - "=============BB===BBD===DDD===", - "=d==ddddd===========0000000000", - "=D==DDDDD===--D=--DD==========", - "=d==ddddd=====================", - "============D~D=DDDD==========", - "===--===---===---=============", - "==============================" + "===SS========dd", + "==========000RR", + "===tt==========", + "========BBD===D", + "=d==d=====00000", + "=D==D==--D=====", + "=d==d==========", + "=======D~D=====", + "===---===-=====", + "===============" ], "verdicts": [ "==.n==.===.n", diff --git a/src/sentier_diagnostics/chain.py b/src/sentier_diagnostics/chain.py index 17aa755..9b82065 100644 --- a/src/sentier_diagnostics/chain.py +++ b/src/sentier_diagnostics/chain.py @@ -17,19 +17,12 @@ steps on either side of that state cannot be measured, and its total is counted as not attributable instead of being split. -**Ranges.** A run of consecutive steps, such as three fixes built one after another, is -compared too where the producer asks for it (`ranges`): the state before its first step -against the state after its last, judged as the whole way is (the largest tolerance of its -steps, no noise, no verdict). A page then shows any run of steps as one comparison of two -built states: what those steps did together, never a sum of steps it cannot see. - `build` writes the whole file and checks it (`fileformat.errors`); `write` stores it. """ from __future__ import annotations import json -import warnings from collections.abc import Iterable, Mapping from pathlib import Path @@ -149,74 +142,6 @@ def explanation(text: str, by: dict, *, step: str | None = None, indicator: str } -#: Without a choice, a chain of at most this many steps has every range, and a longer one none: -#: the ranges of n steps are n(n-1)/2 - 1, each a comparison of every item in every indicator. -AUTO_RANGES = 8 - - -def ranges_within(steps: list[dict], first: str, last: str) -> list[tuple[str, str]]: - """Every run of at least two consecutive steps from `first` to `last`, as `(first, last)` - pairs: what `ranges` takes for the steps of one kind, such as the fixes of a build. - - >>> ranges_within([{"id": i} for i in "abcd"], "b", "d") - [('b', 'c'), ('b', 'd'), ('c', 'd')] - """ - ids = [s["id"] for s in steps] - for one in (first, last): - if one not in ids: - raise ValueError(f"ranges within {first!r} and {last!r}: no step {one!r}") - i, j = ids.index(first), ids.index(last) - if j <= i: - raise ValueError(f"ranges within {first!r} and {last!r}: the first step comes after the last") - return [(ids[a], ids[b]) for a in range(i, j + 1) for b in range(a + 1, j + 1)] - - -def _ranges(said, out_steps: list[dict]) -> list[dict]: - """The ranges of a chain, as the file holds them, from what the producer asked for: - "auto", "all", None, or `(first step id, last step id)` pairs.""" - ids = [s["id"] for s in out_steps] - n = len(ids) - if said == "auto": - said = "all" if n <= AUTO_RANGES else None - if said is None: - # a chain that grows past the limit loses its ranges: never without a word - warnings.warn( - f"a chain of {n} steps has no ranges unless asked (more than {AUTO_RANGES} steps): " - "pass ranges=\"all\", chain.ranges_within(steps, first, last) or (first, last) pairs, " - "or ranges=None to say that none is wanted", - stacklevel=4, - ) - if said is None: - return [] - if said == "all": - pairs = [(a, b) for a in range(n) for b in range(a + 1, n) if (a, b) != (0, n - 1)] - elif isinstance(said, str): - raise ValueError(f"`ranges` is \"auto\", \"all\", None or a list of (first, last) step ids, not {said!r}") - else: - pairs = [] - for one in said: - if not (isinstance(one, (list, tuple)) and len(one) == 2 and all(x in ids for x in one)): - raise ValueError(f"a range is (first step id, last step id) of this chain, not {one!r}") - a, b = ids.index(one[0]), ids.index(one[1]) - if b <= a: - raise ValueError(f"range {one[0]}..{one[1]}: a range runs over at least two steps, the first first") - if (a, b) == (0, n - 1): - raise ValueError(f"range {one[0]}..{one[1]}: every step is the whole way, counted as the total") - if (a, b) in pairs: - raise ValueError(f"range {one[0]}..{one[1]} is asked for twice") - pairs.append((a, b)) - return [ - { - "id": f"{ids[a]}..{ids[b]}", - "steps": ids[a : b + 1], - "from": out_steps[a]["from"], - "to": out_steps[b]["to"], - "tolerance": max(s["tolerance"]["value"] for s in out_steps[a : b + 1]), - } - for a, b in pairs - ] - - def _indicator(entry) -> dict: if isinstance(entry, Mapping): found = {k: entry.get(k) for k in ("id", "name", "short", "unit")} @@ -287,7 +212,6 @@ def _build( notes: Iterable[str] = (), breakdowns: Mapping[str, Mapping[str, str]] | None = None, matrix_file: str | None = None, - ranges="auto", ) -> tuple[dict, dict | None]: """A whole chain, counted, judged, attributed and checked, and its matrix where `matrix_file` names one. @@ -309,10 +233,6 @@ def _build( says it may be published). The tool checks only that it is one of the two. - `breakdowns`: `{item id: {step id or "total": file name}}`. - `matrix_file`: the name of the full matrix, for a local file of items; None for none. - - `ranges`: the runs of consecutive steps compared as one: "all" (every run of at least - two steps but the whole way), a list of `(first step id, last step id)` pairs - (`ranges_within` gives every run between two steps), None for none, or "auto" (the - default): every run where the chain has at most `AUTO_RANGES` steps, else none. """ if matrix_file is not None and (tier != "items" or audience != "local"): raise ValueError("only a local file of items has a matrix: a public file keeps the listed items only") @@ -370,53 +290,47 @@ def _build( "noise": one.get("noise") or noise(), }) # fmt: skip total_tolerance = max(s["tolerance"]["value"] for s in out_steps) + total_noise = fileformat.noise_together(out_steps) published_first = states[0].get("kind") == "published" - out_ranges = _ranges(ranges, out_steps) - nsteps = len(out_steps) - - # every comparison, in the order an item lists them: each step, the whole way, each range; - # as (first state, last state, tolerance, noise by indicator or None, claim or None) - compared = [] - for k, one in enumerate(out_steps): - said = one["noise"] - by = (said["by"] or {}) if said["measured"] else None - compared.append((order[k], order[k + 1], one["tolerance"]["value"], by, steps[k].get("claim"))) - compared.append((order[0], order[-1], total_tolerance, None, None)) - compared += [(r["from"], r["to"], r["tolerance"], None, None) for r in out_ranges] - seen = {} # a judgment is one of a few dozen: every pair refers to one of them - - def judged(c, indicator, item): - """Class, direction, band and verdict of one item in one comparison.""" - first, last, tol, by, said_claim = compared[c] + + def judged(k, indicator, item): + """Class, direction, band and verdict of one item in one step (k) or the total (None).""" + first, last = (order[0], order[-1]) if k is None else (order[k], order[k + 1]) before, after = table[first][indicator].get(item), table[last][indicator].get(item) - level = by.get(indicator) if by is not None else None + if k is None: + level, tol = total_noise.get(indicator), total_tolerance + else: + said = out_steps[k]["noise"] + level = (said["by"] or {}).get(indicator) if said["measured"] else None + tol = out_steps[k]["tolerance"]["value"] floor = floor_table[(indicator, units[item])] kind, way, where = rule.judge(before, after, floor=floor, tolerance=tol, noise=level) said_verdict = None - if said_claim: - covering = [e for e in claims.entries_for(said_claim, indicator) if claims.covers(e, item, indicator)] + if k is not None and steps[k].get("claim"): + entries = claims.entries_for(steps[k]["claim"], indicator) + covering = [e for e in entries if claims.covers(e, item, indicator)] said_verdict = claims.verdict(kind, before, after, way, covering) - key = (kind, way, where, said_verdict) - return seen.setdefault(key, key) - - # every pair, once: `found[(comparison, indicator)][n]` is the judgment of `items[n]` - found = {(c, i): [judged(c, i, item) for item in items] for c in range(len(compared)) for i in ids} - - def ends(c, indicator, item): - return table[compared[c][0]][indicator].get(item), table[compared[c][1]][indicator].get(item) + return before, after, kind, way, where, said_verdict + + # every pair, once + found = { + (k, indicator, item): judged(k, indicator, item) + for k in [*range(len(out_steps)), None] + for indicator in ids + for item in items + } - def block(c, indicator): + def block(k, indicator): classes = dict.fromkeys(rule.CLASSES, 0) missing = dict.fromkeys(fileformat.MISSING_SIDES, 0) bands = dict.fromkeys(rule.BANDS, 0) ways = dict.fromkeys(rule.DIRECTIONS, 0) - verdicts = dict.fromkeys(claims.VERDICTS, 0) if compared[c][4] else None + verdicts = dict.fromkeys(claims.VERDICTS, 0) if k is not None and steps[k].get("claim") else None closer = further = None - if published_first and 0 < c < nsteps: + if published_first and k not in (None, 0): closer = further = 0 - for n, item in enumerate(items): - kind, way, where, said = found[(c, indicator)][n] - before, after = ends(c, indicator, item) + for item in items: + before, after, kind, way, where, said = found[(k, indicator, item)] classes[kind] += 1 if kind == rule.MISSING: missing["both" if before is None and after is None else "before" if before is None else "after"] += 1 @@ -437,20 +351,19 @@ def block(c, indicator): counts = { "steps": {s["id"]: {i: block(k, i) for i in ids} for k, s in enumerate(out_steps)}, - "total": {i: block(nsteps, i) for i in ids}, + "total": {i: block(None, i) for i in ids}, } - counts["ranges"] = {r["id"]: {i: block(nsteps + 1 + j, i) for i in ids} for j, r in enumerate(out_ranges)} # attribution: which step carries the largest share of each item's whole difference attribution = {} for indicator in ids: dominant = {s["id"]: 0 for s in out_steps} not_attributable = spread = unexplained_moved = 0 - for n, item in enumerate(items): - kinds = [found[(k, indicator)][n][0] for k in range(nsteps)] + for item in items: + kinds = [found[(k, indicator, item)][2] for k in range(len(out_steps))] if any(not s["explained"] and kinds[k] in rule.MOVES for k, s in enumerate(out_steps)): unexplained_moved += 1 - if found[(nsteps, indicator)][n][0] not in rule.MOVES: + if found[(None, indicator, item)][2] not in rule.MOVES: continue series = [table[s][indicator].get(item) for s in order] if any(v is None for v in series): @@ -464,27 +377,22 @@ def block(c, indicator): attribution[indicator] = {"dominant": dominant, "not_attributable": not_attributable, "spread": spread, "unexplained_moved": unexplained_moved} # fmt: skip - # the items worth a look, the worst first; a range counts as a step does - at = {item: n for n, item in enumerate(items)} - + # the items worth a look, the worst first def worth(item): - n = at[item] - return any( - found[(c, i)][n][0] not in rule.QUIET or found[(c, i)][n][3] == claims.NOT_MOVED - for i in ids - for c in range(len(compared)) - ) - - ranks = {} + for indicator in ids: + for k in [*range(len(out_steps)), None]: + _, _, kind, _, _, said = found[(k, indicator, item)] + if kind not in rule.QUIET or said == claims.NOT_MOVED: + return True + return False def worst(item): - if item not in ranks: - n = at[item] - ranks[item] = ( - min(rule.severity(*ends(c, i, item), found[(c, i)][n][0]) for i in ids for c in range(len(compared))), - item, - ) - return ranks[item] + keys = [] + for indicator in ids: + for k in [*range(len(out_steps)), None]: + before, after, kind, *_ = found[(k, indicator, item)] + keys.append(rule.severity(before, after, kind)) + return (min(keys), item) qualifying = sorted((item for item in items if worth(item)), key=worst) shown = qualifying[: max(0, listed)] if tier == "items" else [] @@ -492,7 +400,6 @@ def worst(item): any_claim = any(s.get("claim") for s in steps) def record_of(item): - n = at[item] about_item = names.get(item) or {} record = { "id": item, @@ -508,12 +415,12 @@ def record_of(item): "breakdowns": dict(breakdowns[item]) if item in breakdowns else None, } for indicator in ids: - row = [found[(c, indicator)][n] for c in range(len(compared))] - record["classes"][indicator] = [r[0] for r in row] - record["directions"][indicator] = [r[1] for r in row] - record["bands"][indicator] = [r[2] for r in row] + row = [found[(k, indicator, item)] for k in [*range(len(out_steps)), None]] + record["classes"][indicator] = [r[2] for r in row] + record["directions"][indicator] = [r[3] for r in row] + record["bands"][indicator] = [r[4] for r in row] if any_claim: - record["verdicts"][indicator] = [r[3] for r in row[:nsteps]] + record["verdicts"][indicator] = [r[5] for r in row[:-1]] return record out_items = [record_of(item) for item in shown] @@ -532,6 +439,7 @@ def record_of(item): "floors_from": order[0], "beyond": rule.BEYOND_FACTOR, "total_tolerance": total_tolerance, + "total_noise": total_noise, "floors": floor_rows, }, "states": [ @@ -541,8 +449,6 @@ def record_of(item): for s in states ], # fmt: skip "steps": out_steps, - # [] where none was asked for: only a file made before ranges leaves the key out - "ranges": out_ranges, "counts": counts, "attribution": attribution, "items": out_items, diff --git a/src/sentier_diagnostics/fileformat.py b/src/sentier_diagnostics/fileformat.py index 79632d4..6f81a9e 100644 --- a/src/sentier_diagnostics/fileformat.py +++ b/src/sentier_diagnostics/fileformat.py @@ -40,7 +40,7 @@ ORIGIN_KINDS = ("person", "code", "model") TOTAL = "total" #: Keys a file may leave out; each is null where it says nothing. -OPTIONAL_KEYS = {"matrix", "indicator", "ranges"} +OPTIONAL_KEYS = {"matrix", "indicator"} #: The largest file a page reads: it holds the whole file. MAX_BYTES = 12 * 1024 * 1024 @@ -48,8 +48,6 @@ #: An entry of a claim may list as many items as a file may. MAX_SCOPE_ITEMS = MAX_ITEMS MAX_EXPLANATIONS, MAX_NOTES, MAX_IDENTITY = 500, 20, 12 -#: Every run of at least two of the 29 steps a file may have, but the whole way. -MAX_RANGES = 29 * 28 // 2 - 1 MAX_ID, MAX_LABEL, MAX_WORD, MAX_TEXT, MAX_LONG = 100, 80, 40, 600, 2000 FILE_NAME = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,99}\.json") @@ -59,11 +57,12 @@ } # fmt: skip INDICATOR_KEYS = {"id", "name", "short", "unit"} RULE_KEYS = {"floor_factor", "floors_from", "beyond", "total_tolerance", "floors"} +#: Left out only by a file made before the whole way took the noise of its steps. +RULE_OPTIONAL = {"total_noise"} FLOOR_KEYS = {"indicator", "unit", "value", "basis", "n"} STATE_KEYS = {"id", "label", "about", "kind", "identity", "join"} STEP_KEYS = {"id", "from", "to", "label", "about", "kind", "explained", "link", "claim", "tolerance", "noise"} # fmt: skip -RANGE_KEYS = {"id", "steps", "from", "to", "tolerance"} CLAIM_KEYS = {"text", "by", "reach", "scope"} SCOPE_KEYS = {"indicators", "items", "direction", "largest", "expect"} ORIGIN_KEYS = {"kind", "name", "model", "run_by"} @@ -381,57 +380,35 @@ def _steps(data, found, states, indicators, tier) -> list[dict]: return steps -def _ranges(data, found, steps) -> list[dict] | None: - """The ranges of a file: runs of consecutive steps, each compared as the whole way is - (SPEC section 5.5). None where they cannot be read; nothing where the file has none: - `[]` where none was asked for, the key left out in a file made before ranges.""" - if "ranges" not in data: - return [] - said = data["ranges"] - if not isinstance(said, list) or len(said) > MAX_RANGES: - found.append(f"`ranges` is a list of at most {MAX_RANGES} ranges ([] where none was asked for), " - "or left out in a file made before ranges") - return None - ids = [s["id"] for s in steps] - seen = set() - for one in said: - if not ( - isinstance(one, dict) - and set(one) == RANGE_KEYS - and is_text(one["id"], 2 * MAX_ID + 2) - and isinstance(one["steps"], list) - and one["steps"] - and all(isinstance(x, str) for x in one["steps"]) - and is_share(one["tolerance"]) - ): - found.append(f"a range is not {{{', '.join(sorted(RANGE_KEYS))}}}") - return None - where, run = f"range {one['id']!r}", one["steps"] - first = ids.index(run[0]) if run[0] in ids else None - if first is None or run != ids[first : first + len(run)]: - found.append(f"{where}: its steps are not consecutive steps of this chain") - return None - last = first + len(run) - 1 - if len(run) < 2: - found.append(f"{where}: a range runs over at least two steps; one step is that step") - if len(run) == len(ids): - found.append(f"{where}: every step is the whole way, counted as the total") - if one["id"] != f"{run[0]}..{run[-1]}": - found.append(f"{where}: the id of a range is its first and last step, {run[0]}..{run[-1]}") - if one["id"] in seen or one["id"] in ids or one["id"] == TOTAL: - found.append(f"{where}: its id is the id of another range, of a step, or of the total") - seen.add(one["id"]) - if (one["from"], one["to"]) != (steps[first]["from"], steps[last]["to"]): - found.append(f"{where}: it does not lead from the state before its first step to the state after its last") - if one["tolerance"] != max(s["tolerance"]["value"] for s in steps[first : last + 1]): - found.append(f"{where}: its tolerance is not the largest tolerance of its steps") - return said +def noise_together(steps) -> dict[str, float]: + """The noise of several steps taken together, per indicator: the largest noise measured in + any of them (SPEC section 5.3). An indicator that none of them measured is left out: its + noise was not measured, which is not the same as two identical builds. + + >>> noise_together([{"noise": {"measured": True, "by": {"a": 1e-9}}}, + ... {"noise": {"measured": False, "by": None}}, + ... {"noise": {"measured": True, "by": {"a": 3e-9, "b": 2e-9}}}]) + {'a': 3e-09, 'b': 2e-09} + """ + found: dict[str, float] = {} + for one in steps: + said = one["noise"] + if said["measured"]: + for indicator, value in (said["by"] or {}).items(): + found[indicator] = max(found.get(indicator, 0.0), value) + return found + + +def total_noise_level(data: Mapping, indicator: str) -> float | None: + """The noise the whole way is judged with in one indicator; None where it was not measured, + or the file was made before the whole way took the noise of its steps.""" + return (data["rule"].get("total_noise") or {}).get(indicator) def _rule(data, found, indicators, states, steps) -> dict | None: said = data.get("rule") - if not isinstance(said, dict) or set(said) != RULE_KEYS: - found.append(f"`rule` is not {{{', '.join(sorted(RULE_KEYS))}}}") + if not isinstance(said, dict) or not RULE_KEYS <= set(said) <= RULE_KEYS | RULE_OPTIONAL: + found.append(f"`rule` is not {{{', '.join(sorted(RULE_KEYS))}}}, with `total_noise`") return None if not is_share(said["floor_factor"]): found.append("`rule`: the floor factor is not a share") @@ -444,6 +421,14 @@ def _rule(data, found, indicators, states, steps) -> dict | None: return None if steps and said["total_tolerance"] != max(s["tolerance"]["value"] for s in steps): found.append("`rule.total_tolerance` is not the largest tolerance of the steps") + if "total_noise" in said: + given = said["total_noise"] + if not (isinstance(given, dict) and set(given) <= set(indicators) + and all(is_share(v) for v in given.values())): # fmt: skip + found.append("`rule.total_noise` is not a share per indicator") + return None + if steps and given != noise_together(steps): + found.append("`rule.total_noise` is not the largest measured noise of the steps, per indicator") floors = said["floors"] if not isinstance(floors, list): found.append("`rule.floors` is not a list") @@ -527,25 +512,20 @@ def _block(block, where, step) -> list[str]: return found -def _counts(data, found, indicators, steps, ranges, total_pairs): +def _counts(data, found, indicators, steps, total_pairs): counts = data.get("counts") - keys = {"steps", TOTAL} | ({"ranges"} if "ranges" in data else set()) - if not isinstance(counts, dict) or set(counts) != keys: - found.append(f"`counts` is not {{{', '.join(sorted(keys))}}}: ranges are counted where, and only where, the file has its key") + if not isinstance(counts, dict) or set(counts) != {"steps", TOTAL}: + found.append("`counts` is not {steps, total}") return {} by_step = counts["steps"] if not isinstance(by_step, dict) or set(by_step) != {s["id"] for s in steps}: found.append("`counts.steps` does not hold every step") return {} - by_range = counts.get("ranges", {}) - if not isinstance(by_range, dict) or set(by_range) != {r["id"] for r in ranges}: - found.append("`counts.ranges` does not hold every range") - return {} published_first = data["states"][0]["kind"] == "published" blocks = {} - compared = [(one["id"], by_step[one["id"]], one) for one in steps] + [(TOTAL, counts[TOTAL], None)] - compared += [(r["id"], by_range[r["id"]], None) for r in ranges] - for k, (key, table, one) in enumerate(compared): + for k, one in enumerate([*steps, None]): + key = one["id"] if one else TOTAL + table = by_step[key] if one else counts[TOTAL] if not isinstance(table, dict) or set(table) != set(indicators): found.append(f"counts of {key!r} do not hold every indicator") return {} @@ -595,7 +575,7 @@ def _attribution(data, found, indicators, steps, blocks): found.append(f"{where}: does not account for every item whose total moved") -def _items(data, found, indicators, states, steps, ranges, floors, tier, blocks): +def _items(data, found, indicators, states, steps, floors, tier, blocks): listed = data.get("items") said = data.get("items_count") if not (isinstance(said, dict) and set(said) == COUNT_KEYS and all(map(is_count, said.values()))): @@ -611,10 +591,6 @@ def _items(data, found, indicators, states, steps, ranges, floors, tier, blocks) found.append("a file of counts holds no item") return [] nsteps = len(steps) - ncompared = nsteps + 1 + len(ranges) - # a range compares the state before its first step with the state after its last - first_of = {s["id"]: k for k, s in enumerate(steps)} - ends = [(first_of[r["steps"][0]], first_of[r["steps"][0]] + len(r["steps"])) for r in ranges] claims_by_step = [s["claim"] for s in steps] any_claim = any(claims_by_step) published_first = data["states"][0]["kind"] == "published" @@ -665,10 +641,8 @@ def _items(data, found, indicators, states, steps, ranges, floors, tier, blocks) and all(v is None or rule.is_value(v) for v in values)): # fmt: skip found.append(f"{where}, {indicator}: the results are not one finite number or null per state") return [] - if not all(isinstance(x, list) and len(x) == ncompared for x in (kinds, ways, bands)): - found.append( - f"{where}, {indicator}: classes, directions and bands are one per step, the total and each range" - ) + if not all(isinstance(x, list) and len(x) == nsteps + 1 for x in (kinds, ways, bands)): + found.append(f"{where}, {indicator}: classes, directions and bands are one per step and the total") return [] floor = floors.get((indicator, item["unit"])) if floor is None: @@ -678,20 +652,13 @@ def _items(data, found, indicators, states, steps, ranges, floors, tier, blocks) if any_claim and not (isinstance(verdicts, list) and len(verdicts) == nsteps): found.append(f"{where}, {indicator}: verdicts are one per step") return [] - for at in range(ncompared): - k = at if at < nsteps else None # the step, or None for the total and a range - if at > nsteps: - one_range = ranges[at - nsteps - 1] - name = one_range["id"] - before, after = values[ends[at - nsteps - 1][0]], values[ends[at - nsteps - 1][1]] - tol, level = one_range["tolerance"], None - elif k is None: - name = TOTAL - before, after = values[0], values[-1] - tol, level = data["rule"]["total_tolerance"], None + for k in [*range(nsteps), None]: + at = nsteps if k is None else k + name = TOTAL if k is None else steps[k]["id"] + before, after = (values[0], values[-1]) if k is None else (values[k], values[k + 1]) + if k is None: + tol, level = data["rule"]["total_tolerance"], total_noise_level(data, indicator) else: - name = steps[k]["id"] - before, after = values[k], values[k + 1] tol = steps[k]["tolerance"]["value"] noise = steps[k]["noise"] level = (noise["by"] or {}).get(indicator) if noise["measured"] else None @@ -917,17 +884,14 @@ def _errors(data, found: list[str]) -> list[str]: steps = _steps(data, found, states, indicators, tier) if not steps: return found - ranges = _ranges(data, found, steps) - if ranges is None: - return found floors = _rule(data, found, indicators, states, steps) count = data["items_count"] total_pairs = count.get("all") if isinstance(count, dict) else None - blocks = _counts(data, found, indicators, steps, ranges, total_pairs) + blocks = _counts(data, found, indicators, steps, total_pairs) if floors is None or not blocks: return found _attribution(data, found, indicators, steps, blocks) - items = _items(data, found, indicators, states, steps, ranges, floors, tier, blocks) + items = _items(data, found, indicators, states, steps, floors, tier, blocks) _explanations(data, found, indicators, steps, set(items), tier) _matrix(data, found) return found diff --git a/src/sentier_diagnostics/from_tables.py b/src/sentier_diagnostics/from_tables.py index 2392431..538dd0a 100644 --- a/src/sentier_diagnostics/from_tables.py +++ b/src/sentier_diagnostics/from_tables.py @@ -20,11 +20,6 @@ "tier": "items" } -`ranges` says which runs of consecutive steps are compared as one: `"all"`, `"none"`, a -list of `[first step, last step]`, or `{"within": [first step, last step]}` for every run -between those two (a chain's fixes, say). Without it, a chain of at most 8 steps has every -run and a longer one none (`chain.AUTO_RANGES`). - A local file of items may also name its matrix of every item (`"matrix": "matrix.json"`, with `"audience": "local"`): `build_with_matrix` then gives it, and `sentier-diagnostics build` writes it beside the file. @@ -43,7 +38,7 @@ from . import chain, claims, fileformat, tables KEYS = {"title", "about", "item", "indicator", "indicators", "items", "states", "steps", "listed", "tier", "audience", - "claim_lists", "explanations", "notes", "floor_factor", "matrix", "ranges"} # fmt: skip + "claim_lists", "explanations", "notes", "floor_factor", "matrix"} # fmt: skip def _origin(said): @@ -146,35 +141,12 @@ def description_errors(spec) -> list[str]: found.append( f"{where}: a noise is {{states: [a, b]}} or {{tables: [{{label, results}}, {{label, results}}]}}" ) - said = spec.get("ranges") - step_ids = [one["id"] for one in steps] - - def run(v): - return isinstance(v, list) and len(v) == 2 and all(isinstance(x, str) and x in step_ids for x in v) - - if said is not None and not ( - said in ("all", "none") - or (isinstance(said, list) and all(map(run, said))) - or (isinstance(said, dict) and set(said) == {"within"} and run(said["within"])) - ): - found.append('`ranges` is "all", "none", a list of [first step, last step] or {"within": [first step, last step]}') explanations = spec.get("explanations", []) if not (isinstance(explanations, list) and all(_table(e, ("text",)) for e in explanations)): found.append("`explanations` is a list of {text, by, ...}") return found -def _ranges(said, steps): - """What `chain.build` takes for the description's `ranges`.""" - if said is None: - return "auto" - if said == "none": - return None - if isinstance(said, dict): - return chain.ranges_within(steps, *said["within"]) - return said if said == "all" else [tuple(one) for one in said] - - def build(path: Path) -> dict: """The diagnostics file a description and its tables give, checked. Every mistake is a ValueError that says what is wrong (`tables.TableError` for a table).""" @@ -317,7 +289,6 @@ def floor_by_item(indicator): floor_factor=floor_factor, explanations=explanations, notes=spec.get("notes", []), - ranges=_ranges(spec.get("ranges"), steps), ) if named is None: return chain.build(spec["title"], **given), None diff --git a/src/sentier_diagnostics/matrix.py b/src/sentier_diagnostics/matrix.py index 0f7f09a..1f714cc 100644 --- a/src/sentier_diagnostics/matrix.py +++ b/src/sentier_diagnostics/matrix.py @@ -28,7 +28,7 @@ FORMAT = "sentier-diagnostics-matrix/1" FAMILY = "sentier-diagnostics-matrix/" KEYS = {"format", "of", "items", "values", "classes", "verdicts"} -OF_KEYS = {"title", "states", "indicators", "steps", "ranges"} +OF_KEYS = {"title", "states", "indicators", "steps"} #: A result written as the same number as the state before it, in the same indicator. SAME = "=" @@ -38,8 +38,7 @@ MAX_ITEMS = 200_000 #: One character per pair: its class, and for a pair that moved its direction (upper case -#: up, lower case down). An item has one per indicator and comparison: each step, the whole -#: way, and each range of the file, in that order. +#: up, lower case down). CODES = { (rule.AGREES, None): "=", (rule.WITHIN_NOISE, None): "~", @@ -125,8 +124,6 @@ def make(data: Mapping, rows: list[dict]) -> dict: "states": [s["id"] for s in data["states"]], "indicators": ids, "steps": [s["id"] for s in steps], - # as the file: [] where none was asked for, left out where it was made before ranges - **({"ranges": [r["id"] for r in data["ranges"]]} if "ranges" in data else {}), }, "items": [], "values": [], @@ -232,14 +229,13 @@ def _errors(m) -> list[str]: of = m["of"] if not ( isinstance(of, dict) - and set(of) in (OF_KEYS, OF_KEYS - {"ranges"}) + and set(of) == OF_KEYS and fileformat.is_text(of["title"], 120) - and all(isinstance(of[k], list) and all(fileformat.is_text(x, 2 * fileformat.MAX_ID + 2) for x in of[k]) - for k in ("states", "indicators", "steps", "ranges") if k in of) + and all(isinstance(of[k], list) and all(fileformat.is_text(x, fileformat.MAX_ID) for x in of[k]) + for k in ("states", "indicators", "steps")) ): # fmt: skip - return ["`of` is not {title, states, indicators, steps, ranges} (ranges left out only before ranges)"] + return ["`of` is not {title, states, indicators, steps}"] nstates, nind, nsteps = len(of["states"]), len(of["indicators"]), len(of["steps"]) - ncodes = nsteps + 1 + len(of.get("ranges", [])) if nsteps != nstates - 1 or not nind: return ["`of`: one step fewer than states, and at least one indicator"] items = m["items"] @@ -270,8 +266,10 @@ def _errors(m) -> list[str]: except ValueError as error: return [f"item {row[0]!r}: {error}"] codes = m["classes"][at] - if not (isinstance(codes, str) and len(codes) == nind * ncodes and all(c in DECODE for c in codes)): - return [f"item {row[0]!r}: not one class code per indicator, step, the whole way and range"] + if not ( + isinstance(codes, str) and len(codes) == nind * (nsteps + 1) and all(c in DECODE for c in codes) + ): + return [f"item {row[0]!r}: not one class code per indicator, step and the whole way"] if has_claims: said = m["verdicts"][at] if not (isinstance(said, str) and len(said) == nind * nsteps @@ -299,26 +297,21 @@ def _against(m: Mapping, data: Mapping) -> list[str]: ids = [i["id"] for i in data["indicators"]] order = [s["id"] for s in data["states"]] steps = data["steps"] - ranges = data.get("ranges") or [] - of = {"title": data["title"], "states": order, "indicators": ids, "steps": [s["id"] for s in steps], - **({"ranges": [r["id"] for r in ranges]} if "ranges" in data else {})} # fmt: skip + of = {"title": data["title"], "states": order, "indicators": ids, "steps": [s["id"] for s in steps]} if m["of"] != of: - return ["it is the matrix of another file: its title, states, indicators, steps or ranges differ"] + return ["it is the matrix of another file: its title, states, indicators or steps differ"] n = len(m["items"]) if named["items"] != n: found.append(f"the diagnostics file says {named['items']} items, the matrix holds {n}") if data["items_count"]["all"] != n: found.append(f"the diagnostics file counts {data['items_count']['all']} items, the matrix holds {n}") nstates, nsteps = len(order), len(steps) - ncodes = nsteps + 1 + len(ranges) - first_of = {s["id"]: k for k, s in enumerate(steps)} - ends = [(first_of[r["steps"][0]], first_of[r["steps"][0]] + len(r["steps"])) for r in ranges] floors = {(f["indicator"], f["unit"]): f["value"] for f in data["rule"]["floors"]} published_first = data["states"][0]["kind"] == "published" listed = {item["id"]: item for item in data["items"]} # what the counts and attribution must be, counted from every item - def empty(k): # k: the step, or None for the total and a range + def empty(k): return { "pairs": 0, "classes": dict.fromkeys(rule.CLASSES, 0), @@ -330,7 +323,7 @@ def empty(k): # k: the step, or None for the total and a range "further": 0 if published_first and k not in (None, 0) else None, } - counted = {(at, i): empty(at if at < nsteps else None) for at in range(ncodes) for i in ids} + counted = {(k, i): empty(k) for k in [*range(nsteps), None] for i in ids} attributed = { i: { "dominant": {s["id"]: 0 for s in steps}, @@ -354,29 +347,24 @@ def empty(k): # k: the step, or None for the total and a range if floor is None: return [f"{where}, {indicator}: the file holds no floor for unit {unit!r}"] kinds = [] - for at_k in range(ncodes): - k = at_k if at_k < nsteps else None - if at_k > nsteps: - one_range = ranges[at_k - nsteps - 1] - before, after = values[ends[at_k - nsteps - 1][0]], values[ends[at_k - nsteps - 1][1]] - tol, level = one_range["tolerance"], None - elif k is None: - before, after = values[0], values[-1] - tol, level = data["rule"]["total_tolerance"], None + for k in [*range(nsteps), None]: + at_k = nsteps if k is None else k + before, after = (values[0], values[-1]) if k is None else (values[k], values[k + 1]) + if k is None: + tol, level = data["rule"]["total_tolerance"], fileformat.total_noise_level(data, indicator) else: - before, after = values[k], values[k + 1] tol = steps[k]["tolerance"]["value"] noise = steps[k]["noise"] level = (noise["by"] or {}).get(indicator) if noise["measured"] else None kind, way, band = rule.judge(before, after, floor=floor, tolerance=tol, noise=level) - code = codes[x * ncodes + at_k] + code = codes[x * (nsteps + 1) + at_k] if code != code_of(kind, way): - step_name = steps[k]["id"] if k is not None else "the whole way" if at_k == nsteps else ranges[at_k - nsteps - 1]["id"] + step_name = "the whole way" if k is None else steps[k]["id"] return [ f"{where}, {indicator}, {step_name}: written as {DECODE[code]}, the rule gives {kind}/{way}" ] kinds.append(kind) - block = counted[(at_k, indicator)] + block = counted[(k, indicator)] block["pairs"] += 1 block["classes"][kind] += 1 if kind == rule.MISSING: @@ -449,16 +437,13 @@ def empty(k): # k: the step, or None for the total and a range f"the diagnostics file counts {data['items_count']['qualifying']} items worth a look, " f"the matrix holds {qualifying}" ) - for (at, indicator), block in counted.items(): - if at < nsteps: - name = steps[at]["id"] - written = data["counts"]["steps"][name][indicator] - elif at == nsteps: - name = fileformat.TOTAL - written = data["counts"][fileformat.TOTAL][indicator] - else: - name = ranges[at - nsteps - 1]["id"] - written = data["counts"]["ranges"][name][indicator] + for (k, indicator), block in counted.items(): + name = fileformat.TOTAL if k is None else steps[k]["id"] + written = ( + data["counts"][fileformat.TOTAL][indicator] + if k is None + else data["counts"]["steps"][name][indicator] + ) for key in block: if block[key] != written[key]: found.append(f"counts of {name!r} in {indicator!r}: `{key}` is not what the matrix holds") diff --git a/src/sentier_diagnostics/page/body.html b/src/sentier_diagnostics/page/body.html index 508b9f3..2bc2600 100644 --- a/src/sentier_diagnostics/page/body.html +++ b/src/sentier_diagnostics/page/body.html @@ -18,13 +18,26 @@

Open a file