diff --git a/leads/data_persistence/_computational/__init__.py b/leads/data_persistence/_computational/__init__.py index a4830ed..9700dc5 100644 --- a/leads/data_persistence/_computational/__init__.py +++ b/leads/data_persistence/_computational/__init__.py @@ -12,7 +12,6 @@ minimum: type[_np.min] = _np.min maximum: type[_np.max] = _np.max diff: type[_np.diff] = _np.diff -sum_up: type[_np.sum] = _np.sum read_csv: type[_pandas.read_csv] = _pandas.read_csv DataFrame: type[_pandas.DataFrame] = _pandas.DataFrame diff --git a/leads/data_persistence/core.py b/leads/data_persistence/core.py index 7e76273..73920ad 100644 --- a/leads/data_persistence/core.py +++ b/leads/data_persistence/core.py @@ -9,17 +9,20 @@ from leads.types import Compressor as _Compressor, VisualHeader as _VisualHeader, \ VisualHeaderFull as _VisualHeaderFull, DefaultHeaderFull as _DefaultHeaderFull, DefaultHeader as _DefaultHeader from ._computational import array as _array, norm as _norm, read_csv as _read_csv, DataFrame as _DataFrame, \ - TextFileReader as _TextFileReader, sum_up as _sum_up, diff as _diff + TextFileReader as _TextFileReader, diff as _diff, ndarray as _ndarray T = _TypeVar("T", bound=_SupportsFloat) -def weighed_sum(elements: _Sequence[T], indexes: _Sequence[float], a: int = 0, b: int | None = None) -> T: - return _sum_up(_array(elements[a: b]) * _diff(_array(indexes[a: b + 1]))) if b else (_sum_up(_array( - elements[a: -1]) * _diff(_array(indexes[a:]))) + elements[-1]) +def weighed_sum(elements: tuple[T, ...], indexes: tuple[float, ...], a: int = 0, b: int | None = None) -> T: + e = _array(elements[a: b if b else -1]) + w = _diff(_array(indexes[a: b + 1] if b else indexes[a:] + (1,))) + if len(e.shape) > 1: + w = w.reshape((-1, 1)) + return Vector(*tuple(s)) if isinstance(s := (e * w).sum(0, keepdims=True)[0], _ndarray) else float(s) -def weighed_mean(elements: _Sequence[T], indexes: _Sequence[float], a: int = 0, b: int | None = None) -> T: +def weighed_mean(elements: tuple[T, ...], indexes: tuple[float, ...], a: int = 0, b: int | None = None) -> T: return weighed_sum(elements, indexes, a, b) / (indexes[b] - indexes[a]) if b else weighed_sum( elements, indexes, a, b) / (indexes[-1] - indexes[a] + 1) diff --git a/leads_vec_rc/cli.py b/leads_vec_rc/cli.py index 678817a..7937cba 100644 --- a/leads_vec_rc/cli.py +++ b/leads_vec_rc/cli.py @@ -21,7 +21,7 @@ time_stamp_record: DataPersistence[int] = DataPersistence(2000) speed_record: DataPersistence[float] = DataPersistence(2000) -acceleration_record: DataPersistence[float] = DataPersistence(2000) +acceleration_record: DataPersistence[Vector[float]] = DataPersistence(2000) voltage_record: DataPersistence[float] = DataPersistence(2000) gps_record: DataPersistence[Vector[float]] = DataPersistence(2000) csv: CSV | None = None