|
|
@ -1025,6 +1025,8 @@ exports.consumption = async (request, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { customerId } = request.params;
|
|
|
|
const { customerId } = request.params;
|
|
|
@ -1038,7 +1040,6 @@ exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the query object based on block and typeofwater inputs
|
|
|
|
// Construct the query object based on block and typeofwater inputs
|
|
|
|
const tankQuery = { customerId, tankLocation: "overhead" };
|
|
|
|
const tankQuery = { customerId, tankLocation: "overhead" };
|
|
|
|
|
|
|
|
|
|
|
|
if (block !== "All") {
|
|
|
|
if (block !== "All") {
|
|
|
|
tankQuery.blockName = block;
|
|
|
|
tankQuery.blockName = block;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1076,7 +1077,6 @@ exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
const consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
|
|
|
|
const consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
|
|
|
|
totalConsumptionForSelectedBlockAndTypeOfWater += consumption;
|
|
|
|
totalConsumptionForSelectedBlockAndTypeOfWater += consumption;
|
|
|
|
|
|
|
|
|
|
|
|
// Organize data by date
|
|
|
|
|
|
|
|
for (const record of filteredConsumptions) {
|
|
|
|
for (const record of filteredConsumptions) {
|
|
|
|
const recordDate = moment(record.time, "DD-MMM-YYYY - HH:mm").format("DD-MMM-YYYY - HH:mm");
|
|
|
|
const recordDate = moment(record.time, "DD-MMM-YYYY - HH:mm").format("DD-MMM-YYYY - HH:mm");
|
|
|
|
|
|
|
|
|
|
|
@ -1095,7 +1095,24 @@ exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Convert tankconsumptionData object to an array of dates for the response
|
|
|
|
// Ensure dummy tanks have records for each date
|
|
|
|
|
|
|
|
const dummyTankNames = ["DUMMY TANK OH1", "DUMMY TANK OH2", "DUMMY TANK OH3", "DUMMY TANK OH4", "DUMMY TANK OH5", "DUMMY TANK OH6"];
|
|
|
|
|
|
|
|
const dates = Object.keys(tankconsumptionData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const date of dates) {
|
|
|
|
|
|
|
|
for (const dummyTank of dummyTankNames) {
|
|
|
|
|
|
|
|
const recordExists = tankconsumptionData[date].consumptionRecordsdatewise.some(record => record.tankName === dummyTank);
|
|
|
|
|
|
|
|
if (!recordExists) {
|
|
|
|
|
|
|
|
const randomConsumption = Math.floor(Math.random() * (7000 - 3000 + 1)) + 3000;
|
|
|
|
|
|
|
|
tankconsumptionData[date].consumptionRecordsdatewise.push({
|
|
|
|
|
|
|
|
tankName: dummyTank,
|
|
|
|
|
|
|
|
consumption: randomConsumption.toString(),
|
|
|
|
|
|
|
|
time: date
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const responseData = Object.values(tankconsumptionData);
|
|
|
|
const responseData = Object.values(tankconsumptionData);
|
|
|
|
|
|
|
|
|
|
|
|
const response = {
|
|
|
|
const response = {
|
|
|
@ -1115,6 +1132,7 @@ exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
|
|
|
|
|
|
|
|
//const moment = require('moment'); // Import moment.js for date/time operations
|
|
|
|
//const moment = require('moment'); // Import moment.js for date/time operations
|
|
|
|