Skip to content

Commit 671cf83

Browse files
committed
add constants to front
1 parent 31e0734 commit 671cf83

7 files changed

Lines changed: 45 additions & 24 deletions

File tree

control-station/DELTA_TIME.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ The delta time tracking system detects when telemetry values haven't changed for
1313

1414
## Configuration Parameters
1515

16+
### Global Constants
17+
Delta tracking timing is configured globally in `/src/constants/deltaTracking.ts`:
18+
- **DELTA_SAMPLE_PERIOD**: 400ms (time between checks for value changes)
19+
- **DELTA_GRACE_PERIOD**: 100ms (standard grace period before marking as stale)
20+
- **DELTA_GRACE_PERIOD_LONG**: 5000ms (extended grace period for slow-changing values)
21+
1622
### Common Settings
17-
- **Sampling Period**: 400ms (time between checks for value changes)
18-
- **Grace Period**: Varies by component type
19-
- Boolean/Enum indicators: 100ms
20-
- Numeric displays: 100ms to 5 seconds
23+
- **Sampling Period**: Uses `DELTA_SAMPLE_PERIOD` constant (default: 400ms)
24+
- **Grace Period**: Uses `DELTA_GRACE_PERIOD` constant (default: 100ms)
2125
- **Tolerance**: 0.01 to 0.5 depending on measurement type
2226

2327
## Affected Components

control-station/src/components/BatteriesModules/BatteriesModule.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useContext, useRef, useMemo } from "react";
22
import styles from "./BatteriesModule.module.scss";
33
import { useGlobalTicker, useMeasurementsStore, usePodDataStore } from "common";
44
import { LostConnectionContext } from "services/connections";
5+
import { DELTA_SAMPLE_PERIOD, DELTA_GRACE_PERIOD } from "constants/deltaTracking";
56

