|
|
|
@ -258,7 +258,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const action = req.body.action
|
|
|
|
|
const receiver_tank = req.body.to
|
|
|
|
|
const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank});
|
|
|
|
|
const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:req.body.to_type});
|
|
|
|
|
const receiver_capacity = receiver_tank_info.capacity
|
|
|
|
|
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
|
@ -272,24 +272,74 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
console.log(supplier_tank)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
|
console.log(supplier_tank_info1)
|
|
|
|
|
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: initial_update } });
|
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank,tankLocation:supplier_tank_type});
|
|
|
|
|
|
|
|
|
|
// await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
|
|
|
|
|
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
|
// Calculate new water levels
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
|
|
|
|
|
const newWaterLevel = receiver_waterlevel + 200//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
const newSupplierWaterLevel = supplier_waterlevel - 200//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
|
|
// Check if updating should stop
|
|
|
|
|
if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === 0) {
|
|
|
|
|
clearInterval(intervalId)
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
console.log("end");
|
|
|
|
|
} else {
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
supplier_waterlevel = newSupplierWaterLevel;
|
|
|
|
|
receiver_waterlevel = newWaterLevel;
|
|
|
|
|
console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
await Promise.all([
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: newSupplierWaterLevel } })
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
// // console.log(rcvr_info.motor_status)
|
|
|
|
|
// const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
// console.log(supplier_tank_info1)
|
|
|
|
|
// initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
|
|
|
|
|
// initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)/2;
|
|
|
|
|
|
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
|
|
|
|
|
// const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
|
|
|
|
|
// // await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
|
|
|
|
|
// let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
// let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
// intervalId = setInterval(async function () {
|
|
|
|
|
// const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank});
|
|
|
|
|
// const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
// // Calculate new water levels
|
|
|
|
|
// const newWaterLevel = receiver_waterlevel + 200//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
// const newSupplierWaterLevel = supplier_waterlevel - 200//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
// const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
// const newSupplierWaterLevel = Math.min(supplier_capacity, supplier_waterlevel + 350);// Math.floor(supplier_waterlevel * 0.15));
|
|
|
|
|
// // console.log(newWaterLevel)
|
|
|
|
|
// // console.log(newSupplierWaterLevel)
|
|
|
|
|
// // console.log(rcvr_info.motor_status)
|
|
|
|
|
// // console.log(rcvr_info.tankName)
|
|
|
|
|
|
|
|
|
|
// // Check if updating should stop
|
|
|
|
|
// if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage) {
|
|
|
|
|
// if ( (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === 0) {
|
|
|
|
|
|
|
|
|
|
// clearInterval(intervalId)
|
|
|
|
|
// await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
@ -298,8 +348,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
// // Update water levels in database
|
|
|
|
|
// supplier_waterlevel = newSupplierWaterLevel;
|
|
|
|
|
// receiver_waterlevel = newWaterLevel;
|
|
|
|
|
// console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
// console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
// // console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
// // console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
// await Promise.all([
|
|
|
|
|
// Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
// Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: newSupplierWaterLevel } })
|
|
|
|
@ -307,72 +357,25 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
// }
|
|
|
|
|
// }, 2000);
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "true" } });
|
|
|
|
|
|
|
|
|
|
// console.log(rcvr_info.motor_status)
|
|
|
|
|
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)/2;
|
|
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
|
|
|
|
|
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
|
|
|
|
|
|
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank});
|
|
|
|
|
const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
// Calculate new water levels
|
|
|
|
|
const newWaterLevel = receiver_waterlevel + 200//Math.floor(supplier_waterlevel * 0.1);
|
|
|
|
|
const newSupplierWaterLevel = Math.min(supplier_capacity, supplier_waterlevel + 350);// Math.floor(supplier_waterlevel * 0.15));
|
|
|
|
|
console.log(newWaterLevel)
|
|
|
|
|
console.log(newSupplierWaterLevel)
|
|
|
|
|
console.log(rcvr_info.motor_status)
|
|
|
|
|
console.log(rcvr_info.tankName)
|
|
|
|
|
|
|
|
|
|
// Check if updating should stop
|
|
|
|
|
if ( (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "false") {
|
|
|
|
|
|
|
|
|
|
clearInterval(intervalId)
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "false" } });
|
|
|
|
|
|
|
|
|
|
console.log("end");
|
|
|
|
|
} else {
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
supplier_waterlevel = newSupplierWaterLevel;
|
|
|
|
|
receiver_waterlevel = newWaterLevel;
|
|
|
|
|
// console.log((newSupplierWaterLevel/supplier_capacity)*100)
|
|
|
|
|
// console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
await Promise.all([
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: newSupplierWaterLevel } })
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="bore" && receiver_type === "sump"){
|
|
|
|
|
const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
console.log(receiver_capacity,"0")
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "true" } });
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
console.log(receiver_waterlevel,"1")
|
|
|
|
|
intervalId = setInterval(async function () {
|
|
|
|
|
// Calculate new water levels
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank});
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
|
|
|
|
|
const newWaterLevel = receiver_waterlevel+200;
|
|
|
|
|
console.log(newWaterLevel,"2")
|
|
|
|
|
// Check if updating should stop
|
|
|
|
|
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "false" ) {
|
|
|
|
|
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === 0 ) {
|
|
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "false" } });
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { motor_status: 0 } });
|
|
|
|
|
clearInterval(intervalId)
|
|
|
|
|
console.log("end");
|
|
|
|
|
} else {
|
|
|
|
@ -382,7 +385,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
console.log((newWaterLevel/receiver_capacity)*100,"4")
|
|
|
|
|
await Promise.all([
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
@ -434,7 +437,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
// stop_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'})
|
|
|
|
|
// console.log(stop_time)
|
|
|
|
|
// clearInterval(intervalId);
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "false" } });
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:req.body.to_type}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
// reply.send({ status_code: 200, "stop time": stop_time});
|
|
|
|
|
} else {
|
|
|
|
|