Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PYEGERIA_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ Tests: `tests/micro-tests/test_issue_172_analytic_entry_points.py`.

**Change** (`pyegeria/view/format_set_executor.py`):
- **not_established / not_applicable** results now return `{"kind": "absent", "content": <sentence>, "absence": {...}, "envelope": {...}}` on every output format. There is no top-level `data`; a partial result rides under `detail`.
- **nothing_found** results keep their data or chart (real zeros) and gain the same `absence` block. A chart's subtitle is the declared `measured_nothing` sentence.
- **nothing_found** results keep their data or chart (real zeros) and gain the same `absence` block. A chart's subtitle is the declared `nothing_found` sentence.
- **measured** results, and results with no envelope, are unchanged.

`absence` gives the state (`not_measured`, `not_permitted`, `not_applicable` or `measured_nothing`), the sentence, the reason, and `declared`. The sentence comes from the function's registered `declaration.absence` (ISSUE-170), looked up by registry name or by dotted path. A function with no declaration gets words built from its own reason, with `declared: False`. `not_established` becomes `not_permitted` only when the result says so itself (`"absence": "not_permitted"`); the reason text is never parsed to guess.
`absence` gives the state (`not_measured`, `not_permitted`, `not_applicable` or `nothing_found`), the sentence, the reason, and `declared`. The sentence comes from the function's registered `declaration.absence` (ISSUE-170), looked up by registry name or by dotted path. A function with no declaration gets words built from its own reason, with `declared: False`. `not_established` becomes `not_permitted` only when the result says so itself (`"absence": "not_permitted"`); the reason text is never parsed to guess.

**Consumers to update:** Egeria Advisor's `report_pipeline`/`report_spec_agent` (trellis) treat an unknown kind generically. `content` is among the keys its fallback reads, so it shows the sentence, but it should handle `absent` explicitly. Any Portal tile that reads `data` for these states gets no `data` now.

Expand Down
6 changes: 3 additions & 3 deletions docs/output-formats-and-report-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,9 @@ All three chart formats are dispatched *before* the normal Format-row lookup (`e
```

There is no top-level `data`, so no table or tile can show placeholder zeros as an answer. A consumer should show `content`. `detail` is there for diagnosis, not display.
- `nothing_found` keeps its data or chart and gains the same `absence` block (state `measured_nothing`). If the function declares sentences, its chart subtitle is the declared one.
- `nothing_found` keeps its data or chart and gains the same `absence` block (state `nothing_found`). If the function declares sentences, its chart subtitle is the declared one.

The `absence` states are the four of trellis-analytics: `not_measured`, `not_permitted`, `not_applicable` and `measured_nothing`. `not_established` becomes `not_measured`, unless the result itself says `"absence": "not_permitted"`; the reason text is never parsed to guess. The sentence is the function's declared one (see [Declaring what results mean](#declaring-what-results-mean)). A function with no declaration gets words built from its own reason, with `declared: false`.
The `absence` states are the four of trellis-analytics: `not_measured`, `not_permitted`, `not_applicable` and `nothing_found`. `not_established` becomes `not_measured`, unless the result itself says `"absence": "not_permitted"`; the reason text is never parsed to guess. The sentence is the function's declared one (see [Declaring what results mean](#declaring-what-results-mean)). A function with no declaration gets words built from its own reason, with `declared: false`.

A result without an envelope is returned exactly as before. A result that is a pydantic model is returned as plain data (`model_dump`). See ISSUE-139/140/171.

Expand Down Expand Up @@ -1050,7 +1050,7 @@ AnalyticFunctionSpec(
"not_measured": "Coverage was not measured: the catalog could not be read.",
"not_permitted": "Coverage was not measured: reading the catalog is not permitted.",
"not_applicable": "Coverage does not apply to this resource.",
"measured_nothing": "The catalog was read and holds no columns.",
"nothing_found": "The catalog was read and holds no columns.",
},
},
)
Expand Down
32 changes: 25 additions & 7 deletions pyegeria/view/analytic_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
'AbsenceSentences',
'RESULT_KINDS',
'ABSENCE_STATES',
'canonical_absence_state',
'KNOWN_ANALYTIC_SOURCES',
'AnalyticRegistryCollision',
'refresh_analytic_functions',
Expand Down Expand Up @@ -125,9 +126,18 @@ class AnalyticActionSpec(BaseModel):
RESULT_KINDS = ("measure", "series", "distribution", "list", "graph", "finding", "proposal", "table")

#: The four ways a result can be absent, each a sentence the function declares. Envelope states
#: map onto them: nothing_found -> measured_nothing; not_established -> not_measured (or
#: map onto them: nothing_found -> nothing_found; not_established -> not_measured (or
#: not_permitted, told apart by the reason); not_applicable -> not_applicable.
ABSENCE_STATES = ("not_measured", "not_permitted", "not_applicable", "measured_nothing")
ABSENCE_STATES = ("not_measured", "not_permitted", "not_applicable", "nothing_found")

#: The word 0.2 / 6.2.22 used for `nothing_found`. Read everywhere, written nowhere (RS-W1-1).
LEGACY_NOTHING_FOUND = "measured_nothing"