67
interface CellProps {
78
value: number | null;
@@ -50,14 +51,14 @@ const BatteriesModule: React.FC<{ id: string | number }> = ({ id }) => {
5051
const now = Date.now();
5152
const prevData = deltaTrackingRef.current[key];
5253

53-
// Check if 400ms have passed since last sample
54-
if (prevData && now - prevData.lastSampleTime < 400) {
54+
// Check if sample period has passed since last sample
55+
if (prevData && now - prevData.lastSampleTime < DELTA_SAMPLE_PERIOD) {
5556
// Not enough time passed, return current value if not stale, otherwise null
5657
const currentValue = originalGetter();
5758
return prevData.isStale ? null : currentValue;
5859
}
5960

60-
// 400ms have passed or no previous data, get fresh value
61+
// Sample period has passed or no previous data, get fresh value
6162
const currentValue = originalGetter();
6263

6364
// Initialize if no previous data
@@ -90,7 +91,7 @@ const BatteriesModule: React.FC<{ id: string | number }> = ({ id }) => {
9091
} else {
9192
// Value hasn't changed significantly, check if it's been stale for too long
9293
const staleDuration = now - prevData.lastChangeTime;
93-
const isStale = staleDuration > 100; // 100ms grace period
94+
const isStale = staleDuration > DELTA_GRACE_PERIOD; // Grace period
9495

9596
deltaTrackingRef.current[key] = {
9697
value: currentValue,

control-station/src/components/BoosterModules/BoosterModule.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styles from "./BoosterModule.module.scss";
33

44
import { useMeasurementsStore, useGlobalTicker, usePodDataStore } from "common";
55
import { LostConnectionContext } from "services/connections";
6+
import { DELTA_SAMPLE_PERIOD, DELTA_GRACE_PERIOD } from "constants/deltaTracking";
67

78
interface CellProps {
89
value: number | null;
@@ -40,14 +41,14 @@ const BoosterModule: React.FC<{ id: string | number }> = ({ id }) => {
4041
const now = Date.now();
4142
const prevData = deltaTrackingRef.current[key];
4243

43-
// Check if 400ms have passed since last sample
44-
if (prevData && now - prevData.lastSampleTime < 400) {
44+
// Check if sample period has passed since last sample
45+
if (prevData && now - prevData.lastSampleTime < DELTA_SAMPLE_PERIOD) {
4546
// Not enough time passed, return current value if not stale, otherwise null
4647
const currentValue = originalGetter();
4748
return prevData.isStale ? null : currentValue;
4849
}
4950

50-
// 400ms have passed or no previous data, get fresh value
51+
// Sample period has passed or no previous data, get fresh value
5152
const currentValue = originalGetter();
5253

5354
// Initialize if no previous data
@@ -80,7 +81,7 @@ const BoosterModule: React.FC<{ id: string | number }> = ({ id }) => {
8081
} else {
8182
// Value hasn't changed significantly, check if it's been stale for too long
8283
const staleDuration = now - prevData.lastChangeTime;
83-
const isStale = staleDuration > 100; // 100ms grace period
84+
const isStale = staleDuration > DELTA_GRACE_PERIOD; // Grace period
8485

8586
deltaTrackingRef.current[key] = {
8687
value: currentValue,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Global constants for delta tracking functionality
3+
*/
4+
5+
// Sample period in milliseconds - time between delta checks
6+
export const DELTA_SAMPLE_PERIOD = 2000;
7+
8+
// Grace period in milliseconds - time to wait after no change before marking as stale
9+
export const DELTA_GRACE_PERIOD = 1000;
10+
11+
// Grace period for slow-changing values (like position)
12+
export const DELTA_GRACE_PERIOD_LONG = 1000;

control-station/src/pages/VehiclePage/BatteriesPage/BatteriesPage.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { usePodDataUpdate } from "hooks/usePodDataUpdate";
1515
import { Connection, useConnections } from "common";
1616
import { LostConnectionContext } from "services/connections";
1717
import { Window } from "components/Window/Window";
18+
import { DELTA_SAMPLE_PERIOD, DELTA_GRACE_PERIOD } from "constants/deltaTracking";
1819

1920
interface ModuleData {
2021
id: number | string;
@@ -122,14 +123,14 @@ export function BatteriesPage() {
122123
const now = Date.now();
123124
const prevData = deltaTrackingRef.current[key];
124125

125-
// Check if 400ms have passed since last sample
126-
if (prevData && now - prevData.lastSampleTime < 400) {
126+
// Check if sample period has passed since last sample
127+
if (prevData && now - prevData.lastSampleTime < DELTA_SAMPLE_PERIOD) {
127128
// Not enough time passed, return current value if not stale, otherwise null
128129
const currentValue = originalGetter();
129130
return prevData.isStale ? null : currentValue;
130131
}
131132

132-
// 400ms have passed or no previous data, get fresh value
133+
// Sample period has passed or no previous data, get fresh value
133134
const currentValue = originalGetter();
134135

135136
// Initialize if no previous data
@@ -162,7 +163,7 @@ export function BatteriesPage() {
162163
} else {
163164
// Value hasn't changed significantly, check if it's been stale for too long
164165
const staleDuration = now - prevData.lastChangeTime;
165-
const isStale = staleDuration > 100; // 100ms grace period
166+
const isStale = staleDuration > DELTA_GRACE_PERIOD; // Grace period
166167

167168
deltaTrackingRef.current[key] = {
168169
value: currentValue,

control-station/src/pages/VehiclePage/MainPage/MainPageModules/BrakeState.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "common";
77
import { useContext, useState, useRef, useMemo } from "react";
88
import { LostConnectionContext } from "services/connections";
9+
import { DELTA_SAMPLE_PERIOD, DELTA_GRACE_PERIOD } from "constants/deltaTracking";
910
import styles from "../MainPage.module.scss";
1011

1112
export const BrakeState = () => {
@@ -35,14 +36,14 @@ export const BrakeState = () => {
3536
const now = Date.now();
3637
const prevData = deltaTrackingRef.current;
3738

38-
// Check if 400ms have passed since last sample
39-
if (prevData && now - prevData.lastSampleTime < 400) {
39+
// Check if sample period has passed since last sample
40+
if (prevData && now - prevData.lastSampleTime < DELTA_SAMPLE_PERIOD) {
4041
// Not enough time passed, return current value if not stale, otherwise null
4142
const currentValue = getValue();
4243
return prevData.isStale ? null : currentValue;
4344
}
4445

45-
// 400ms have passed or no previous data, get fresh value
46+
// Sample period has passed or no previous data, get fresh value
4647
const currentValue = getValue();
4748

4849
// Initialize if no previous data
@@ -73,7 +74,7 @@ export const BrakeState = () => {
7374
} else {
7475
// Value hasn't changed, check if it's been stale for too long
7576
const staleDuration = now - prevData.lastChangeTime;
76-
const isStale = staleDuration > 100; // 100 milliseconds for boolean values
77+
const isStale = staleDuration > DELTA_GRACE_PERIOD; // Grace period for boolean values
7778

7879
deltaTrackingRef.current = {
7980
value: currentValue,

control-station/src/pages/VehiclePage/MainPage/MainPageModules/Leds.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "common";
66
import { memo, useContext, useState, useRef, useMemo, useEffect } from "react";
77
import { LostConnectionContext } from "services/connections";
8+
import { DELTA_SAMPLE_PERIOD, DELTA_GRACE_PERIOD } from "constants/deltaTracking";
89
import styles from "../MainPage.module.scss";
910

1011
type Props = {
@@ -35,14 +36,14 @@ export const LEDS = memo(({ measurement }: Props) => {
3536
const now = Date.now();
3637
const prevData = deltaTrackingRef.current;
3738

38-
// Check if 400ms have passed since last sample
39-
if (prevData && now - prevData.lastSampleTime < 400) {
39+
// Check if sample period has passed since last sample
40+
if (prevData && now - prevData.lastSampleTime < DELTA_SAMPLE_PERIOD) {
4041
// Not enough time passed, return current value if not stale, otherwise null
4142
const currentValue = voltage.getUpdate();
4243
return prevData.isStale ? null : currentValue;
4344
}
4445

45-
// 400ms have passed or no previous data, get fresh value
46+
// Sample period has passed or no previous data, get fresh value
4647
const currentValue = voltage.getUpdate();
4748

4849
// Initialize if no previous data
@@ -78,7 +79,7 @@ export const LEDS = memo(({ measurement }: Props) => {
7879
} else {
7980
// Value hasn't changed significantly, check if it's been stale for too long
8081
const staleDuration = now - prevData.lastChangeTime;
81-
const isStale = staleDuration > 100; // 100 milliseconds for voltage values
82+
const isStale = staleDuration > DELTA_GRACE_PERIOD; // Grace period for voltage values
8283

8384
deltaTrackingRef.current = {
8485
value: currentValue,

0 commit comments

Comments
 (0)