|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
//const Tank = require("../models/tanks");
|
|
|
|
|
const { Tank, MotorData, IotData,MotorIot,TankWaterLevel } = require('../models/tanks')
|
|
|
|
|
const { Tank, MotorData, IotData,MotorIot,TankWaterLevel,TankConsumptionSchema } = require('../models/tanks')
|
|
|
|
|
|
|
|
|
|
const User = require("../models/User");
|
|
|
|
|
const boom = require("boom");
|
|
|
|
@ -2177,18 +2177,33 @@ cron.schedule('0 0 * * *', updatewaterlevelsatmidnight, {
|
|
|
|
|
timezone: "Asia/Kolkata"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const updateWaterConsumptiontillmidnight = async () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updatetotalConsumptiontillmidnight = async () => {
|
|
|
|
|
console.log('Cron job triggered at:', moment().tz('Asia/Kolkata').format());
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const tanks = await Tank.find({});
|
|
|
|
|
for (const tank of tanks) {
|
|
|
|
|
|
|
|
|
|
const waterlevel_at_midnight = parseInt((tank.waterlevel_at_midnight).replace(/,/g, ''), 10);
|
|
|
|
|
const total_water_added_from_midnight = parseInt((tank.total_water_added_from_midnight).replace(/,/g, ''), 10);
|
|
|
|
|
const waterlevel = parseInt((tank.waterlevel).replace(/,/g, ''), 10);
|
|
|
|
|
const totalconsumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel
|
|
|
|
|
const newTankConsumption = new TankConsumptionSchema({
|
|
|
|
|
customerId: tank.customerId,
|
|
|
|
|
tankName: tank.tankName,
|
|
|
|
|
tankLocation: tank.tankLocation,
|
|
|
|
|
consumption: totalconsumption.toString(),
|
|
|
|
|
time: new Date().toISOString()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tank.waterlevel_at_midnight = tank.waterlevel;
|
|
|
|
|
tank.total_water_added_from_midnight = "0";
|
|
|
|
|
await tank.save();
|
|
|
|
|
console.log(`Updated tank ${tank._id} waterlevel_at_midnight to ${tank.waterlevel}`);
|
|
|
|
|
// Save the new document
|
|
|
|
|
await newTankConsumption.save();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
console.log('Waterlevel noted in waterlevel_at_midnight');
|
|
|
|
|
} catch (error) {
|
|
|
|
@ -2197,11 +2212,14 @@ const updateWaterConsumptiontillmidnight = async () => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Schedule the task to run every day at 13:49 IST (1:49 PM IST)
|
|
|
|
|
cron.schedule('55 23 * * *', updateWaterConsumptiontillmidnight, {
|
|
|
|
|
cron.schedule('55 23 * * *', updatetotalConsumptiontillmidnight, {
|
|
|
|
|
timezone: "Asia/Kolkata"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deletemotordatarecordsbefore7days = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
// Schedule the task to run every day at 10 seconds past the minute
|
|
|
|
|