|
|
@ -960,7 +960,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
const tanks = await Tank.find(tankQuery);
|
|
|
|
const tanks = await Tank.find(tankQuery);
|
|
|
|
const tankData = [];
|
|
|
|
const tankData = [];
|
|
|
|
|
|
|
|
const tankconsumptionData = [];
|
|
|
|
// Variable to track total consumption for the selected block and typeofwater
|
|
|
|
// Variable to track total consumption for the selected block and typeofwater
|
|
|
|
let totalConsumptionForSelectedBlockAndTypeOfWater = 0;
|
|
|
|
let totalConsumptionForSelectedBlockAndTypeOfWater = 0;
|
|
|
|
|
|
|
|
|
|
|
@ -990,6 +990,10 @@ exports.consumption = async (request, reply) => {
|
|
|
|
const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => {
|
|
|
|
const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => {
|
|
|
|
return acc + parseInt(record.consumption, 10);
|
|
|
|
return acc + parseInt(record.consumption, 10);
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
tankconsumptionData.push({
|
|
|
|
|
|
|
|
tankname,
|
|
|
|
|
|
|
|
consumptionRecordsdatewise: filteredConsumptions
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
@ -998,6 +1002,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
tankData.push({
|
|
|
|
tankData.push({
|
|
|
|
tankname,
|
|
|
|
tankname,
|
|
|
|
|
|
|
|
|
|
|
|
totalConsumption: consumption,
|
|
|
|
totalConsumption: consumption,
|
|
|
|
block: tank.blockName,
|
|
|
|
block: tank.blockName,
|
|
|
|
TypeofWater: tank.typeOfWater,
|
|
|
|
TypeofWater: tank.typeOfWater,
|
|
|
@ -1010,7 +1015,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
// Include the total consumption in the response
|
|
|
|
// Include the total consumption in the response
|
|
|
|
const response = {
|
|
|
|
const response = {
|
|
|
|
status_code: 200,
|
|
|
|
status_code: 200,
|
|
|
|
tankData,
|
|
|
|
tankData,consumptiorecordsdatewise:tankconsumptionData,
|
|
|
|
[`total consumption of ${typeofwater} and selected block`]: totalConsumptionForSelectedBlockAndTypeOfWater
|
|
|
|
[`total consumption of ${typeofwater} and selected block`]: totalConsumptionForSelectedBlockAndTypeOfWater
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|