|
|
|
@ -511,3 +511,147 @@ exports.consumption = async (req, reply) => {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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==="horizontalcylinder"){
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, capacity: capacity});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(shape==="verticalcylinder"){
|
|
|
|
|
console.log("hii2")
|
|
|
|
|
const { height,diameter } = req.body
|
|
|
|
|
|
|
|
|
|
// Ensure all parameters are valid numbers
|
|
|
|
|
if (isNaN(height) || 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) * height
|
|
|
|
|
const capacity = volume * 1000
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, capacity: capacity});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if(shape==="horizontaloval"){
|
|
|
|
|
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, '$&,')
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, capacity: formattedCapacity});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(shape=== "verticaloval"){
|
|
|
|
|
console.log("hii4")
|
|
|
|
|
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 = width / 2
|
|
|
|
|
const a = height - width
|
|
|
|
|
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});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { message: 'success' };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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 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' };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|