diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index d25c4179..c76acc90 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -158,11 +158,12 @@ exports.updateTanklevels = async (req, reply) => { for (const tank of tanks) { const tankId = tank._id; + const tank_name = tank.tankName let capacity = parseInt(tank.capacity.replace(/,/g, ''), 10); let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); const intervalId = setInterval(async function () { - const newWaterLevel = Math.floor(waterLevel - 200); + const newWaterLevel = Math.floor(waterLevel - 200); if (newWaterLevel <= 0) { clearInterval(intervals[tankId]); @@ -174,6 +175,7 @@ exports.updateTanklevels = async (req, reply) => { { _id: tankId }, { $set: { waterlevel: newWaterLevel } } ); + console.log(tank_name+"="+newWaterLevel) } // console.log(result); @@ -357,9 +359,10 @@ exports.motorAction = async (req, reply) => { // Update water levels in database receiver_waterlevel = newWaterLevel; - console.log(receiver_tank+""+newWaterLevel+""+"bore to sump") + //console.log((newWaterLevel/receiver_capacity)*100,"4",receiver_tank_info.tankName) await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } }) + console.log(receiver_tank+"="+newWaterLevel+"="+"bore to sump") } }, 2000); @@ -497,54 +500,56 @@ exports.calculateCapacity = async (req, reply) => { } - if(shape==="oval"){ - console.log("hii3") - const { length, width, height } = req.body - - // Ensure all parameters are valid numbers - if (isNaN(length) || isNaN(width) || isNaN(height)) { - reply.code(400).send('Invalid input parameters') - return - } +// if(shape==="oval"){ +// console.log("hii3") +// const { length, width, height } = req.body + +// // Ensure all parameters are valid numbers +// if (isNaN(length) || isNaN(width) || isNaN(height)) { +// reply.code(400).send('Invalid input parameters') +// return +// } - // Calculate the capacity of the water tank in liters - const radius = height / 2 - const a = width - height - const area = Math.PI * radius * radius + 2 * radius * a - const volume = area * length - const capacity = volume * 1000 - - // Format the result with two decimal places and comma-separated thousands - const formattedCapacity = capacity.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') +// // Calculate the capacity of the water tank in liters +// const radius = height / 2 +// const a = width - height +// const area = Math.PI * radius * radius + 2 * radius * a +// const volume = area * length +// const capacity = volume * 1000 + +// // Format the result with two decimal places and comma-separated thousands +// const formattedCapacity = capacity.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') - reply.send({ status_code: 200, capacity: formattedCapacity}); +// reply.send({ status_code: 200, capacity: formattedCapacity}); - return { message: 'success' }; +// return { message: 'success' }; -} +// } -if(shape==="horizontalellipse"){ - const { length, width, height } = req.body +// if(shape==="horizontalellipse"){ - // Ensure all parameters are valid numbers - if (isNaN(length) || isNaN(width) || isNaN(height)) { - reply.code(400).send('Invalid input parameters') - return - } - // Calculate the capacity of the water tank in liters - const radius1 = length / 2 - const radius2 = width / 2 - const volume = Math.PI * radius1 * radius2 * height - const capacity = volume * 1000 - reply.send({ status_code: 200, capacity: capacity}); +// const { length, width, height } = req.body +// // Ensure all parameters are valid numbers +// if (isNaN(length) || isNaN(width) || isNaN(height)) { +// reply.code(400).send('Invalid input parameters') +// return +// } - return { message: 'success' }; +// // Calculate the capacity of the water tank in liters +// const radius1 = length / 2 +// const radius2 = width / 2 +// const volume = Math.PI * radius1 * radius2 * height +// const capacity = volume * 1000 +// reply.send({ status_code: 200, capacity: capacity}); -} + +// return { message: 'success' }; + +// } if(shape==="userdefined"){ const capacity = req.body