refactor: centralize numeric normalization
This commit is contained in:
@@ -4,6 +4,8 @@ from copy import deepcopy
|
||||
from statistics import mean, median
|
||||
from typing import Any
|
||||
|
||||
from backend.data.numbers import non_nan_number as _number
|
||||
|
||||
|
||||
COMPONENT_WEIGHTS = {
|
||||
"breadth": 20,
|
||||
@@ -16,14 +18,6 @@ COMPONENT_WEIGHTS = {
|
||||
SENTIMENT_ENGINE_VERSION = 2
|
||||
|
||||
|
||||
def _number(value: Any, default: float = 0.0) -> float:
|
||||
try:
|
||||
number = float(value)
|
||||
return number if number == number else default
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
|
||||
def _clamp(value: float, lower: float = 0.0, upper: float = 100.0) -> float:
|
||||
return min(upper, max(lower, value))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user