From b01a3afe71d027f82f8a06bd77d9b4e7be04f5f0 Mon Sep 17 00:00:00 2001 From: Varun Date: Wed, 19 Mar 2025 12:30:00 +0530 Subject: [PATCH] previous motoraction code --- src/controllers/tanksController.js | 66 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 39ebe2c0..376ea7ca 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2838,7 +2838,6 @@ async function calculateTotalPumpedWater(customerId, motorId, start_instance_id) - exports.motorAction = async (req, reply) => { try { const customerId = req.params.customerId; @@ -3331,41 +3330,42 @@ exports.motorAction = async (req, reply) => { }; -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, ""); +// 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 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 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 } } +// ); +// } +// }