|
|
|
@ -7520,3 +7520,94 @@ exports.validateTankHeight = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.getActualWaterLevelInCm = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { tankName } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!tankName) {
|
|
|
|
|
return reply.status(400).send({ message: "Tank name is required." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch tank details using tankName
|
|
|
|
|
const tank = await Tank.findOne({ tankName });
|
|
|
|
|
|
|
|
|
|
if (!tank) {
|
|
|
|
|
return reply.status(404).send({ message: "Tank not found." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const actualWaterLevel = parseFloat(tank.waterlevel); // Current water level in liters
|
|
|
|
|
const waterCapacityPerCm = parseFloat(tank.waterCapacityPerCm); // Liters per cm
|
|
|
|
|
|
|
|
|
|
if (!actualWaterLevel || !waterCapacityPerCm) {
|
|
|
|
|
return reply.status(400).send({ message: "Tank data is incomplete for conversion." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert actual water level from liters to cm
|
|
|
|
|
const actualWaterLevelInCm = actualWaterLevel / waterCapacityPerCm;
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: {
|
|
|
|
|
tankName,
|
|
|
|
|
actualWaterLevel: actualWaterLevel.toFixed(2) + " L",
|
|
|
|
|
actualWaterLevelInCm: actualWaterLevelInCm.toFixed(2) + " cm"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.compareMeasuredHeight = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { tankName } = req.params;
|
|
|
|
|
const { measuredHeight } = req.body;
|
|
|
|
|
|
|
|
|
|
if (!tankName || measuredHeight === undefined) {
|
|
|
|
|
return reply.status(400).send({ message: "Tank name and measured height are required." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch tank details using tankName
|
|
|
|
|
const tank = await Tank.findOne({ tankName });
|
|
|
|
|
|
|
|
|
|
if (!tank) {
|
|
|
|
|
return reply.status(404).send({ message: "Tank not found." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const actualWaterLevel = parseFloat(tank.waterlevel); // Current water level in liters
|
|
|
|
|
const waterCapacityPerCm = parseFloat(tank.waterCapacityPerCm); // Liters per cm
|
|
|
|
|
|
|
|
|
|
if (!actualWaterLevel || !waterCapacityPerCm) {
|
|
|
|
|
return reply.status(400).send({ message: "Tank data is incomplete for conversion." });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert actual water level from liters to cm
|
|
|
|
|
const actualWaterLevelInCm = actualWaterLevel / waterCapacityPerCm;
|
|
|
|
|
|
|
|
|
|
// Calculate difference between measured and actual water level in cm
|
|
|
|
|
const heightDifferenceInCm = Math.abs(actualWaterLevelInCm - measuredHeight);
|
|
|
|
|
|
|
|
|
|
let message;
|
|
|
|
|
if (heightDifferenceInCm <= 10) { // Within 10 cm is considered a match
|
|
|
|
|
message = "Measured height is within an acceptable range of actual water level.";
|
|
|
|
|
} else {
|
|
|
|
|
message = "Measured height differs significantly from actual water level.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: {
|
|
|
|
|
tankName,
|
|
|
|
|
measuredHeight: measuredHeight.toFixed(2) + " cm",
|
|
|
|
|
actualWaterLevelInCm: actualWaterLevelInCm.toFixed(2) + " cm",
|
|
|
|
|
heightDifferenceInCm: heightDifferenceInCm.toFixed(2) + " cm",
|
|
|
|
|
message
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|