Progressbar mit Prozent und Zeit

This commit is contained in:
ISA
2025-08-13 14:04:21 +02:00
parent 974f468766
commit 8fcbf6cfcd
9 changed files with 153 additions and 17 deletions

View File

@@ -7,6 +7,9 @@ export interface DeviceEventsState {
anyLoopActive: boolean;
anyTdrActive: boolean;
anyAlignmentActive: boolean;
loopStartedAt: number | null; // unix ms timestamp when KSX became active
tdrStartedAt: number | null; // unix ms timestamp when KSY became active
alignmentStartedAt: number | null; // unix ms timestamp when KSZ became active
}
const ZERO32 = Array.from({ length: 32 }, () => 0);
@@ -18,6 +21,9 @@ const initialState: DeviceEventsState = {
anyLoopActive: false,
anyTdrActive: false,
anyAlignmentActive: false,
loopStartedAt: null,
tdrStartedAt: null,
alignmentStartedAt: null,
};
export const deviceEventsSlice = createSlice({
@@ -28,6 +34,9 @@ export const deviceEventsSlice = createSlice({
state,
action: PayloadAction<{ ksx?: number[]; ksy?: number[]; ksz?: number[] }>
) {
const prevLoop = state.anyLoopActive;
const prevTdr = state.anyTdrActive;
const prevAlign = state.anyAlignmentActive;
const to32 = (arr?: number[]) => {
if (!Array.isArray(arr)) return ZERO32.slice();
const a = arr
@@ -42,6 +51,16 @@ export const deviceEventsSlice = createSlice({
state.anyLoopActive = state.ksx.some((v) => v === 1);
state.anyTdrActive = state.ksy.some((v) => v === 1);
state.anyAlignmentActive = state.ksz.some((v) => v === 1);
// Transition detection to set/reset startedAt timestamps
if (!prevLoop && state.anyLoopActive) state.loopStartedAt = Date.now();
if (prevLoop && !state.anyLoopActive) state.loopStartedAt = null;
if (!prevTdr && state.anyTdrActive) state.tdrStartedAt = Date.now();
if (prevTdr && !state.anyTdrActive) state.tdrStartedAt = null;
if (!prevAlign && state.anyAlignmentActive)
state.alignmentStartedAt = Date.now();
if (prevAlign && !state.anyAlignmentActive)
state.alignmentStartedAt = null;
},
resetEvents(state) {
state.ksx = ZERO32.slice();
@@ -50,6 +69,9 @@ export const deviceEventsSlice = createSlice({
state.anyLoopActive = false;
state.anyTdrActive = false;
state.anyAlignmentActive = false;
state.loopStartedAt = null;
state.tdrStartedAt = null;
state.alignmentStartedAt = null;
},
},
});