estimate wizard display dec for ggod better best packages

This commit is contained in:
Mayur Shinde
2026-06-12 17:19:29 +05:30
parent 46c8933ec7
commit eff6695f54
3 changed files with 108 additions and 53 deletions
@@ -55,6 +55,15 @@ export function computeHailRisk(input) {
const p10Low = prob(lambdaLow, 10);
const p10High = prob(lambdaHigh, 10);
// Never present a 100% historical probability — that reads as a certainty/guarantee,
// which this model explicitly is not (spec §6). High-activity areas push p10High to
// ~1.0, so cap the DISPLAYED band just under certainty. Underlying p10* values still
// drive the exposure tier and scoring unchanged.
const MAX_DISPLAY_PROB = 0.95;
const dispLow = Math.min(p10Low, MAX_DISPLAY_PROB);
const dispBase = Math.min(p10Base, MAX_DISPLAY_PROB);
const dispHigh = Math.min(p10High, MAX_DISPLAY_PROB);
// Confidence score (0..1): sample size + window length + geocode precision.
const sampleScore = clamp(count / 8, 0, 1); // ~8+ events → strong
const windowScore = clamp(years / 10, 0, 1); // 10y window → full
@@ -74,7 +83,7 @@ export function computeHailRisk(input) {
annualRate: +lambda.toFixed(3),
maxHailInches,
lastEventDate,
probability10yr: { low: pct(p10Low), base: pct(p10Base), high: pct(p10High) },
probability10yr: { low: pct(dispLow), base: pct(dispBase), high: pct(dispHigh) },
confidence: confidenceLabel,
confidenceValue,
exposureTier,
@@ -87,7 +96,7 @@ export function computeHailRisk(input) {
: `This area has averaged about ${lambda.toFixed(1)} observed hail event(s) per year in the available dataset.`,
probability: count === 0
? 'There is not enough historical hail activity nearby to estimate a meaningful probability.'
: `Based on historical reports, the chance of at least one hail event in the next 10 years is estimated at ${pct(p10Low)}${pct(p10High)}%, assuming future patterns resemble the past.`,
: `Based on historical reports, the chance of at least one hail event in the next 10 years is estimated at ${pct(dispLow)}${pct(dispHigh)}%, assuming future patterns resemble the past.`,
confidence: `Confidence: ${confidenceLabel}. This is based on county-level and nearby reports within ~${radiusMiles} miles, not a roof-specific inspection.`,
lastUpdated: `Storm data reflects reports through ${new Date(generatedAt).toLocaleDateString()}.`,
},