From f5e219edf58974d1a4b1b675ffef534eaf1fdd81 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 26 May 2023 02:06:40 -0400 Subject: [PATCH] added stop_at --- src/controllers/tanksController.js | 13 +++++-------- src/routes/tanksRoute.js | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 4e882515..2e13d78b 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -152,7 +152,7 @@ exports.getTank = async (req, reply) => { exports.updateTanklevels = async (req, reply) => { try { const customerId = req.params.customerId; - const tanks = await Tank.find({ customerId }); + const tanks = await Tank.find({ customerId,tankLocation:"overhead" }); const intervals = {}; @@ -166,7 +166,7 @@ exports.updateTanklevels = async (req, reply) => { const tank_data = await Tank.findOne({ _id:tankId }); const motorStatus = tank_data.motor_status let waterLevel = parseInt(tank_data.waterlevel.replace(/,/g, ''), 10); - const newWaterLevel = Math.floor(waterLevel - 200); + const newWaterLevel = Math.floor(waterLevel - 150); console.log("motorstatus:"+motorStatus) if (newWaterLevel <= 0 ) { @@ -243,7 +243,7 @@ exports.motorAction = async (req, reply) => { if(action === "start"){ const start_time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'}) - + const stop_at = req.body.stop_at @@ -281,7 +281,7 @@ exports.motorAction = async (req, reply) => { 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") { + if ((newSupplierWaterLevel/supplier_capacity)*100 <= stop_at || (newWaterLevel/receiver_capacity)*100 >= 95 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0") { clearInterval(intervals[interval_variable]); // Clear the interval for this tank delete intervals[interval_variable]; sum_oh_count--; @@ -400,7 +400,7 @@ exports.motorAction = async (req, reply) => { const newWaterLevel = receiver_waterlevel + 300//Math.floor(supplier_waterlevel * 0.1); const newSupplierWaterLevel = Math.min(supplier_capacity, supplier_waterlevel - 300);// Math.floor(supplier_waterlevel * 0.15)); // Check if updating should stop - if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0" || (newSupplierWaterLevel/supplier_capacity)*100 <= 5 ) { + if ((newWaterLevel/receiver_capacity)*100 >= 97 || (newWaterLevel/receiver_capacity)*100 >= desired_water_percentage || rcvr_info.motor_status === "0" || (newSupplierWaterLevel/supplier_capacity)*100 <= stop_at ) { clearInterval(intervals[interval_variable]); // Clear the interval for this tank delete intervals[interval_variable]; @@ -432,9 +432,6 @@ exports.motorAction = async (req, reply) => { - - - if(supplier_tank_type==="bore" && receiver_type === "sump"){ const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10) diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index cfcfac74..fb52a6c3 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -245,6 +245,7 @@ module.exports = function (fastify, opts, next) { percentage: { type: "string",default: "100" }, startTime:{ type: "string" }, stopTime:{ type: "string" }, + stop_at:{type:"number"} }, },