using co2 for the bin activity along with cables
This commit is contained in:
parent
ee8f34dcc6
commit
41a17ded94
7 changed files with 274 additions and 101 deletions
|
|
@ -68,6 +68,7 @@ import { Controller } from "models/Controller";
|
|||
import TaskViewer from "tasks/TaskViewer";
|
||||
import ButtonGroup from "common/ButtonGroup";
|
||||
import BinTransactions from "bin/BinTransactions";
|
||||
import { CO2 } from "models/CO2";
|
||||
|
||||
interface TabPanelProps {
|
||||
children?: React.ReactNode;
|
||||
|
|
@ -192,7 +193,7 @@ export default function Bin(props: Props) {
|
|||
const [ambients, setAmbients] = useState<Ambient[]>([]);
|
||||
const [grainCables, setGrainCables] = useState<GrainCable[]>([]);
|
||||
const [pressures, setPressures] = useState<Pressure[]>([]);
|
||||
const [headspaceCO2, setHeadspaceCO2] = useState<Component[]>([]);
|
||||
const [headspaceCO2, setHeadspaceCO2] = useState<CO2[]>([]);
|
||||
const [heaters, setHeaters] = useState<Controller[]>([]);
|
||||
const [fans, setFans] = useState<Controller[]>([]);
|
||||
const [detail, setDetail] = useState<
|
||||
|
|
@ -210,63 +211,13 @@ export default function Bin(props: Props) {
|
|||
new Map<string, number>()
|
||||
);
|
||||
const [binPresets, setBinPresets] = useState<DevicePreset[]>([]);
|
||||
const [missedCableReadings, setMissedCableReadings] = useState(0);
|
||||
const [missedReadings, setMissedReadings] = useState(0);
|
||||
|
||||
const handleChange = (_event: React.ChangeEvent<{}>, newValue: number) => {
|
||||
setValue(newValue);
|
||||
};
|
||||
|
||||
// const StyledToggle = styled(ToggleButton)(() => ({
|
||||
// root: {
|
||||
// backgroundColor: "transparent",
|
||||
// overflow: "visible",
|
||||
// content: "content-box",
|
||||
// "&$selected": {
|
||||
// backgroundColor: "gold",
|
||||
// color: "black",
|
||||
// borderRadius: 24,
|
||||
// fontWeight: "bold"
|
||||
// },
|
||||
// "&$selected:hover": {
|
||||
// backgroundColor: "rgb(255, 255, 0)",
|
||||
// color: "black",
|
||||
// borderRadius: 24
|
||||
// }
|
||||
// },
|
||||
// selected: {}
|
||||
// }))
|
||||
|
||||
// const StyledToggleButtonGroup = styled(ToggleButtonGroup)(({ theme }: { theme: Theme }) => ({
|
||||
// grouped: {
|
||||
// margin: theme.spacing(-0.5),
|
||||
// border: "none",
|
||||
// padding: theme.spacing(1),
|
||||
// "&:not(:first-child):not(:last-child)": {
|
||||
// borderRadius: 24,
|
||||
// marginRight: theme.spacing(0.5),
|
||||
// marginLeft: theme.spacing(0.5)
|
||||
// },
|
||||
// "&:first-child": {
|
||||
// borderRadius: 24,
|
||||
// marginLeft: theme.spacing(0.25)
|
||||
// },
|
||||
// "&:last-child": {
|
||||
// borderRadius: 24,
|
||||
// marginRight: theme.spacing(0.25)
|
||||
// }
|
||||
// },
|
||||
// root: {
|
||||
// backgroundColor: darken(
|
||||
// theme.palette.background.paper,
|
||||
// getThemeType() === "light" ? 0.05 : 0.25
|
||||
// ),
|
||||
// borderRadius: 24,
|
||||
// content: "border-box"
|
||||
// }
|
||||
// }))
|
||||
|
||||
const load = useCallback(() => {
|
||||
console.log(loadRef.current)
|
||||
if (loadRef.current || user.id() === "") return;
|
||||
setBinLoading(true);
|
||||
loadRef.current = true;
|
||||
|
|
@ -365,9 +316,10 @@ export default function Bin(props: Props) {
|
|||
var fans: Controller[] = [];
|
||||
var heaters: Controller[] = [];
|
||||
var pressures: Pressure[] = [];
|
||||
var headspaceCo2: Component[] = [];
|
||||
var headspaceCo2: CO2[] = [];
|
||||
var mostMissed: number = 0;
|
||||
let now = moment();
|
||||
|
||||
components.forEach(comp => {
|
||||
let pref = preferences.get(comp.key());
|
||||
if (pref) {
|
||||
|
|
@ -396,7 +348,17 @@ export default function Bin(props: Props) {
|
|||
pressures.push(Pressure.create(comp));
|
||||
if (pref.type === pond.BinComponent.BIN_COMPONENT_HEADSPACE) {
|
||||
if (comp.type() === quack.ComponentType.COMPONENT_TYPE_CO2) {
|
||||
headspaceCo2.push(comp);
|
||||
//check if there are missed readings from the co2 and compare them to what we already had
|
||||
let coComp = CO2.create(comp)
|
||||
let lastRead = moment(coComp.lastReading);
|
||||
let elapsedMS = now.diff(lastRead);
|
||||
if (elapsedMS > coComp.settings.measurementPeriodMs) {
|
||||
let missedReadings = Math.floor(elapsedMS / coComp.settings.measurementPeriodMs);
|
||||
if (missedReadings > mostMissed) {
|
||||
mostMissed = missedReadings;
|
||||
}
|
||||
}
|
||||
headspaceCo2.push(coComp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -404,7 +366,7 @@ export default function Bin(props: Props) {
|
|||
}
|
||||
}
|
||||
});
|
||||
setMissedCableReadings(mostMissed);
|
||||
setMissedReadings(mostMissed);
|
||||
setPlenums(plenums);
|
||||
setGrainCables(grainCables);
|
||||
setPressures(pressures);
|
||||
|
|
@ -1098,9 +1060,37 @@ export default function Bin(props: Props) {
|
|||
};
|
||||
|
||||
const componentState = () => {
|
||||
const hasCables = grainCables.length > 0
|
||||
const hasCO2 = headspaceCO2.length > 0
|
||||
return (
|
||||
<Box display="flex" alignContent="center" alignItems="center">
|
||||
<Typography
|
||||
{hasCables || hasCO2 ?
|
||||
<React.Fragment>
|
||||
<Typography
|
||||
align="center"
|
||||
style={{
|
||||
marginRight: 10,
|
||||
fontWeight: 650,
|
||||
fontSize: 15,
|
||||
textAlign: "center",
|
||||
color: "black"
|
||||
}}>
|
||||
{missedReadings < 3
|
||||
? "Active"
|
||||
: missedReadings <= warningThreshold
|
||||
? "Missing"
|
||||
: "Inactive"}
|
||||
</Typography>
|
||||
{missedReadings < 3 ? (
|
||||
<CheckCircle style={{ color: "green" }} />
|
||||
) : missedReadings <= warningThreshold ? (
|
||||
<Warning style={{ color: "yellow" }} />
|
||||
) : (
|
||||
<Warning style={{ color: "red" }} />
|
||||
)}
|
||||
</React.Fragment>
|
||||
:
|
||||
<Typography
|
||||
align="center"
|
||||
style={{
|
||||
marginRight: 10,
|
||||
|
|
@ -1109,19 +1099,9 @@ export default function Bin(props: Props) {
|
|||
textAlign: "center",
|
||||
color: "black"
|
||||
}}>
|
||||
{missedCableReadings < 3
|
||||
? "Active"
|
||||
: missedCableReadings <= warningThreshold
|
||||
? "Missing"
|
||||
: "Inactive"}
|
||||
</Typography>
|
||||
{missedCableReadings < 3 ? (
|
||||
<CheckCircle style={{ color: "green" }} />
|
||||
) : missedCableReadings <= warningThreshold ? (
|
||||
<Warning style={{ color: "yellow" }} />
|
||||
) : (
|
||||
<Warning style={{ color: "red" }} />
|
||||
)}
|
||||
Unmonitored
|
||||
</Typography>
|
||||
}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue