From 52c8a02af3f8fe33594b1c9d6f0eb7032b11c65e Mon Sep 17 00:00:00 2001 From: csawatzky Date: Wed, 1 Apr 2026 10:42:16 -0600 Subject: [PATCH] with changing unit preferences and such to use the user object and not local storage, the decriber needed to be updated as well and i missed that part, so now describeMeasurement takes in an optional user and uses its settings for the unit and such and when not passed in will use the defaults --- src/bin/BinConditioningInteraction.tsx | 22 +++++++++---------- src/bin/GrainNodeInteractions.tsx | 21 +++++++++++++++--- src/bin/conditioning/modeChangeDialog.tsx | 16 ++++++++++---- src/charts/MeasurementsChart.tsx | 8 ++++--- src/component/ComponentForm.tsx | 18 ++++++++++----- src/component/ExportDataSettings.tsx | 6 +++-- src/gate/GateGraphs.tsx | 4 ++-- src/interactions/InteractionSettings.tsx | 12 ++++++---- src/interactions/InteractionsOverview.tsx | 8 +++---- src/models/CO2.ts | 2 -- src/models/UnitMeasurement.ts | 2 +- src/objects/objectInteractions/Alerts.tsx | 4 +++- src/objects/objectInteractions/Controls.tsx | 4 +++- .../NewObjectInteraction.tsx | 8 ++++--- src/pages/Bins.tsx | 6 ++++- src/pbHelpers/ComponentType.tsx | 20 +++++++++++++---- src/pbHelpers/Interaction.ts | 7 +++--- src/pbHelpers/MeasurementDescriber.ts | 5 +++-- 18 files changed, 117 insertions(+), 56 deletions(-) diff --git a/src/bin/BinConditioningInteraction.tsx b/src/bin/BinConditioningInteraction.tsx index 0a7e694..d729462 100644 --- a/src/bin/BinConditioningInteraction.tsx +++ b/src/bin/BinConditioningInteraction.tsx @@ -103,7 +103,7 @@ export default function BinConditioningInteraction(props: Props) { let sliderVals: Map = new Map(); let sliderMarks: Map = new Map(); passedInteraction.conditions().forEach(condition => { - let describer = describeMeasurement(condition.measurementType, source.type()); + let describer = describeMeasurement(condition.measurementType, source.type(), undefined, undefined, user); //NOTE: toDisplay will convert the temp value to fahrenheit sliderVals.set(condition.measurementType, describer.toDisplay(condition.value)); }); @@ -173,17 +173,17 @@ export default function BinConditioningInteraction(props: Props) { return ( {interaction.conditions().map((condition, i) => { - let describer = describeMeasurement(condition.measurementType, source?.type()); - let labelTail = ""; + let describer = describeMeasurement(condition.measurementType, source?.type(), source.subType(), undefined, user); + let labelTail = describer.unit(); let marks: Mark[] = []; - if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) { - if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { - labelTail = "°F"; - } else { - labelTail = "°C"; - } - } + // if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) { + // if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { + // labelTail = "°F"; + // } else { + // labelTail = "°C"; + // } + // } if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_PERCENT) { labelTail = "%"; } @@ -198,7 +198,7 @@ export default function BinConditioningInteraction(props: Props) { return ( - {interactionConditionText(source, condition, false)} + {interactionConditionText(source, condition, false, user)} (); const [nodeMoist, setNodeMoist] = useState(); const [{ user, as }] = useGlobalState(); - const tempDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE); - const humDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_PERCENT); - const moistureDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_GRAIN_EMC); + const tempDescriber = describeMeasurement( + quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE, + quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, + undefined, + undefined, + user); + const humDescriber = describeMeasurement( + quack.MeasurementType.MEASUREMENT_TYPE_PERCENT, + quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, + undefined, + undefined, + user); + const moistureDescriber = describeMeasurement( + quack.MeasurementType.MEASUREMENT_TYPE_GRAIN_EMC, + quack.ComponentType.COMPONENT_TYPE_GRAIN_CABLE, + undefined, + undefined, + user); const [topNode, setTopNode] = useState(false); const [excluded, setExcluded] = useState(false); const componentAPI = useComponentAPI(); diff --git a/src/bin/conditioning/modeChangeDialog.tsx b/src/bin/conditioning/modeChangeDialog.tsx index cc17448..ef2dfbd 100644 --- a/src/bin/conditioning/modeChangeDialog.tsx +++ b/src/bin/conditioning/modeChangeDialog.tsx @@ -288,7 +288,9 @@ if (!selectedDevice) return; describeMeasurement( quack.MeasurementType.MEASUREMENT_TYPE_PERCENT, sensor.settings.type, - sensor.settings.subtype + sensor.settings.subtype, + undefined, + user ).toStored(hum) ) }); @@ -301,7 +303,9 @@ if (!selectedDevice) return; let tempVal = describeMeasurement( quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE, sensor.settings.type, - sensor.settings.subtype + sensor.settings.subtype, + undefined, + user ).toStored(temp); let tempCondition = pond.InteractionCondition.create({ @@ -385,7 +389,9 @@ if (!selectedDevice) return; value: describeMeasurement( quack.MeasurementType.MEASUREMENT_TYPE_PERCENT, sensor.settings.type, - sensor.settings.subtype + sensor.settings.subtype, + undefined, + user ).toStored(humidityPreset) }); conditions.push(fanConditionOne); @@ -397,7 +403,9 @@ if (!selectedDevice) return; let tempVal = describeMeasurement( quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE, sensor.settings.type, - sensor.settings.subtype + sensor.settings.subtype, + undefined, + user ).toStored(tempPreset); let fanConditionTwo = pond.InteractionCondition.create({ diff --git a/src/charts/MeasurementsChart.tsx b/src/charts/MeasurementsChart.tsx index 1baeea6..c4a5d8b 100644 --- a/src/charts/MeasurementsChart.tsx +++ b/src/charts/MeasurementsChart.tsx @@ -67,7 +67,7 @@ export default function MeasurementsChart(props: Props) { const [currentMax, setCurrentMax] = useState("dataMax"); const [newChart, setNewChart] = useState(false); const [xDomain, setXDomain] = useState(["dataMin", "dataMax"]); - const [{ showErrors }, dispatch] = useGlobalState(); + const [{ showErrors, user }, dispatch] = useGlobalState(); const isMobile = useMobile(); // const [zoomStart, setZoomStart] = useState(); // const [zoomEnd, setZoomEnd] = useState(); @@ -123,7 +123,7 @@ export default function MeasurementsChart(props: Props) { if (filters?.selectedInteractions?.includes(interaction.key())) { interaction.settings.conditions.forEach((condition, j) => { if (condition.measurementType === measurementType) { - let describer = describeMeasurement(condition.measurementType); + let describer = describeMeasurement(condition.measurementType, undefined, undefined, undefined, user); selectedInteractions.push( ) @@ -823,7 +831,7 @@ export default function ComponentForm(props: Props) { const describeSource = (measurementType: quack.MeasurementType): MeasurementDescriber => { const { component } = form; - return describeMeasurement(measurementType, component.type(), component.subType()); + return describeMeasurement(measurementType, component.type(), component.subType(), undefined, user); }; const availableMeasurementTypes = (type: quack.ComponentType): quack.MeasurementType[] => { diff --git a/src/component/ExportDataSettings.tsx b/src/component/ExportDataSettings.tsx index 0a310ba..a17cdc0 100644 --- a/src/component/ExportDataSettings.tsx +++ b/src/component/ExportDataSettings.tsx @@ -210,7 +210,7 @@ class ExportDataSettings extends React.Component { // } formatMeasurements(measurements: Array): Promise> { - const { device, component } = this.props; + const { device, component, user } = this.props; return new Promise(function(resolve, reject) { if (!measurements) reject("Invalid measurements"); @@ -237,7 +237,9 @@ class ExportDataSettings extends React.Component { let unit = describeMeasurement( componentMeasurement.measurementType, component.settings.type, - component.settings.subtype + component.settings.subtype, + undefined, + user ).unit(); let key = componentMeasurement.label + " (" + unit + ")"; row[key] = componentMeasurement.extract(measurement.measurement); diff --git a/src/gate/GateGraphs.tsx b/src/gate/GateGraphs.tsx index b2ec455..5a3a039 100644 --- a/src/gate/GateGraphs.tsx +++ b/src/gate/GateGraphs.tsx @@ -282,13 +282,13 @@ export default function GateGraphs(props: Props) { if (um.values[0] && um.values[0].values.length > 1) { return areaGraph( um, - describeMeasurement(um.type, component.type(), component.subType()), + describeMeasurement(um.type, component.type(), component.subType(), undefined, user), component.settings.smoothingAverages ); } else { return lineGraph( um, - describeMeasurement(um.type, component.type(), component.subType()), + describeMeasurement(um.type, component.type(), component.subType(), undefined, user), component.settings.smoothingAverages ); } diff --git a/src/interactions/InteractionSettings.tsx b/src/interactions/InteractionSettings.tsx index 87bdf98..4f2a2d3 100644 --- a/src/interactions/InteractionSettings.tsx +++ b/src/interactions/InteractionSettings.tsx @@ -195,7 +195,9 @@ export default function InteractionSettings(props: Props) { let value = describeMeasurement( condition.measurementType, or(initialComponent, Component.create()).settings.type, - or(initialComponent, Component.create()).settings.subtype + or(initialComponent, Component.create()).settings.subtype, + undefined, + user ).toDisplay(condition.value); rawConditionValues.push(value.toString()); }); @@ -425,7 +427,7 @@ export default function InteractionSettings(props: Props) { mappedComponents.get(componentIDToString(interaction.settings.source)), Component.create() ); - return describeMeasurement(measurementType, source.settings.type, source.settings.subtype); + return describeMeasurement(measurementType, source.settings.type, source.settings.subtype, undefined, user); }; const describeSink = (): MeasurementDescriber => { @@ -433,7 +435,9 @@ export default function InteractionSettings(props: Props) { return describeMeasurement( Measurement.boolean, or(sink, Component.create()).settings.type, - or(sink, Component.create()).settings.subtype + or(sink, Component.create()).settings.subtype, + undefined, + user ); }; @@ -861,7 +865,7 @@ export default function InteractionSettings(props: Props) { const conditionGroup = (index: number) => { if (index >= numConditions) return; let measurementType = interaction.settings.conditions[index].measurementType; - let source = describeSource(measurementType); + let source = describeSource(measurementType, ); let isBoolean = isBooleanValue(index); return ( diff --git a/src/interactions/InteractionsOverview.tsx b/src/interactions/InteractionsOverview.tsx index 127f2a6..600c88a 100644 --- a/src/interactions/InteractionsOverview.tsx +++ b/src/interactions/InteractionsOverview.tsx @@ -71,7 +71,7 @@ interface Props { export default function InteractionsOverview(props: Props) { const classes = useStyles(); - const [{as}] = useGlobalState(); + const [{as, user}] = useGlobalState(); const interactionsAPI = useInteractionsAPI(); const { success, error } = useSnackbar(); const { device, component, components, permissions, refreshCallback } = props; @@ -118,12 +118,12 @@ export default function InteractionsOverview(props: Props) { if (!conditions) return items; conditions.forEach((condition: pond.IInteractionCondition, conditionIndex: number) => { let measurementType = condition.measurementType; - let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype); + let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user); items.push( - {interactionConditionText(source, condition, conditionIndex > 0)} + {interactionConditionText(source, condition, conditionIndex > 0, user)} @@ -185,7 +185,7 @@ export default function InteractionsOverview(props: Props) { let condition = conditions[conditionIndex]; let sourceType = source && source.settings.type; let sourceSubtype = source && source.settings.subtype; - let describer = describeMeasurement(condition.measurementType, sourceType, sourceSubtype); + let describer = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user); condition.value = describer.toStored(value); updatedDirtyInteractions.set(interactionIndex, true); } diff --git a/src/models/CO2.ts b/src/models/CO2.ts index 62e5d73..fcb1ed5 100644 --- a/src/models/CO2.ts +++ b/src/models/CO2.ts @@ -3,8 +3,6 @@ import { quack } from "protobuf-ts/pond"; import { or } from "utils/types"; import { clone, cloneDeep } from "lodash"; import { Component } from "models"; -import { describeMeasurement } from "pbHelpers/MeasurementDescriber"; -import { extractGrainCable } from "pbHelpers/ComponentTypes"; export class CO2 { public settings: pond.ComponentSettings = pond.ComponentSettings.create(); diff --git a/src/models/UnitMeasurement.ts b/src/models/UnitMeasurement.ts index d33c17d..9fc3a42 100644 --- a/src/models/UnitMeasurement.ts +++ b/src/models/UnitMeasurement.ts @@ -32,7 +32,7 @@ export class UnitMeasurement { public static create(pb?: pond.UnitMeasurementsForComponent, user?: User): UnitMeasurement { let my = new UnitMeasurement(); if (pb) { - let describer = describeMeasurement(pb.type, pb.componentType); + let describer = describeMeasurement(pb.type, pb.componentType, undefined, undefined, user); let values = pb.values; if (user) { values = unitConversion(pb.values, pb.type, user); diff --git a/src/objects/objectInteractions/Alerts.tsx b/src/objects/objectInteractions/Alerts.tsx index 8546363..01f5bec 100644 --- a/src/objects/objectInteractions/Alerts.tsx +++ b/src/objects/objectInteractions/Alerts.tsx @@ -6,6 +6,7 @@ import { pond, quack } from "protobuf-ts/pond"; import React, { useState } from "react"; import NewObjectInteraction from "./NewObjectInteraction"; import { Option } from "common/SearchSelect"; +import { useGlobalState } from "providers"; export interface Alert { conditions: pond.InteractionCondition[]; @@ -20,10 +21,11 @@ interface Props { export default function Alerts(props: Props){ const {alerts, addNew, permissions} = props + const [{user}] = useGlobalState(); // const [openNewAlert, setOpenNewAlert] = useState(false) const readableCondition = (condition: pond.InteractionCondition) => { - let describer = describeMeasurement(condition.measurementType); + let describer = describeMeasurement(condition.measurementType, undefined, undefined, undefined, user); let type = describer.label(); let comparison = condition.comparison === quack.RelationalOperator.RELATIONAL_OPERATOR_EQUAL_TO diff --git a/src/objects/objectInteractions/Controls.tsx b/src/objects/objectInteractions/Controls.tsx index 0346c87..6f3f817 100644 --- a/src/objects/objectInteractions/Controls.tsx +++ b/src/objects/objectInteractions/Controls.tsx @@ -4,6 +4,7 @@ import { Component, Device, Interaction } from "models"; import { interactionResultText } from "pbHelpers/Interaction"; import { describeMeasurement } from "pbHelpers/MeasurementDescriber"; import { pond, quack } from "protobuf-ts/pond"; +import { useGlobalState } from "providers"; import React, { useEffect, useState } from "react"; export interface Control { @@ -23,6 +24,7 @@ interface Props { export default function Controls(props: Props){ const { devices, controls, addNew, permissions } = props + const [{user}] = useGlobalState(); const [deviceControls, setDeviceControls] = useState>(new Map()) const [openDeviceMenu, setOpenDeviceMenu] = useState(false) const [anchor, setAnchor] = useState(null) @@ -45,7 +47,7 @@ export default function Controls(props: Props){ let conditions: string = "" let firstSource = control.sourceComponents[0] control.conditions.forEach((condition, index) => { - let describer = describeMeasurement(condition.measurementType, firstSource.type(), firstSource.subType()); + let describer = describeMeasurement(condition.measurementType, firstSource.type(), firstSource.subType(), undefined, user); let type = describer.label(); let comparison = condition.comparison === quack.RelationalOperator.RELATIONAL_OPERATOR_EQUAL_TO diff --git a/src/objects/objectInteractions/NewObjectInteraction.tsx b/src/objects/objectInteractions/NewObjectInteraction.tsx index 64a63b0..40aed71 100644 --- a/src/objects/objectInteractions/NewObjectInteraction.tsx +++ b/src/objects/objectInteractions/NewObjectInteraction.tsx @@ -64,7 +64,7 @@ const useStyles = makeStyles((theme: Theme) => { export default function NewObjectInteraction(props: Props){ const { open, onClose, device, linkedComponents, componentDevices } = props const classes = useStyles() - const [{ as }] = useGlobalState(); + const [{ as, user }] = useGlobalState(); const {openSnack} = useSnackbar(); const interactionsAPI = useInteractionsAPI(); const [newAlertComponentType, setNewAlertComponentType] = useState( @@ -249,7 +249,7 @@ export default function NewObjectInteraction(props: Props){ const measurementTypeMenuItems = () => { return availableMeasurementTypes(newAlertComponentType).map(measurementType => ( - {describeMeasurement(measurementType).label()} + {describeMeasurement(measurementType, undefined, undefined, undefined, user).label()} )); }; @@ -531,7 +531,9 @@ export default function NewObjectInteraction(props: Props){ return describeMeasurement( Measurement.boolean, or(sink, Component.create()).settings.type, - or(sink, Component.create()).settings.subtype + or(sink, Component.create()).settings.subtype, + undefined, + user ); }; diff --git a/src/pages/Bins.tsx b/src/pages/Bins.tsx index ad30d23..7529f3f 100644 --- a/src/pages/Bins.tsx +++ b/src/pages/Bins.tsx @@ -569,7 +569,11 @@ export default function Bins(props: Props) { measurementType: quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE, comparison: quack.RelationalOperator.RELATIONAL_OPERATOR_GREATER_THAN, value: describeMeasurement( - quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE + quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE, + undefined, + undefined, + undefined, + user ).toStored(bin.settings.highTemp) }), componentLocation: quack.ComponentID.create({ diff --git a/src/pbHelpers/ComponentType.tsx b/src/pbHelpers/ComponentType.tsx index 03be638..047c852 100644 --- a/src/pbHelpers/ComponentType.tsx +++ b/src/pbHelpers/ComponentType.tsx @@ -236,16 +236,16 @@ export function unitMeasurementSummary( ): Summary { let vals: string[] = []; convertedMeasurement.values.forEach(val => { - vals.push(val + describer.unit()); + vals.push(val + convertedMeasurement.unit); }); let v = vals.join(", "); if (describer.enumerations().length > 0) { v = describer.enumerations()[parseFloat(vals[0])]; } return { - colour: describer.colour(), - label: describer.label(), - type: describer.type(), + colour: convertedMeasurement.colour, + label: convertedMeasurement.label, + type: convertedMeasurement.type, value: v, error: convertedMeasurement.error }; @@ -258,6 +258,8 @@ export function unitMeasurementSummaries( ): Summary[] { let summaries: Summary[] = []; measurements.measurementsFor.forEach(measurement => { + //the only reason the user doesnt need to be passed in here is because it is only used for enumerations, + //things like the unit and colour are in the measurement itself at this point let describer = describeMeasurement(measurement.type, compType, subtype); summaries.push(unitMeasurementSummary(measurement, describer)); }); @@ -530,6 +532,7 @@ export function simpleLineChartData( } }); } + console.log(lineData) return lineData; } @@ -945,6 +948,15 @@ function getOverlayAreas( return overlayAreas; } + +/** + * this function adds lines to victory graphs for interactions on the component + * DEPRECATED: we now use Recharts for our graphs + * @param componentType + * @param subtype + * @param interactionCondition + * @returns + */ function createInteractionLine( componentType: quack.ComponentType, subtype: number, diff --git a/src/pbHelpers/Interaction.ts b/src/pbHelpers/Interaction.ts index 5b91d00..f48bd73 100644 --- a/src/pbHelpers/Interaction.ts +++ b/src/pbHelpers/Interaction.ts @@ -1,4 +1,4 @@ -import { Interaction, Component } from "models"; +import { Interaction, Component, User } from "models"; import { pond } from "protobuf-ts/pond"; import { quack } from "protobuf-ts/quack"; import { or, notNull } from "utils/types"; @@ -172,7 +172,8 @@ export const interactionResultText = (interaction: Interaction, sink?: Component export const interactionConditionText = ( source: Component | undefined, condition: pond.IInteractionCondition, - and: boolean + and: boolean, + user?: User ) => { let comparison = "is exactly"; switch (condition.comparison) { @@ -189,7 +190,7 @@ export const interactionConditionText = ( if (!condition.measurementType) return "Unknown " + comparison + " " + condition.value; let sourceType = source && source.settings.type; let sourceSubtype = source && source.settings.subtype; - let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype); + let measurement = describeMeasurement(condition.measurementType, sourceType, sourceSubtype, undefined, user); return ( (and ? "and " : "") + measurement.label() + diff --git a/src/pbHelpers/MeasurementDescriber.ts b/src/pbHelpers/MeasurementDescriber.ts index 169a7d2..947c545 100644 --- a/src/pbHelpers/MeasurementDescriber.ts +++ b/src/pbHelpers/MeasurementDescriber.ts @@ -694,11 +694,12 @@ export function describeMeasurement( componentType: quack.ComponentType | null | undefined = quack.ComponentType .COMPONENT_TYPE_INVALID, componentSubtype: number = 0, - product?: pond.DeviceProduct + product?: pond.DeviceProduct, + user?: User ): MeasurementDescriber { measurementType = measurementType ? measurementType : quack.MeasurementType.MEASUREMENT_TYPE_INVALID; componentType = componentType ? componentType : quack.ComponentType.COMPONENT_TYPE_INVALID; - return new MeasurementDescriber(measurementType, componentType, componentSubtype, product); + return new MeasurementDescriber(measurementType, componentType, componentSubtype, product, user); }