def canonical_absence_state(state: Any) -> Any:
"""The current absence word for `state`: the legacy `measured_nothing` reads as `nothing_found`;
every other value is returned unchanged."""
return "nothing_found" if state == LEGACY_NOTHING_FOUND else state


def _words(value: Any) -> str:
Expand Down Expand Up @@ -169,7 +179,17 @@ class AbsenceSentences(BaseModel):
not_measured: str
not_permitted: str
not_applicable: str
measured_nothing: str
nothing_found: str

@model_validator(mode="before")
@classmethod
def _legacy_word(cls, data: Any) -> Any:
"""Declarations authored before RS-W1-1 say `measured_nothing`; read it as `nothing_found`."""
if isinstance(data, dict) and LEGACY_NOTHING_FOUND in data:
data = dict(data)
legacy = data.pop(LEGACY_NOTHING_FOUND)
data.setdefault("nothing_found", legacy)
return data

@model_validator(mode="after")
def _filled(self) -> "AbsenceSentences":
Expand All @@ -180,7 +200,7 @@ def _filled(self) -> "AbsenceSentences":
return self

def sentence(self, state: str) -> str:
return getattr(self, state)
return getattr(self, canonical_absence_state(state))


class AnalyticDeclaration(BaseModel):
Expand Down Expand Up @@ -647,14 +667,12 @@ def _strict() -> AnalyticParam:
MeasureDeclaration(name="not_visible", unit="elements", as_of="as_of",
value_field="rows.not_visible.value"),
],
# RS-W1-1 PR-2 (the nothing_found rename) has not landed: the fourth word is
# still measured_nothing here.
absence=AbsenceSentences(
not_measured="The subtype counts could not be measured: the count queries failed or "
"the server could not answer them.",
not_permitted="You are not permitted to count these elements.",
not_applicable="A subtype composition does not apply to this type.",
measured_nothing="Counted: there are no elements of this type or its subtypes.",
nothing_found="Counted: there are no elements of this type or its subtypes.",
),
),
),
Expand Down
13 changes: 7 additions & 6 deletions pyegeria/view/format_set_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
get_report_registry,
)
from pyegeria.view.output_formatter import generate_output
from pyegeria.view.analytic_registry import ABSENCE_STATES, AnalyticActionSpec
from pyegeria.view.analytic_registry import ABSENCE_STATES, AnalyticActionSpec, canonical_absence_state
from pyegeria.view.analytic_registry import get_analytic_registry as get_analytic_registry_functions
from pyegeria.egeria_tech_client import EgeriaTech

Expand Down Expand Up @@ -297,8 +297,9 @@ def _from_mapping(m: Dict[str, Any]) -> Optional[Dict[str, str]]:
reason = str(m.get("state_reason", m.get("resultStateReason", m.get("result_state_reason", ""))) or "")
subtitle = m.get("subtitle") or (state.replace("_", " ") + (f" \u00b7 {reason}" if reason else ""))
found = {"state": state, "reason": reason, "subtitle": str(subtitle)}
if m.get("absence") in ABSENCE_STATES: # the result says which absence (ISSUE-171)
found["absence"] = m["absence"]
claimed = canonical_absence_state(m.get("absence")) # legacy measured_nothing reads as nothing_found
if claimed in ABSENCE_STATES: # the result says which absence (ISSUE-171)
found["absence"] = claimed
return found

if isinstance(result, dict):
Expand Down Expand Up @@ -334,7 +335,7 @@ def _with_envelope(out: Dict[str, Any], envelope: Optional[Dict[str, str]]) -> D
# not_measured unless the result itself claims not_permitted (an `absence` key);
# the reason text is never parsed to guess which.
_ABSENCE_FOR_STATE = {
"nothing_found": "measured_nothing",
"nothing_found": "nothing_found",
"not_established": "not_measured",
"not_applicable": "not_applicable",
}
Expand All @@ -344,7 +345,7 @@ def _with_envelope(out: Dict[str, Any], envelope: Optional[Dict[str, str]]) -> D
"not_measured": "Not measured",
"not_permitted": "Not measured: not permitted",
"not_applicable": "Does not apply",
"measured_nothing": "Measured; nothing found",
"nothing_found": "Measured; nothing found",
}


