made changes in tanks controller,added feets as measuring units in capacity calculation and decreased water consumption speed

master
varun 2 years ago
parent ed9f4aa4c6
commit 375cd5f387

@ -160,7 +160,7 @@ exports.updateTanklevels = async (req, reply) => {
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);
//let waterLevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
const intervalId = setInterval(async function () {
const tank_data = await Tank.findOne({ _id:tankId });
@ -259,7 +259,7 @@ exports.motorAction = async (req, reply) => {
// Calculate new water levels
const supplier_tank_info2 = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
const newWaterLevel = receiver_waterlevel + 350//Math.floor(supplier_waterlevel * 0.1);
const newWaterLevel = receiver_waterlevel + 250//Math.floor(supplier_waterlevel * 0.1);
const newSupplierWaterLevel = supplier_waterlevel//Math.floor(supplier_waterlevel * 0.1);
const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
console.log((newSupplierWaterLevel/supplier_capacity)*100)
@ -279,7 +279,7 @@ exports.motorAction = async (req, reply) => {
console.log(receiver_tank+""+newWaterLevel+""+"bore to sump")
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } })
if (supplier_tank_info2.motor_status==="0"){
supplier_waterlevel = parseInt(supplier_tank_info2.waterlevel.replace(/,/g, ''), 10)-350
supplier_waterlevel = parseInt(supplier_tank_info2.waterlevel.replace(/,/g, ''), 10)-250
console.log(supplier_tank+""+newSupplierWaterLevel+""+"s to oh")
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: supplier_waterlevel } })
}
@ -350,7 +350,7 @@ exports.motorAction = async (req, reply) => {
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
//console.log(rcvr_info)
//console.log(rcvr_info.motor_status)
const newWaterLevel = receiver_waterlevel+450;
const newWaterLevel = receiver_waterlevel+250;
//console.log(newWaterLevel,"2",receiver_tank_info.tankName)
// Check if updating should stop
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0" ) {
@ -461,117 +461,181 @@ exports.consumption = async (req, reply) => {
}
};
exports.calculateCapacity = async (req, reply) => {
try {
const shape = req.body.shape
if(shape==="rectangle"){
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
}
// exports.calculateCapacity = async (req, reply) => {
// try {
// const shape = req.body.shape
// if(shape==="rectangle"){
// const { length, width, height } = req.body
// Calculate the capacity of the water tank in liters
const capacity = length * width * height * 1000
// // Ensure all parameters are valid numbers
// if (isNaN(length) || isNaN(width) || isNaN(height)) {
// reply.code(400).send('Invalid input parameters')
// return
// }
reply.send({ status_code: 200, capacity: capacity});
// // Calculate the capacity of the water tank in liters
// const capacity = length * width * height * 1000
// reply.send({ status_code: 200, capacity: capacity});
return { message: 'success' };
}
if(shape==="cylinder"){
console.log("hii1")
const { length,diameter } = req.body
// Ensure all parameters are valid numbers
if (isNaN(length) || isNaN(diameter)) {
reply.code(400).send('Invalid input parameters')
return
}
// return { message: 'success' };
// Calculate the capacity of the water tank in liters
const radius = diameter / 2
const volume = Math.PI * Math.pow(radius, 2) * length
const capacity = volume * 1000
// }
// if(shape==="cylinder"){
// console.log("hii1")
// const { length,diameter } = req.body
reply.send({ status_code: 200, capacity: capacity});
// // Ensure all parameters are valid numbers
// if (isNaN(length) || isNaN(diameter)) {
// reply.code(400).send('Invalid input parameters')
// return
// }
// // Calculate the capacity of the water tank in liters
// const radius = diameter / 2
// const volume = Math.PI * Math.pow(radius, 2) * length
// const capacity = volume * 1000
return { message: 'success' };
// reply.send({ status_code: 200, capacity: capacity});
}
// if(shape==="oval"){
// console.log("hii3")
// const { length, width, height } = req.body
// return { message: 'success' };
// // 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
// // if(shape==="oval"){
// // console.log("hii3")
// // const { length, width, height } = req.body
// // Format the result with two decimal places and comma-separated thousands
// const formattedCapacity = capacity.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
// // // Ensure all parameters are valid numbers
// // if (isNaN(length) || isNaN(width) || isNaN(height)) {
// // reply.code(400).send('Invalid input parameters')
// // return
// // }
// reply.send({ status_code: 200, capacity: formattedCapacity});
// // // 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, '$&,')
// return { message: 'success' };
// // reply.send({ status_code: 200, capacity: formattedCapacity});
// }
// // 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
// // 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 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
// reply.send({ status_code: 200, capacity: capacity});
// return { message: 'success' };
// }
if(shape==="userdefined"){
const capacity = req.body
reply.send({ status_code: 200, capacity: capacity});
// }
return { message: 'success' };
// catch (err) {
// throw boom.boomify(err);
// }
// };
}
exports.calculateCapacity = async (req, reply) => {
try {
const shape = req.body.shape;
if (shape === "rectangle") {
const { length, width, height } = req.body;
// Convert input units from feet to meters
const length_m = length * 0.3048;
const width_m = width * 0.3048;
const height_m = height * 0.3048;
console.log(length_m,width_m,height_m)
// Ensure all parameters are valid numbers
if (isNaN(length_m) || isNaN(width_m) || isNaN(height_m)) {
reply.code(400).send("Invalid input parameters");
return;
}
// Calculate the capacity of the water tank in liters
const capacity = length_m * width_m * height_m * 1000;
reply.send({ status_code: 200, capacity: capacity });
return { message: "success" };
}
if (shape === "cylinder") {
console.log("hii1");
const { length, diameter } = req.body;
catch (err) {
// Convert input units from feet to meters
const length_m = length * 0.3048;
const diameter_m = diameter * 0.3048;
// Ensure all parameters are valid numbers
if (isNaN(length_m) || isNaN(diameter_m)) {
reply.code(400).send("Invalid input parameters");
return;
}
// Calculate the capacity of the water tank in liters
const radius = diameter_m / 2;
const volume = Math.PI * Math.pow(radius, 2) * length_m;
const capacity = volume * 1000;
reply.send({ status_code: 200, capacity: capacity });
return { message: "success" };
}
// Add similar conversions for other shapes if necessary
if (shape === "userdefined") {
const capacity = req.body;
reply.send({ status_code: 200, capacity: capacity });
return { message: "success" };
}
} catch (err) {
throw boom.boomify(err);
}
};
exports.IotDevice = async (req, reply) => {
try {
const { hardwareId, tankHeight, maxLevel, minLevel, mode } = req.body;

Loading…
Cancel
Save