from numpy.typing import ArrayLike
from spatz.metrics import Metric


class MaxAbsDeviation(Metric):
    def __init__(self) -> None:
        """A metric tracking the maximum absolute deviation from the true value."""
        super().__init__()

    def _update(self, x: ArrayLike, y: ArrayLike):
        self._score = max(self._score, abs(x - y))


class MaxRelDeviation(Metric):
    def __init__(self) -> None:
        """A metric tracking the maximum deviation from the true value in percent."""
        super().__init__()

    def _update(self, x: ArrayLike, y: ArrayLike):
        self._score = max(self._score, (x - y) / y)
