made changes in start and stop,created consumption

master
varun 3 years ago
parent d381d95533
commit 2a279e3ce4

@ -260,41 +260,69 @@ exports.motorAction = async (req, reply) => {
if(action === "start"){ if(action === "start"){
supplier_tank = req.body.from supplier_tank = req.body.from
supplier_tank_type = req.body.from_type supplier_tank_type = req.body.from_type
receiver_type = req.body.to_type
if(supplier_tank_type==="sump"){ // if(supplier_tank_type==="sump" && receiver_type === "overhead"){
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank}); // const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200; // initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)-200;
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } }); // await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });
const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank}); // const supplier_tank_info = await Tank.findOne({ customerId ,tankName:supplier_tank});
//await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info); //await changingfrom_tankwaterlevel(customerId,initial_update,supplier_tank_info);
let supplier_waterlevel = parseInt(supplier_tank_info.waterlevel.replace(/,/g, ''), 10) // 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 newWaterLevel = receiver_waterlevel + 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)
// Check if updating should stop
// if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95) {
// clearInterval(intervalId)
// 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 = receiver_tank_info.capacity
let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10) let receiver_waterlevel = parseInt(receiver_tank_info.waterlevel.replace(/,/g, ''), 10)
intervalId = setInterval(async function () { intervalId = setInterval(async function () {
// Calculate new water levels // Calculate new water levels
const newWaterLevel = receiver_waterlevel + Math.floor(supplier_waterlevel * 0.1); const newWaterLevel = receiver_waterlevel+225;
const newSupplierWaterLevel = supplier_waterlevel - Math.floor(supplier_waterlevel * 0.1);
const supplier_capacity = parseInt(supplier_tank_info.capacity.replace(/,/g, ''), 10)
// Check if updating should stop // Check if updating should stop
if ((newSupplierWaterLevel/supplier_capacity)*100 <= 5 || (newWaterLevel/receiver_capacity)*100 >= 95) { if ((newWaterLevel/receiver_capacity)*100 >= 97) {
clearInterval(intervalId) clearInterval(intervalId)
console.log("end"); console.log("end");
} else { } else {
// Update water levels in database // Update water levels in database
supplier_waterlevel = newSupplierWaterLevel;
receiver_waterlevel = newWaterLevel; receiver_waterlevel = newWaterLevel;
console.log((newSupplierWaterLevel/supplier_capacity)*100)
console.log((newWaterLevel/receiver_capacity)*100) console.log((newWaterLevel/receiver_capacity)*100)
await Promise.all([ await Promise.all([
Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }), Tank.findOneAndUpdate({customerId, tankName: receiver_tank}, { $set: { waterlevel: newWaterLevel } }),
Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: newSupplierWaterLevel } })
]); ]);
} }
}, 2000); }, 2000);
} }
if(supplier_tank_type==="bore"){
if(supplier_tank_type==="sump" && receiver_type === "overhead"){
const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank}); const supplier_tank_info1 = await Tank.findOne({ customerId ,tankName:supplier_tank});
initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)/2; initial_update = parseInt(supplier_tank_info1.capacity.replace(/,/g, ''), 10)/2;
await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } }); await Tank.findOneAndUpdate({customerId, tankName: supplier_tank}, { $set: { waterlevel: initial_update } });

@ -229,6 +229,7 @@ module.exports = function (fastify, opts, next) {
to: { type: "string", default: null }, to: { type: "string", default: null },
from: { type: "string", default: null }, from: { type: "string", default: null },
from_type: { type: "string" }, from_type: { type: "string" },
to_type: { type: "string" },
action: { type: "string" }, action: { type: "string" },
}, },

Loading…
Cancel
Save