|
|
|
@ -270,7 +270,7 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
supplier_tank_type = req.body.from_type
|
|
|
|
|
receiver_type = req.body.to_type
|
|
|
|
|
console.log(supplier_tank)
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 1 } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(supplier_tank_type==="sump" && receiver_type === "overhead"){
|
|
|
|
|
// const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
|
|
|
|
@ -312,24 +312,34 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 ) {
|
|
|
|
|
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
|
|
|
|
@ -348,25 +358,29 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="bore" && receiver_type === "sump"){
|
|
|
|
|
const receiver_capacity = receiver_tank_info.capacity
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 1 } });
|
|
|
|
|
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" } });
|
|
|
|
|
|
|
|
|
|
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 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 ) {
|
|
|
|
|
if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "false" ) {
|
|
|
|
|
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "false" } });
|
|
|
|
|
clearInterval(intervalId)
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: 0 } });
|
|
|
|
|
|
|
|
|
|
console.log("end");
|
|
|
|
|
} else {
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
|
|
|
|
|
receiver_waterlevel = newWaterLevel;
|
|
|
|
|
|
|
|
|
|
console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
console.log((newWaterLevel/receiver_capacity)*100,"4")
|
|
|
|
|
await Promise.all([
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
]);
|
|
|
|
@ -419,8 +433,8 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
else if (action === "stop") {
|
|
|
|
|
// 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: 0 } });
|
|
|
|
|
// clearInterval(intervalId);
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { motor_status: "false" } });
|
|
|
|
|
|
|
|
|
|
// reply.send({ status_code: 200, "stop time": stop_time});
|
|
|
|
|
} else {
|
|
|
|
|