sensor details tank

master^2
Bhaskar 3 months ago
parent c39e448c8c
commit 996df9bc2e

@ -8270,7 +8270,7 @@ exports.compareMeasuredHeight = async (req, reply) => {
const { tankName, measuredHeight, tankHeight } = req.body;
if (!tankName || typeof measuredHeight !== 'number' || typeof tankHeight !== 'number') {
return reply.status(400).send({ message: "tankName, tankHeight and measuredHeight (all required, as integers)." });
return reply.status(400).send({ message: "tankName, tankHeight and measuredHeight are required and must be numbers." });
}
if (tankHeight <= 0 || measuredHeight < 0) {
@ -8287,7 +8287,14 @@ exports.compareMeasuredHeight = async (req, reply) => {
return reply.status(400).send({ message: "Invalid waterCapacityPerCm in tank data." });
}
// 🔹 Sensor data
// DB tank height (in feet → cm)
const tankHeightFeetFromDB = parseFloat(tank.height);
const tankHeightInCmFromDB = Math.round(tankHeightFeetFromDB * 30.48);
// tankHeight from body is already in cm
const tankHeightInCmFromBody = Math.round(tankHeight);
// 🔹 Sensor data (use DB tank height)
let sensorGapCm = null;
let sensorWaterLevelInCm = null;
let sensorWaterLevelLiters = null;
@ -8302,17 +8309,17 @@ exports.compareMeasuredHeight = async (req, reply) => {
t => t.tankhardwareId === tank.tankhardwareId
);
if (matchingTank) {
const tankHeightFromSensor = parseInt(matchingTank.tankHeight, 10);
const tankHeightFromSensor = parseFloat(matchingTank.tankHeight);
if (!isNaN(tankHeightFromSensor) && tankHeightFromSensor >= 0) {
sensorGapCm = tankHeightFromSensor;
sensorWaterLevelInCm = Math.max(0, tankHeight - sensorGapCm);
sensorGapCm = Math.round(tankHeightFromSensor);
sensorWaterLevelInCm = Math.max(0, tankHeightInCmFromDB - sensorGapCm);
sensorWaterLevelLiters = Math.round(sensorWaterLevelInCm * capacityPerCm);
}
}
}
// 🔹 Manual data
const manualWaterLevelInCm = measuredHeight;
// 🔹 Manual data (use tankHeight from body)
const manualWaterLevelInCm = Math.round(measuredHeight); // measuredHeight in cm
const manualWaterLevelLiters = Math.round(manualWaterLevelInCm * capacityPerCm);
// 🔹 Comparison
@ -8325,18 +8332,16 @@ exports.compareMeasuredHeight = async (req, reply) => {
status_code: 200,
data: {
tankName,
tankHeightInCm: tankHeight,
capacity: tank.capacity,
sensor: {
tankHeightInCm: tankHeight,
sensorGapCm: sensorGapCm ?? null,
waterLevelInCm: sensorWaterLevelInCm ?? null,
waterLevelLiters: sensorWaterLevelLiters ?? null
tankHeightInCm: tankHeightInCmFromDB, // from DB
sensorGapCm,
waterLevelInCm: sensorWaterLevelInCm,
waterLevelLiters: sensorWaterLevelLiters
},
manual: {
tankHeightInCm: tankHeight,
//measuredHeightCm: measuredHeight,
waterLevelInCm: manualWaterLevelInCm,
tankHeightInCm: tankHeightInCmFromBody, // passed in body
measuredHeightCm: manualWaterLevelInCm,
waterLevelLiters: manualWaterLevelLiters
},
comparison: {
@ -8354,6 +8359,8 @@ exports.compareMeasuredHeight = async (req, reply) => {
//const ExcelJS = require('exceljs');
//const IotData = require('../models/IotData'); // adjust the path

Loading…
Cancel
Save