pysonar_demo/scoring.pyStatic analysis
1 """Scoring functions with branching and recursive type flow.""" 2 3 4 def clamp(value, lower=0.0, upper=1.0): 5 if value < lower: 6 return lower 7 if value > upper: 8 return upper 9 return value 10 11 12 def confidence_band(score): 13 distance = abs(score - 0.5) 14 if distance >= 0.35: 15 return "high conviction" 16 if distance >= 0.18: 17 return "moderate conviction" 18 return "watchlist" 19 20 21 def weighted_signal(values): 22 """Collapse a list recursively so the demo exposes recursive references.""" 23 if len(values) == 1: 24 return values[0] 25 head = values[0] 26 tail = weighted_signal(values[1:]) 27 return head * 0.6 + tail * 0.4 28 29 30 def score_market(market): 31 price_signal = clamp(market.yes_price) 32 volume_signal = clamp(market.volume / 150000.0) 33 return weighted_signal([price_signal, volume_signal])