changes on compare water level

master^2
Bhaskar 3 months ago
parent dc8f81994e
commit f470c2109e

@ -8293,6 +8293,8 @@ exports.compareMeasuredHeight = async (req, reply) => {
// tankHeight from body is already in cm
const tankHeightInCmFromBody = Math.round(tankHeight);
console.log("tankHeightInCmFromBody",tankHeightInCmFromBody)
console.log("tankHeightInCmFromDB",tankHeightInCmFromDB)
// 🔹 Sensor data (use DB tank height)
let sensorGapCm = null;
@ -8322,37 +8324,91 @@ exports.compareMeasuredHeight = async (req, reply) => {
}
// 🔹 Manual data (use tankHeight from body)
const manualWaterLevelInCm = Math.round(measuredHeight); // measuredHeight in cm
const manualWaterLevelLiters = Math.round(manualWaterLevelInCm * capacityPerCm);
// 🔹 Comparison
const heightDifferenceInCm = Math.abs(manualWaterLevelInCm - (sensorWaterLevelInCm ?? 0));
const comparisonMessage = heightDifferenceInCm <= 10
? "Manual measurement matches within 10 cm of sensor data."
: "Manual measurement not matched within range 10 cm.";
// const manualWaterLevelInCm = Math.round(measuredHeight); // measuredHeight in cm
// const manualWaterLevelLiters = Math.round(manualWaterLevelInCm * capacityPerCm);
// // 🔹 Comparison
// const heightDifferenceInCm = Math.abs(manualWaterLevelInCm - (sensorWaterLevelInCm ?? 0));
// const comparisonMessage = heightDifferenceInCm <= 10
// ? "Manual measurement matches within 10 cm of sensor data."
// : "Manual measurement not matched within range 10 cm.";
// reply.send({
// status_code: 200,
// data: {
// tankName,
// capacity: tank.capacity,
// sensor: {
// tankHeightInCm: dynamicTankHeightInCm, // from DB
// sensorGapCm,
// waterLevelInCm: sensorWaterLevelInCm,
// waterLevelLiters: sensorWaterLevelLiters
// },
// manual: {
// tankHeightInCm: tankHeightInCmFromBody, // passed in body
// measuredHeightCm: manualWaterLevelInCm,
// waterLevelLiters: manualWaterLevelLiters
// },
// comparison: {
// heightDifferenceInCm,
// message: comparisonMessage
// }
// }
// });
// 🔹 Manual data
// 🔹 Manual data
const manualWaterLevelInCm = Math.round(measuredHeight); // measuredHeight in cm
const manualWaterLevelLiters = Math.round(manualWaterLevelInCm * capacityPerCm);
// 🔹 Comparison
const waterLevelDifferenceInCm = Math.abs(manualWaterLevelInCm - (sensorWaterLevelInCm ?? 0));
const tankHeightDifferenceInCm = Math.abs(tankHeightInCmFromDB - (tankHeightInCmFromBody ?? 0 ));
// require *both* to be within 10cm
// const isWithinRange = waterLevelDifferenceInCm <= 10 && tankHeightDifferenceInCm <= 10;
// const comparisonMessage = isWithinRange
// ? "Manual measurement matches within 10 cm of sensor data and tank height."
// : "Manual measurement not matched within range 10 cm.";
const isWaterLevelMatch = waterLevelDifferenceInCm <= 10;
const isTankHeightMatch = tankHeightDifferenceInCm <= 10;
let comparisonMessage = "";
if (isWaterLevelMatch && isTankHeightMatch) {
comparisonMessage = "✅ Manual measurement matches: water level and tank height both within 10 cm range.";
} else if (isWaterLevelMatch) {
comparisonMessage = "✅ Manual water level matches within 10 cm, but tank height does not.";
} else if (isTankHeightMatch) {
comparisonMessage = "✅ Manual tank height matches within 10 cm, but water level does not.";
} else {
comparisonMessage = "❌ Manual measurement does not match within 10 cm range for either water level or tank height.";
}
reply.send({
status_code: 200,
data: {
tankName,
capacity: tank.capacity,
sensor: {
tankHeightInCm: dynamicTankHeightInCm, // from DB
sensorGapCm,
waterLevelInCm: sensorWaterLevelInCm,
waterLevelLiters: sensorWaterLevelLiters
},
manual: {
tankHeightInCm: tankHeightInCmFromBody, // passed in body
measuredHeightCm: manualWaterLevelInCm,
waterLevelLiters: manualWaterLevelLiters
},
comparison: {
heightDifferenceInCm,
message: comparisonMessage
}
}
});
reply.send({
status_code: 200,
data: {
tankName,
capacity: tank.capacity,
sensor: {
tankHeightInCm: dynamicTankHeightInCm, // from DB + IoT data
sensorGapCm,
waterLevelInCm: sensorWaterLevelInCm,
waterLevelLiters: sensorWaterLevelLiters
},
manual: {
tankHeightInCm: tankHeightInCmFromBody,
measuredHeightCm: manualWaterLevelInCm,
waterLevelLiters: manualWaterLevelLiters
},
comparison: {
waterLevelDifferenceInCm,
tankHeightDifferenceInCm,
message: comparisonMessage
}
}
});
} catch (err) {
console.error(err);

Loading…
Cancel
Save