import dayjs from 'dayjs' /** Gleiche Logik wie History.jsx für rollierende Mittel */ export function rollingAvg(arr, key, window = 7) { return arr.map((d, i) => { const s = arr .slice(Math.max(0, i - window + 1), i + 1) .map((x) => x[key]) .filter((v) => v != null) return s.length ? { ...d, [`${key}_avg`]: Math.round((s.reduce((a, b) => a + b, 0) / s.length) * 10) / 10 } : d }) } export const fmtDate = (d) => dayjs(d).format('DD.MM')