From 97128080e081d06f01360c7c5c2d236536fc52a2 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Thu, 20 Mar 2025 14:34:53 +0530 Subject: [PATCH] low water levels notification --- src/controllers/tanksController.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index d8985a2f..13a12322 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -3308,10 +3308,6 @@ const monitorWaterLevels = async () => { for (const tank of tanks) { - -//console.log(fcmTokens) - //console.log(`🔍 Tank: ${tank.tankName} | Water Level: ${tank.waterlevel} | FCM Tokens:`, fcmTokens); - const { _id, customerId, // Move this to the top @@ -3336,9 +3332,13 @@ const monitorWaterLevels = async () => { //console.error("❌ No valid FCM tokens found for customerId:", customerId); continue; // Skip this tank } - const lowWaterLevel = (auto_min_percentage / 100) * capacity; // Low threshold in liters - const criticalLowWaterLevel = (reserved_percentage / 100) * capacity; // Critical threshold in liters - const currentWaterPercentage = (currentWaterLevel / capacity) * 100; // Current percentage + const LOW_PERCENTAGE = 20; // 20% threshold + const CRITICAL_PERCENTAGE = 10; // 10% threshold + + // **Calculate thresholds based on tank capacity** + const lowWaterLevel = (LOW_PERCENTAGE / 100) * capacity; + const criticalLowWaterLevel = (CRITICAL_PERCENTAGE / 100) * capacity; + const currentWaterPercentage = (currentWaterLevel / capacity) * 100; // const lowWaterLevel = 9483; // Low threshold in liters // const criticalLowWaterLevel = 9483; if (currentWaterLevel <= criticalLowWaterLevel) {