passing multiple plenums and pressure to the visualizer and added a button to cycle them

This commit is contained in:
csawatzky 2025-11-05 15:07:34 -06:00
parent 2a8aeed510
commit 842f9bee6a
2 changed files with 66 additions and 17 deletions

View file

@ -48,6 +48,8 @@ import { useBinAPI } from "providers/pond/binAPI";
import BindaptIcon from "products/Bindapt/BindaptIcon"; import BindaptIcon from "products/Bindapt/BindaptIcon";
import { import {
AccessTime, AccessTime,
ArrowForward,
ArrowForwardIos,
CheckCircleOutline, CheckCircleOutline,
Error, Error,
InfoOutlined, InfoOutlined,
@ -172,16 +174,21 @@ interface GrainConditions {
emcTrend: number; emcTrend: number;
} }
interface CombinedPlenum {
tempHumidity?: Plenum,
pressure?: Pressure
}
interface Props { interface Props {
bin: Bin; bin: Bin;
loading: boolean; loading: boolean;
components: Map<string, Component>; components: Map<string, Component>;
componentDevices?: Map<string, number>; componentDevices?: Map<string, number>;
devices: Device[]; devices: Device[];
plenum?: Plenum; plenums?: Plenum[];
ambient?: Ambient; ambient?: Ambient;
cables?: GrainCable[]; cables?: GrainCable[];
pressure?: Pressure; pressures?: Pressure[];
interactions?: Interaction[]; interactions?: Interaction[];
//changeBinMode: (binMode: pond.BinMode) => boolean; //changeBinMode: (binMode: pond.BinMode) => boolean;
refresh: (showSnack?: boolean) => void; refresh: (showSnack?: boolean) => void;
@ -197,9 +204,9 @@ export default function BinVisualizer(props: Props) {
bin, bin,
//changeBinMode, //changeBinMode,
//changeGrainAmount, //changeGrainAmount,
plenum, plenums,
ambient, ambient,
pressure, pressures,
loading, loading,
cables, cables,
components, components,
@ -282,6 +289,10 @@ export default function BinVisualizer(props: Props) {
const [storageDate, setStorageDate] = useState(moment().format("YYYY-MM-DD")); const [storageDate, setStorageDate] = useState(moment().format("YYYY-MM-DD"));
const [storageTime, setStorageTime] = useState(moment().format("HH:mm")); const [storageTime, setStorageTime] = useState(moment().format("HH:mm"));
const [activePlenum, setActivePlenum] = useState<CombinedPlenum | undefined>()
const [activePlenumIndex, setActivePlenumIndex] = useState(0)
const [combinedPlenums, setCombinedPlenums] = useState<CombinedPlenum[]>([])
// const StyledToggle = styled(ToggleButton)(({ theme }: { theme: Theme }) => ({ // const StyledToggle = styled(ToggleButton)(({ theme }: { theme: Theme }) => ({
// root: { // root: {
// backgroundColor: "transparent", // backgroundColor: "transparent",
@ -335,6 +346,31 @@ export default function BinVisualizer(props: Props) {
setModeTime(moment(bin.status.lastModeChange)); setModeTime(moment(bin.status.lastModeChange));
}, [bin.status.lastModeChange]); }, [bin.status.lastModeChange]);
useEffect(()=>{
//match the plenums and pressures based on their location (address)
let combinedPlenums: CombinedPlenum[] = []
if (plenums) {
plenums.forEach(plenum => {
let newCombinedPlenum: CombinedPlenum = {
tempHumidity: plenum
}
if (pressures) {
pressures.forEach(pressure => {
if(plenum.location().address === pressure.location().address){
console.log("found match")
newCombinedPlenum.pressure = pressure
}
})
}
combinedPlenums.push(newCombinedPlenum)
})
}
if (combinedPlenums.length > 0){
setActivePlenum(combinedPlenums[0])
}
setCombinedPlenums(combinedPlenums)
},[plenums, pressures])
useEffect(() => { useEffect(() => {
setIsCustomInventory(bin.storage() !== pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN); setIsCustomInventory(bin.storage() !== pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN);
setStorageType(bin.storage()); setStorageType(bin.storage());
@ -418,7 +454,6 @@ export default function BinVisualizer(props: Props) {
//determine which node is the coldest so that the data displayed is for the same node //determine which node is the coldest so that the data displayed is for the same node
let lowTempIndex = let lowTempIndex =
filteredNodes.temps.indexOf(Math.min(...filteredNodes.temps)) === -1 ? 0 : filteredNodes.temps.indexOf(Math.min(...filteredNodes.temps)); filteredNodes.temps.indexOf(Math.min(...filteredNodes.temps)) === -1 ? 0 : filteredNodes.temps.indexOf(Math.min(...filteredNodes.temps));
console.log(lowTempIndex)
lowNodeConditions = { lowNodeConditions = {
tempC: filteredNodes.temps[lowTempIndex], tempC: filteredNodes.temps[lowTempIndex],
humidity: filteredNodes.humids[lowTempIndex], humidity: filteredNodes.humids[lowTempIndex],
@ -1094,14 +1129,28 @@ export default function BinVisualizer(props: Props) {
const plenumOverview = () => { const plenumOverview = () => {
return ( return (
<Box style={{ position: "absolute", bottom: 5, width: "100%" }}> <Box style={{ position: "absolute", bottom: 5, width: "100%" }}>
<Box display="flex" flexDirection="row" alignItems="center">
<Typography style={{ fontSize: isMobile ? "0.85rem" : "1.0rem", fontWeight: 650 }}> <Typography style={{ fontSize: isMobile ? "0.85rem" : "1.0rem", fontWeight: 650 }}>
Plenum Plenum {plenums && plenums?.length > 1 ? activePlenumIndex+1 : ""}
</Typography> </Typography>
{plenums && plenums.length > 1 &&
<IconButton size="small" onClick={()=>{
let newIndex = activePlenumIndex + 1
if(newIndex > combinedPlenums.length - 1){
newIndex = 0
}
setActivePlenum(combinedPlenums[newIndex])
setActivePlenumIndex(newIndex)
}}>
<ArrowForwardIos />
</IconButton>
}
</Box>
<Box <Box
className={classes.displayBoxBinLeft} className={classes.displayBoxBinLeft}
style={{ marginRight: isMobile ? -70 : -90 }} style={{ marginRight: isMobile ? -70 : -90 }}
position="relative"> position="relative">
{plenum ? ( {activePlenum?.tempHumidity ? (
<React.Fragment> <React.Fragment>
<Grid <Grid
container container
@ -1129,7 +1178,7 @@ export default function BinVisualizer(props: Props) {
fontWeight: 650, fontWeight: 650,
color: tempColour color: tempColour
}}> }}>
{plenum.getTempString(user.settings.temperatureUnit)} {activePlenum.tempHumidity.getTempString(user.settings.temperatureUnit)}
</Typography> </Typography>
</Grid> </Grid>
<Grid size={{ xs: 5 }}> <Grid size={{ xs: 5 }}>
@ -1141,7 +1190,7 @@ export default function BinVisualizer(props: Props) {
fontWeight: 650, fontWeight: 650,
color: humidColour color: humidColour
}}> }}>
{plenum.getHumidityString()} {activePlenum.tempHumidity.getHumidityString()}
</Typography> </Typography>
</Grid> </Grid>
</Grid> </Grid>
@ -1262,7 +1311,7 @@ export default function BinVisualizer(props: Props) {
style={{ height: isMobile ? 20 : 25, width: isMobile ? 20 : 25 }} style={{ height: isMobile ? 20 : 25, width: isMobile ? 20 : 25 }}
/> />
</Grid> </Grid>
{pressure ? ( {activePlenum?.pressure ? (
<React.Fragment> <React.Fragment>
<Grid size={{ xs: 5 }}> <Grid size={{ xs: 5 }}>
<Typography <Typography
@ -1273,7 +1322,7 @@ export default function BinVisualizer(props: Props) {
fontWeight: 650, fontWeight: 650,
color: pressColour color: pressColour
}}> }}>
{pressure.getPressureString(user.settings.pressureUnit)} {activePlenum.pressure.getPressureString(user.settings.pressureUnit)}
</Typography> </Typography>
</Grid> </Grid>
{/* <Grid item xs={5}> {/* <Grid item xs={5}>
@ -1600,7 +1649,7 @@ export default function BinVisualizer(props: Props) {
<Typography style={{ fontSize: isMobile ? "0.85rem" : "1.0rem", fontWeight: 650 }}> <Typography style={{ fontSize: isMobile ? "0.85rem" : "1.0rem", fontWeight: 650 }}>
Fan Performance Fan Performance
</Typography> </Typography>
{pressure && pressure.fanId === 0 && !bin.settings.fan?.type && bin.fanID() === 0 && ( {activePlenum?.pressure && activePlenum.pressure.fanId === 0 && !bin.settings.fan?.type && bin.fanID() === 0 && (
<Typography variant="subtitle2" color="textPrimary" style={{ fontWeight: 600 }}> <Typography variant="subtitle2" color="textPrimary" style={{ fontWeight: 600 }}>
No fans found to calculate CFM No fans found to calculate CFM
</Typography> </Typography>
@ -1642,8 +1691,8 @@ export default function BinVisualizer(props: Props) {
<Typography align="center" style={{ fontWeight: 650, color: emcColour }}> <Typography align="center" style={{ fontWeight: 650, color: emcColour }}>
{ExtractMoisture( {ExtractMoisture(
bin.grain(), bin.grain(),
plenum?.temperature ?? 0, activePlenum?.tempHumidity?.temperature ?? 0,
plenum?.humidity ?? 0 activePlenum?.tempHumidity?.humidity ?? 0
).toFixed(2)} ).toFixed(2)}
% %
</Typography> </Typography>
@ -2148,7 +2197,7 @@ export default function BinVisualizer(props: Props) {
</Grid> </Grid>
<Grid size={1.5} >{controls()}</Grid> <Grid size={1.5} >{controls()}</Grid>
</Grid> </Grid>
{plenum && pressure && fanPerformance()} {plenums && pressures && fanPerformance()}
{ambient && ambientDisplay()} {ambient && ambientDisplay()}
{(bin.status.fans.length > 0 || bin.status.heaters.length > 0) && controllerDisplay()} {(bin.status.fans.length > 0 || bin.status.heaters.length > 0) && controllerDisplay()}
{dryingEstimate()} {dryingEstimate()}

View file

@ -689,8 +689,8 @@ export default function Bin(props: Props) {
const overview = () => { const overview = () => {
return ( return (
<BinVisualizerV2 <BinVisualizerV2
plenum={plenums[0]} plenums={plenums}
pressure={pressures[0]} pressures={pressures}
ambient={ambients[0]} ambient={ambients[0]}
cables={grainCables} cables={grainCables}
bin={bin} bin={bin}