23 lines
739 B
Python
23 lines
739 B
Python
from __future__ import annotations
|
|
|
|
from typing import Dict, List
|
|
|
|
from .contracts import Signal
|
|
|
|
|
|
class Aggregator:
|
|
@staticmethod
|
|
def aggregate_signals(signals: List[Signal]) -> Dict[str, float]:
|
|
# Simple cross-venue aggregation: average of numeric metrics where possible
|
|
sums: Dict[str, float] = {}
|
|
counts: Dict[str, int] = {}
|
|
for s in signals:
|
|
for k, v in s.metrics.items():
|
|
try:
|
|
val = float(v)
|
|
except (TypeError, ValueError):
|
|
continue
|
|
sums[k] = sums.get(k, 0.0) + val
|
|
counts[k] = counts.get(k, 0) + 1
|
|
return {k: (sums[k] / counts[k] if counts[k] else 0.0) for k in sums}
|