diff --git a/docs_test/src/assets/helpers.tsx b/docs_test/src/assets/helpers.tsx index 5cfe8eb..3cd5994 100644 --- a/docs_test/src/assets/helpers.tsx +++ b/docs_test/src/assets/helpers.tsx @@ -1,7 +1,8 @@ import React from "react"; export type DataPoint = { - timestamp: string; // ISO format + time: string // ISO format + timestamp: number; // epoch milliseconds value: number; }; diff --git a/docs_test/src/dashboard/components/MainGrid.tsx b/docs_test/src/dashboard/components/MainGrid.tsx index 9f637f1..df9e746 100644 --- a/docs_test/src/dashboard/components/MainGrid.tsx +++ b/docs_test/src/dashboard/components/MainGrid.tsx @@ -95,7 +95,8 @@ export default function MainGrid() { if(payload.topic in topic_map) { const { update } = topic_map[payload.topic]; const newPoint: DataPoint = { - timestamp: new Date().toISOString(), + time: new Date().toISOString(), + timestamp: Date.now(), value: d }; update(current => [...current, newPoint]) @@ -228,10 +229,10 @@ export default function MainGrid() { up for {serverUptime} - + - + diff --git a/docs_test/src/dashboard/components/SessionsChart.tsx b/docs_test/src/dashboard/components/SessionsChart.tsx index 0708355..1e5bfd1 100644 --- a/docs_test/src/dashboard/components/SessionsChart.tsx +++ b/docs_test/src/dashboard/components/SessionsChart.tsx @@ -7,6 +7,7 @@ import CountUp from 'react-countup'; import type { DataPoint } from '../../assets/helpers.jsx'; import {CircularProgress} from "@mui/material"; + import {useRef} from "react"; const currentTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; @@ -117,6 +118,23 @@ export default function SessionsChart(props: any) { + const lastCalc = useRef(0); + + const calc_per_second = (curValue: DataPoint, lastValue: DataPoint) => { + if(!props.isPerSecond) { return ''; } + + if(!curValue || !lastValue) { + return ''; + } + + if(curValue.timestamp - lastValue.timestamp > 0) { + const per_second = (curValue.value - lastValue.value) / ((curValue.timestamp - lastValue.timestamp) / 1000); + lastCalc.current = Math.trunc(per_second * 10) / 10; + } + + return `${lastCalc.current} / sec`; + } + return ( @@ -143,6 +161,9 @@ />} {props.label} +

+ { calc_per_second(props.data[props.data.length-1], props.data[props.data.length-2]) } +

{ props.data.length < 2 ? :