feat(product): add /v4/product/risk and /v4/product/light (Laixer/FunderMaps#985)#10
Merged
Merged
Conversation
Two new billable products on top of data.model_risk_static. - /v4/product/risk — subset of analysis for valuation chains and dashboards. Same data source, fewer fields. - /v4/product/light — minimal output for fast chain integrations. The three component risks (drystand, bio-infection, dewatering-depth) collapse into one overallRisk plus its overallRiskReliability. Priority is reliability tier first (established > cluster > supercluster > indicative), then risk letter (E > D > C > B > A) within the same tier — so 'C established' beats 'D indicative'. Override: any non-NULL recovery_type forces overallRisk = A with established reliability — a recovered building is the lowest risk class by definition and the recovery flag itself is hard evidence. Tracker product names: risk3, light3 (matching the analysis3 / statistics3 versioning). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new billable products on top of `data.model_risk_static` per Laixer/FunderMaps#985.
overallRisk derivation (light)
The three component risks — drystand, bio-infection, dewatering-depth — collapse into one `overallRisk` + `overallRiskReliability`. Priority is:
So `C established` beats `D indicative` — the example called out in the issue. Components missing either field are skipped (null risk without a reliability label can't compete).
Recovery override. Any non-NULL `recovery_type` forces `overallRisk = "a"` with `overallRiskReliability = "established"`, regardless of model output. A recovered building is the lowest risk class by definition, and the recovery flag itself is hard evidence — confirmed in scoping that `unknown` (the 'known-recovered, type unclear' sentinel) also triggers the override.
The computation lives as a pure function in `src/risk.ts` with 12 table-driven tests in `risk.test.ts` covering each rule the issue pins down (issue example, in-tier letter ranking, cross-tier reliability, null-component skipping, all-null, the override, override on `unknown`, override over otherwise-worst data).
Naming note
Issue spells it `product_risc` (Dutch). Code stays English (`risk` / `light`) to match the rest of the surface — confirmed in scoping.
Test plan
Dev DB has no rows with `recovery_type` set, so the override branch is verified by unit tests rather than HTTP — the route passes `recovery_type` straight into `computeOverallRisk` with no extra logic, so the unit-test coverage is the relevant signal there.
🤖 Generated with Claude Code