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