package staffing import "github.com/shopspring/decimal" // Confidence is a DETERMINISTIC transparency aid in [0,1], never a probability and never an input to a // decision. It blends three observable, explainable factors: // // confidence = wFit * (total / 100) + wProvenance * provenanceScore + wCompleteness * completeness // // fit is how far the engine score is above zero, provenanceScore reflects how the clearance was // established (a self reported clearance is weaker evidence than continuous vetting), and completeness is // the fraction of profile sections present. All three are bounded in [0,1] and the weights sum to 1, so // the result is bounded in [0,1]. It is computed with decimal, never float, and rounded to 4 places to // match the numeric(5,4) column. func Confidence(cfg Config, c ScoredCandidate) decimal.Decimal { fit := c.Total.Div(decimal.NewFromInt(100)) prov, ok := provenanceScore[c.Provenance] if !ok { prov = unknownProvenanceScore // an unknown or absent provenance is the conservative floor } comp := clamp01(c.Completeness) score := cfg.ConfidenceFitWeight.Mul(clamp01(fit)). Add(cfg.ConfidenceProvenanceWeight.Mul(prov)). Add(cfg.ConfidenceCompletenessWeight.Mul(comp)) return clamp01(score).Round(4) } // provenanceScore maps a clearance provenance code to its evidence strength. The codes are the // candidates.clearance_provenance domain. Higher is stronger evidence the clearance is real and current. var provenanceScore = map[string]decimal.Decimal{ "self_reported": decimal.RequireFromString("0.40"), "document": decimal.RequireFromString("0.60"), "sponsor_verified": decimal.RequireFromString("0.90"), "continuous_vetting": decimal.NewFromInt(1), } var unknownProvenanceScore = decimal.RequireFromString("0.30") func clamp01(d decimal.Decimal) decimal.Decimal { if d.LessThan(decimal.Zero) { return decimal.Zero } if d.GreaterThan(decimal.NewFromInt(1)) { return decimal.NewFromInt(1) } return d }