Expand All @@ -363,7 +364,7 @@ def _absence_for(envelope: Optional[Dict[str, str]], func_decl: str) -> Optional
one with no envelope, which keep their old shapes."""
if not envelope or envelope["state"] not in _ABSENCE_FOR_STATE:
return None
state = _ABSENCE_FOR_STATE[envelope["state"]]
state = canonical_absence_state(_ABSENCE_FOR_STATE[envelope["state"]])
if state == "not_measured" and envelope.get("absence") == "not_permitted":
state = "not_permitted"
reason = envelope.get("reason", "")
Expand Down
14 changes: 12 additions & 2 deletions tests/micro-tests/test_issue_170_analytic_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"not_measured": "Coverage was not measured: the catalog could not be read.",
"not_permitted": "Coverage was not measured: reading the catalog is not permitted.",
"not_applicable": "Coverage does not apply to this resource.",
"measured_nothing": "No columns were found to cover.",
"nothing_found": "No columns were found to cover.",
}

DECLARATION = {
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_declaration_round_trips_on_a_spec():
declaration=DECLARATION)
m = spec.declaration.measures[0]
assert (m.unit, m.as_of, m.basis.denominator_label) == ("columns", "asOf", "columns")
assert spec.declaration.absence.sentence("measured_nothing") == ABSENCE["measured_nothing"]
assert spec.declaration.absence.sentence("nothing_found") == ABSENCE["nothing_found"]
assert AnalyticFunctionSpec(**spec.model_dump()).declaration == spec.declaration


Expand Down Expand Up @@ -80,3 +80,13 @@ def test_incomplete_declarations_are_refused_with_a_sentence(bad, words):

def test_unmeasured_kinds_need_no_measures():
assert AnalyticDeclaration(result_kind="finding", absence=ABSENCE).measures == []


def test_legacy_measured_nothing_declaration_still_loads_and_is_written_as_nothing_found():
legacy = dict(ABSENCE)
legacy["measured_nothing"] = legacy.pop("nothing_found")
decl = AnalyticDeclaration(**{**DECLARATION, "absence": legacy})
assert decl.absence.nothing_found == ABSENCE["nothing_found"]
assert decl.absence.sentence("measured_nothing") == ABSENCE["nothing_found"]
dumped = decl.model_dump()
assert "measured_nothing" not in dumped["absence"] and dumped["absence"]["nothing_found"]
24 changes: 19 additions & 5 deletions tests/micro-tests/test_issue_171_state_aware_report_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"not_measured": "Coverage was not measured: the catalog could not be read.",
"not_permitted": "Coverage was not measured: reading the catalog is not permitted.",
"not_applicable": "Coverage does not apply to this resource.",
"measured_nothing": "The catalog was read and holds no columns.",
"nothing_found": "The catalog was read and holds no columns.",
}


Expand Down Expand Up @@ -102,19 +102,19 @@ def test_not_applicable_says_so(monkeypatch):
assert (out["kind"], out["content"]) == ("absent", ABSENCE["not_applicable"])


def test_nothing_found_carries_the_measured_nothing_sentence(monkeypatch):
def test_nothing_found_carries_the_nothing_found_sentence(monkeypatch):
_declare("nothing_found_empty")
out = _run(monkeypatch, "nothing_found_empty")
assert out["kind"] == "json" # a real answer: the dict, with its sentence
assert out["absence"]["state"] == "measured_nothing"
assert out["absence"]["sentence"] == ABSENCE["measured_nothing"]
assert out["absence"]["state"] == "nothing_found"
assert out["absence"]["sentence"] == ABSENCE["nothing_found"]


def test_nothing_found_counts_are_charted_with_the_declared_sentence(monkeypatch):
_declare("nothing_found_counts")
out = _run(monkeypatch, "nothing_found_counts", "BAR")
assert "$schema" in out["data"]
assert out["data"]["title"] == {"text": "Coverage", "subtitle": ABSENCE["measured_nothing"]}
assert out["data"]["title"] == {"text": "Coverage", "subtitle": ABSENCE["nothing_found"]}


def test_undeclared_function_gets_words_from_its_own_reason(monkeypatch):
Expand All @@ -136,3 +136,17 @@ def test_registered_name_finds_the_declaration(monkeypatch):
assert fse._declaration_for("cov-not_established").absence.not_measured == ABSENCE["not_measured"]
assert fse._declaration_for(f"{MOD}.not_established") is not None
assert fse._declaration_for(f"{MOD}.unregistered") is None


def test_legacy_declaration_and_stored_result_word_still_resolve(monkeypatch):
legacy = dict(ABSENCE)
legacy["measured_nothing"] = legacy.pop("nothing_found")
register_analytic_functions({"legacy": {"name": "legacy", "function": f"{MOD}.nothing_found_empty",
"declaration": {"result_kind": "list", "absence": legacy}}})
out = fse._absence_for({"state": "nothing_found"}, "legacy")
assert out["state"] == "nothing_found" and out["sentence"] == ABSENCE["nothing_found"]
# a stored result that names its absence with the old word is read as the new one
from pyegeria.view.analytic_registry import canonical_absence_state
assert canonical_absence_state("measured_nothing") == "nothing_found"
found = fse._result_envelope({"state": "not_established", "absence": "measured_nothing"})
assert found["absence"] == "nothing_found"
2 changes: 1 addition & 1 deletion tests/micro-tests/test_overview_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,4 @@ def test_asset_composition_is_registered_with_a_declaration():
assert decl.result_kind == "distribution"
assert {m.name for m in decl.measures} == {"repository_count", "viewer_count", "not_visible"}
assert all(m.unit == "elements" and m.as_of == "as_of" for m in decl.measures)
assert decl.absence.measured_nothing # RS-W1-1 PR-2 not landed: still measured_nothing
assert decl.absence.nothing_found
Loading