|
|
|
@ -294,29 +294,28 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
const receiver_type = (req.body.to_type).toLowerCase()
|
|
|
|
|
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)
|
|
|
|
|
//console.log(supplier_tank_info1)
|
|
|
|
|
//const initial_update = parseInt(supplier_tank_info1.waterlevel.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)
|
|
|
|
|
console.log(supplier_waterlevel)
|
|
|
|
|
// console.log(supplier_waterlevel)
|
|
|
|
|
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
|
|
|
|
|
intervals[receiver_tank] = setInterval(async function () {
|
|
|
|
|
// 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 newSupplierWaterLevel = supplier_waterlevel - 350//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)
|
|
|
|
|
// 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(intervals[receiver_tank]); // Clear the interval for this tank
|
|
|
|
@ -326,14 +325,18 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
console.log("end for"+receiver_tank);
|
|
|
|
|
} else {
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
supplier_waterlevel = newSupplierWaterLevel;
|
|
|
|
|
//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 } })
|
|
|
|
|
]);
|
|
|
|
|
// console.log((newWaterLevel/receiver_capacity)*100)
|
|
|
|
|
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
|
|
|
|
|
console.log(supplier_tank+""+newSupplierWaterLevel+""+"s to oh")
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank,tankLocation:supplier_tank_type}, { $set: { waterlevel: supplier_waterlevel } })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
@ -389,18 +392,18 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
if(supplier_tank_type==="bore" && receiver_type === "sump"){
|
|
|
|
|
const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10)
|
|
|
|
|
console.log(receiver_capacity,"0",receiver_tank_info.tankName)
|
|
|
|
|
// console.log(receiver_capacity,"0",receiver_tank_info.tankName)
|
|
|
|
|
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")
|
|
|
|
|
// console.log(receiver_waterlevel,"1")
|
|
|
|
|
intervals[receiver_tank] = setInterval(async function () {
|
|
|
|
|
// Calculate new water levels
|
|
|
|
|
const rcvr_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:receiver_type});
|
|
|
|
|
console.log(rcvr_info)
|
|
|
|
|
console.log(rcvr_info.motor_status)
|
|
|
|
|
//console.log(rcvr_info)
|
|
|
|
|
//console.log(rcvr_info.motor_status)
|
|
|
|
|
const newWaterLevel = receiver_waterlevel+450;
|
|
|
|
|
console.log(newWaterLevel,"2",receiver_tank_info.tankName)
|
|
|
|
|
//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" ) {
|
|
|
|
|
|
|
|
|
@ -412,16 +415,14 @@ exports.motorAction = async (req, reply) => {
|
|
|
|
|
// Update water levels in database
|
|
|
|
|
|
|
|
|
|
receiver_waterlevel = newWaterLevel;
|
|
|
|
|
|
|
|
|
|
console.log((newWaterLevel/receiver_capacity)*100,"4",receiver_tank_info.tankName)
|
|
|
|
|
await Promise.all([
|
|
|
|
|
Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } }),
|
|
|
|
|
]);
|
|
|
|
|
console.log(receiver_tank+""+newWaterLevel+""+"bore to sump")
|
|
|
|
|
//console.log((newWaterLevel/receiver_capacity)*100,"4",receiver_tank_info.tankName)
|
|
|
|
|
await Tank.findOneAndUpdate({customerId, tankName: receiver_tank,tankLocation:receiver_type}, { $set: { waterlevel: newWaterLevel } })
|
|
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
console.log(customerId,req.body.from,req.body.from_type,receiver_tank,req.body.to_type,)
|
|
|
|
|
// console.log(customerId,req.body.from,req.body.from_type,receiver_tank,req.body.to_type,)
|
|
|
|
|
motorData = {
|
|
|
|
|
|
|
|
|
|
customerId:customerId,
|
|
|
|
|