Skip to main content

Unit References Analysis

This document catalogs all locations in the codebase where units are hardcoded and need to be updated to use the new UnitsContext.

Summary​

The following units were searched for:

  • flow: "GPM"
  • status: "OPEN/CLOSED"
  • headloss: "FEET"
  • power: "kW"
  • velocity: "FT/SEC"
  • setting: "N/A"
  • leakage: "GPM"
  • head: "FEET"
  • demand: "GPM"
  • pressure: "PSI"
  • level: "FEET"
  • tankVolume: "GAL"
  • leakageFlow: "GPM"
  • AGE: "HOURS"
  • CHLORINE: "MG/L"
  • TR1: "N/A"
  • TR2: "N/A"
  • CONDUCTIVITY: "S"
  • THM: "UG/L"

Files Requiring Updates​

1. Dashboard Components​

src/components/dashboard/RealtimeMetricsWidget.jsx​

Lines with hardcoded units:

  • Line 76: {pressure?.average ? \${pressure.average.toFixed(1)}` : 'N/A'} psi`
  • Line 94: {flow?.average ? \${flow.average.toFixed(0)}` : 'N/A'} gpm`
  • Line 154: Inactive: {pumps?.inactiveCount || 'N/A'} | Flow: {pumps?.totalFlow?.toFixed(0) || 'N/A'} gpm

Action Required: Replace hardcoded "psi" and "gpm" with dynamic units from UnitsContext

src/components/dashboard/SystemSummaryWidget.jsx​

Lines with hardcoded units:

  • Line 78: {demandTrends?.current ? fShortenNumber(demandTrends.current) : 'N/A'} gpm
  • Line 93: {demandTrends?.peak ? fShortenNumber(demandTrends.peak) : 'N/A'} gpm

Action Required: Replace hardcoded "gpm" with dynamic units from UnitsContext

src/components/dashboard/QualityMetricsWidget.jsx​

Lines with hardcoded units:

  • Line 75: {chlorine?.average ? \${chlorine.average.toFixed(2)}` : 'N/A'} mg/L`
  • Line 93: {waterAge?.average ? \${waterAge.average.toFixed(1)}` : 'N/A'} hrs`

Action Required: Replace hardcoded "mg/L" and "hrs" with dynamic units from UnitsContext

2. Constants File​

src/constants.jsx​

Lines with unit-related constants:

  • Lines 180-184: Metric constants (CHLORINE, TR1, CONDUCTIVITY, THM, AGE)
  • Lines 186-198: Hydraulic constants (HEAD, FLOW, PRESSURE, LEVEL, etc.)
  • Lines 191, 198: Leakage constants (LEAKAGE_FLOW, LEAKAGE)
  • Lines 195, 197: Other constants (HEADLOSS, VELOCITY)

Action Required: These are constant definitions, not hardcoded units. No changes needed here.

3. Utility Files​

src/utils/formatChartLabel.jsx​

Lines with unit references:

  • Line 3: Comment mentions "GAL" as example
  • Line 4: Comment mentions "Tank Volume (GAL)" as example

Action Required: Update comments to use dynamic units or make the function accept units parameter

4. Map Utilities​

src/map_utils/esri/ScadaAssets3DLayer.jsx​

Lines with unit references:

  • Line 40: z: asset.elevation * 0.3048 || 0 // Convert feet to meters, default to 0 if not provided

Action Required: This is a conversion comment, not a display unit. No changes needed.

Units Not Found in Codebase​

The following units from the search list were NOT found in the codebase:

  • status: "OPEN/CLOSED" - No hardcoded references found
  • power: "kW" - No hardcoded references found
  • velocity: "FT/SEC" - No hardcoded references found
  • setting: "N/A" - No hardcoded references found
  • head: "FEET" - No hardcoded references found
  • level: "FEET" - No hardcoded references found
  • tankVolume: "GAL" - No hardcoded references found
  • leakageFlow: "GPM" - No hardcoded references found
  • AGE: "HOURS" - No hardcoded references found
  • TR1: "N/A" - No hardcoded references found
  • TR2: "N/A" - No hardcoded references found
  • CONDUCTIVITY: "S" - No hardcoded references found
  • THM: "UG/L" - No hardcoded references found

Priority Update List​

High Priority (User-facing displays)​

  1. src/components/dashboard/RealtimeMetricsWidget.jsx

    • Replace "psi" with dynamic pressure unit
    • Replace "gpm" with dynamic flow unit
  2. src/components/dashboard/SystemSummaryWidget.jsx

    • Replace "gpm" with dynamic demand unit
  3. src/components/dashboard/QualityMetricsWidget.jsx

    • Replace "mg/L" with dynamic chlorine unit
    • Replace "hrs" with dynamic age unit

Medium Priority (Utility functions)​

  1. src/utils/formatChartLabel.jsx
    • Update to accept units parameter or use UnitsContext

Low Priority (Comments/documentation)​

  1. src/map_utils/esri/ScadaAssets3DLayer.jsx
    • Update conversion comment if needed

Implementation Strategy​

  1. Update Dashboard Components First

    • These are the most visible to users
    • Use useUnits() hook to get dynamic units
    • Replace hardcoded strings with getUnit(metric) calls
  2. Update Utility Functions

    • Modify formatChartLabel.jsx to accept units parameter
    • Or integrate UnitsContext directly
  3. Test and Validate

    • Ensure all unit displays are working correctly
    • Verify fallback behavior when units are not available

Example Implementation​

// Before
{pressure?.average ? `${pressure.average.toFixed(1)}` : 'N/A'} psi

// After
const { getUnit } = useUnits();
{pressure?.average ? `${pressure.average.toFixed(1)}` : 'N/A'} {getUnit('pressure') || 'PSI'}

Notes​

  • Most unit references are in dashboard components
  • Constants file contains metric definitions, not display units
  • Some units may be handled by the backend API
  • Consider adding fallback units for when UnitsContext is not available