From 257030e603d739e66544f03114406b9f54d40625 Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 21 Mar 2025 13:24:19 +0530 Subject: [PATCH 1/4] added runtime in motordata --- src/controllers/tanksController.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 6769e7ea..075c3034 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3062,6 +3062,10 @@ exports.motorAction = async (req, reply) => { const quantityDelivered = receiverFinalWaterLevel - parseInt(motorData.receiverInitialwaterlevel, 10); const water_pumped_till_now = parseInt(receiverTank.total_water_added_from_midnight, 10); const totalwaterpumped = quantityDelivered + water_pumped_till_now; + const start = moment(motorData.startTime, 'DD-MMM-YYYY - HH:mm'); + const stop = moment(currentTime, 'DD-MMM-YYYY - HH:mm'); + const duration = moment.duration(stop.diff(start)); + const runtime = Math.floor(duration.asMinutes()); await Tank.findOneAndUpdate( { customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }, @@ -3074,7 +3078,8 @@ exports.motorAction = async (req, reply) => { $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), - quantity_delivered: quantityDelivered.toString() + quantity_delivered: quantityDelivered.toString(), + runtime:runtime.toString() } } ); From d883fa8f68238aaa70e580b4db41d6f0d04e81d8 Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 21 Mar 2025 13:31:59 +0530 Subject: [PATCH 2/4] changes reverted --- src/controllers/tanksController.js | 42 +++--------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 075c3034..336ad056 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3065,7 +3065,8 @@ exports.motorAction = async (req, reply) => { const start = moment(motorData.startTime, 'DD-MMM-YYYY - HH:mm'); const stop = moment(currentTime, 'DD-MMM-YYYY - HH:mm'); const duration = moment.duration(stop.diff(start)); - const runtime = Math.floor(duration.asMinutes()); + const runtime = Math.floor(duration.asMinutes()); // runtime in minutes + await Tank.findOneAndUpdate( { customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }, @@ -3079,7 +3080,7 @@ exports.motorAction = async (req, reply) => { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), - runtime:runtime.toString() + runtime: runtime.toString() } } ); @@ -3251,43 +3252,6 @@ async function stopMotor(motorId, customerId, start_instance_id) { } -async function stopMotor(motorId, customerId, start_instance_id) { - const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); - await Tank.updateOne( - { customerId, "connections.inputConnections.motor_id": motorId }, - { $set: { - "connections.inputConnections.$.motor_stop_status": "1", - "connections.inputConnections.$.stopTime": currentTime, - "connections.inputConnections.$.threshold_type": null, - "connections.inputConnections.$.manual_threshold_time": null, - "connections.inputConnections.$.manual_threshold_percentage": null - }} - ); - - if (motorIntervals[motorId]) { - clearInterval(motorIntervals[motorId]); - delete motorIntervals[motorId]; - } - - // eventEmitter.emit("motorStop", customerId, [], "", "", currentTime, "Mobile APP", 0, "", motorId, ""); - - const motorData = await MotorData.findOne({ customerId, motor_id: motorId, start_instance_id }); - if (motorData) { - const startTime = moment(motorData.startTime, 'DD-MMM-YYYY - HH:mm'); - const runtime = moment.duration(moment(currentTime, 'DD-MMM-YYYY - HH:mm').diff(startTime)).asSeconds(); - - const receiverTank = await Tank.findOne({ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }); - const receiverFinalWaterLevel = parseInt(receiverTank.waterlevel.replace(/,/g, ''), 10); - const quantityDelivered = receiverFinalWaterLevel - parseInt(motorData.receiverInitialwaterlevel.replace(/,/g, ''), 10); - - await MotorData.updateOne( - { customerId, motor_id: motorId, start_instance_id }, - { $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime } } - ); - } -} - - const monitorWaterLevels = async () => { From dc5b3766b5df60a82176f5c31a77da1631e208c3 Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 21 Mar 2025 13:55:08 +0530 Subject: [PATCH 3/4] changes consoles added in motor action for quantity delivered --- src/controllers/tanksController.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 336ad056..c4dff7f1 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3059,7 +3059,9 @@ exports.motorAction = async (req, reply) => { console.log("got into if") const receiverTank = await Tank.findOne({ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }); const receiverFinalWaterLevel = parseInt(receiverTank.waterlevel, 10); + console.log(receiverFinalWaterLevel,"receiverFinalWaterLevel") const quantityDelivered = receiverFinalWaterLevel - parseInt(motorData.receiverInitialwaterlevel, 10); + console.log(quantityDelivered,"quantityDelivered") const water_pumped_till_now = parseInt(receiverTank.total_water_added_from_midnight, 10); const totalwaterpumped = quantityDelivered + water_pumped_till_now; const start = moment(motorData.startTime, 'DD-MMM-YYYY - HH:mm'); @@ -3136,7 +3138,7 @@ exports.motorAction = async (req, reply) => { const supplier_threshold = supplier_waterLevel-desired_percentage console.log(supplier_threshold,"supplier_threshold") - for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { + this.publishMotorStopStatus(motorId, motorStopStatus); for await (const tank of Tank.find({ "connections.inputConnections.motor_id": motorId })) { const index = tank.connections.inputConnections.findIndex(connection => connection.motor_id === motorId); @@ -3200,7 +3202,7 @@ exports.motorAction = async (req, reply) => { } } }, 20000); - } + } @@ -6133,6 +6135,11 @@ async function processIotData(hw_Id, data) { inputConnection.motor_stop_status = "1"; inputConnection.motor_on_type = "manual"; inputConnection.stopTime = currentTime; + if (motorIntervals[motorId]) { + clearInterval(motorIntervals[motorId]); + delete motorIntervals[motorId]; + console.log("motor interval deleted") + } } await motorTank.save(); From 2416ee856604d60f6a26ca4782bf88921fafe3cd Mon Sep 17 00:00:00 2001 From: Varun Date: Fri, 21 Mar 2025 14:21:16 +0530 Subject: [PATCH 4/4] changes --- src/controllers/tanksController.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index c4dff7f1..493a5f15 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3032,6 +3032,8 @@ exports.motorAction = async (req, reply) => { "connections.inputConnections.$.manual_threshold_time": null, "connections.inputConnections.$.manual_threshold_percentage": null, "connections.inputConnections.$.stopTime": currentTime, + "connections.inputConnections.$.start_instance_id": null, + } } ); @@ -3057,6 +3059,7 @@ exports.motorAction = async (req, reply) => { console.log(motorData,"motorData") if (motorData) { console.log("got into if") + const receiverTank = await Tank.findOne({ customerId, tankName: motorData.receiverTank, tankLocation: motorData.receiver_type.toLowerCase() }); const receiverFinalWaterLevel = parseInt(receiverTank.waterlevel, 10); console.log(receiverFinalWaterLevel,"receiverFinalWaterLevel")