|
|
|
@ -7446,3 +7446,76 @@ exports.notificationTiming = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
return reply.send({ message: "Preference updated successfully" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.adjustMeasurement = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { tankName, 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 originalHeight = parseFloat(tank.height); // Example: 5.8 feet
|
|
|
|
|
const waterCapacityPerCm = parseFloat(tank.waterCapacityPerCm); // Example: 87 L/cm
|
|
|
|
|
const actualWaterLevel = parseFloat(tank.waterlevel); // Current water level in tank (liters)
|
|
|
|
|
const capacity = parseFloat(tank.capacity.replace(/,/g, ""));
|
|
|
|
|
|
|
|
|
|
console.log("originalHeight",originalHeight)
|
|
|
|
|
console.log("waterCapacityPerCm",waterCapacityPerCm)
|
|
|
|
|
console.log("actualWaterLevel",actualWaterLevel)
|
|
|
|
|
console.log("capacity",capacity)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Perform calculations
|
|
|
|
|
const heightDifference = originalHeight - measuredHeight;
|
|
|
|
|
const heightDifferenceInCm = heightDifference * 30.48; // Convert feet to cm
|
|
|
|
|
const calculatedWaterLevel = heightDifferenceInCm * waterCapacityPerCm; // Estimated water level in liters
|
|
|
|
|
|
|
|
|
|
console.log("heightDifference",heightDifference)
|
|
|
|
|
console.log("heightDifferenceInCm",heightDifferenceInCm)
|
|
|
|
|
console.log("calculatedWaterLevel",calculatedWaterLevel)
|
|
|
|
|
|
|
|
|
|
// **Ensure actualWaterLevel and calculatedWaterLevel do not exceed tank capacity**
|
|
|
|
|
const boundedActualWaterLevel = Math.min(actualWaterLevel, capacity);
|
|
|
|
|
const boundedCalculatedWaterLevel = Math.min(calculatedWaterLevel, capacity);
|
|
|
|
|
|
|
|
|
|
console.log("boundedActualWaterLevel",boundedActualWaterLevel)
|
|
|
|
|
console.log("boundedCalculatedWaterLevel",boundedCalculatedWaterLevel)
|
|
|
|
|
|
|
|
|
|
// Calculate original and calculated percentages correctly
|
|
|
|
|
const originalPercentage = (boundedActualWaterLevel / capacity) * 100;
|
|
|
|
|
const calculatedPercentage = (boundedCalculatedWaterLevel / capacity) * 100;
|
|
|
|
|
|
|
|
|
|
// Calculate percentage difference
|
|
|
|
|
const percentageDifference = Math.abs(originalPercentage - calculatedPercentage);
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: {
|
|
|
|
|
tankName,
|
|
|
|
|
originalHeight,
|
|
|
|
|
measuredHeight,
|
|
|
|
|
heightDifference: heightDifference.toFixed(2),
|
|
|
|
|
heightDifferenceInCm: heightDifferenceInCm.toFixed(2),
|
|
|
|
|
calculatedWaterLevel: calculatedWaterLevel.toFixed(2),
|
|
|
|
|
actualWaterLevel: actualWaterLevel.toFixed(2),
|
|
|
|
|
originalPercentage: originalPercentage.toFixed(2) + "%",
|
|
|
|
|
calculatedPercentage: calculatedPercentage.toFixed(2) + "%",
|
|
|
|
|
percentageDifference: percentageDifference.toFixed(2) + "%",
|
|
|
|
|
message: "Calculation completed. No updates were made."
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
reply.status(500).send({ message: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|