|  |  |  | @ -1,5 +1,5 @@ | 
			
		
	
		
			
				
					|  |  |  |  | //const Tank = require("../models/tanks");
 | 
			
		
	
		
			
				
					|  |  |  |  | const { Tank, MotorData, IotData,MotorIot } = require('../models/tanks') | 
			
		
	
		
			
				
					|  |  |  |  | const { Tank, MotorData, IotData,MotorIot,TankWaterLevel } = require('../models/tanks') | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | const User = require("../models/User"); | 
			
		
	
		
			
				
					|  |  |  |  | const boom = require("boom"); | 
			
		
	
	
		
			
				
					|  |  |  | @ -2373,3 +2373,32 @@ exports.update_auto_percentage = async (req, reply) => { | 
			
		
	
		
			
				
					|  |  |  |  |     throw boom.boomify(error); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | //storing water level for every 15 minutes
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | const getFormattedISTTime = () => { | 
			
		
	
		
			
				
					|  |  |  |  |   return moment().tz('Asia/Kolkata').format('DD-MM-YYYY hh:mm:ss A'); | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | const storeWaterLevels = async () => { | 
			
		
	
		
			
				
					|  |  |  |  |   try { | 
			
		
	
		
			
				
					|  |  |  |  |     const tanks = await Tank.find({}); | 
			
		
	
		
			
				
					|  |  |  |  |     const currentTime = getFormattedISTTime(); | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     const waterLevelRecords = tanks.map(tank => ({ | 
			
		
	
		
			
				
					|  |  |  |  |       customerId: tank.customerId, | 
			
		
	
		
			
				
					|  |  |  |  |       tankName: tank.tankName, | 
			
		
	
		
			
				
					|  |  |  |  |       tankLocation: tank.tankLocation, | 
			
		
	
		
			
				
					|  |  |  |  |       waterlevel: tank.waterlevel, | 
			
		
	
		
			
				
					|  |  |  |  |       time: currentTime | 
			
		
	
		
			
				
					|  |  |  |  |     })); | 
			
		
	
		
			
				
					|  |  |  |  |      | 
			
		
	
		
			
				
					|  |  |  |  |     await TankWaterLevel.insertMany(waterLevelRecords); | 
			
		
	
		
			
				
					|  |  |  |  |     console.log('Water levels stored successfully'); | 
			
		
	
		
			
				
					|  |  |  |  |   } catch (error) { | 
			
		
	
		
			
				
					|  |  |  |  |     console.error('Error storing water levels:', error); | 
			
		
	
		
			
				
					|  |  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | setInterval(storeWaterLevels, 15 * 60 * 1000);  | 
			
		
	
	
		
			
				
					|  |  |  | 
 |