|
|
@ -7519,3 +7519,51 @@ exports.adjustMeasurement = async (req, reply) => {
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.validateTankHeight = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { tankhardwareId, hardwareId } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tankhardwareId || !hardwareId) {
|
|
|
|
|
|
|
|
return reply.status(400).send({ message: "Both tankhardwareId and hardwareId are required." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find tank details from tanksSchema
|
|
|
|
|
|
|
|
const tank = await Tank.findOne({ tankhardwareId, hardwareId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tank) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ message: "Tank not found with the given tankhardwareId and hardwareId." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find corresponding IoT data from IOttankSchema
|
|
|
|
|
|
|
|
const iotTank = await IotData.findOne({ hardwareId, "tanks.tankhardwareId": tankhardwareId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!iotTank) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ message: "IoT tank data not found for the given hardwareId and tankhardwareId." });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convert tank height from feet to cm
|
|
|
|
|
|
|
|
const heightInCm = parseFloat(tank.height) * 30.48;
|
|
|
|
|
|
|
|
const iotTankHeight = parseFloat(iotTank.tanks.find(t => t.tankhardwareId === tankhardwareId).tankHeight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Converted Tank Height (cm):", heightInCm);
|
|
|
|
|
|
|
|
console.log("IoT Tank Height (cm):", iotTankHeight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for extreme values
|
|
|
|
|
|
|
|
if (heightInCm < iotTankHeight) {
|
|
|
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
|
|
|
message: "Extreme high values detected! Tank height exceeds IoT data."
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
|
|
|
status_code: 200,
|
|
|
|
|
|
|
|
message: "Tank height is within the valid range."
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|