|
|
|
@ -1184,17 +1184,35 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
...(typeofwater === "drinking" && { typeofwater: { $in: ["drinking", "Drinking Water"] } }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
let filteredConsumptions;
|
|
|
|
|
if (start.getTime() === end.getTime()) {
|
|
|
|
|
// If start and end are the same, filter for exact match
|
|
|
|
|
filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
return moment(record.time, "DD-MMM-YYYY - HH:mm").toDate().getTime() === start.getTime();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Normal range filter
|
|
|
|
|
filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
const recordTime = moment(record.time, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
return recordTime >= start && recordTime <= end;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const total_consumption_from_records = filteredConsumptions.reduce((acc, record) => {
|
|
|
|
|
return acc + parseInt(record.consumption, 10);
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
const consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
|
|
|
|
|
totalConsumptionForSelectedBlockAndTypeOfWater += consumption;
|
|
|
|
|
let consumption;
|
|
|
|
|
|
|
|
|
|
const isSameTime = start.getTime() === end.getTime();
|
|
|
|
|
const isToday = moment(start).isSame(moment(), 'day');
|
|
|
|
|
|
|
|
|
|
if (isSameTime && !isToday) {
|
|
|
|
|
// Same date & time and NOT today => use only records
|
|
|
|
|
consumption = total_consumption_from_records;
|
|
|
|
|
} else {
|
|
|
|
|
// Normal case => use full calculation
|
|
|
|
|
consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add to the total consumption and capacities based on water type
|
|
|
|
|
if (tank.typeOfWater === "bore" || tank.typeOfWater === "Bore Water") {
|
|
|
|
@ -1301,11 +1319,19 @@ exports.consumptiondatewiseofalltanks = async (request, reply) => {
|
|
|
|
|
...(typeofwater !== "all" && { typeofwater: tank.typeOfWater })
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
let filteredConsumptions;
|
|
|
|
|
if (start.getTime() === end.getTime()) {
|
|
|
|
|
// If start and end are the same, filter for exact match
|
|
|
|
|
filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
return moment(record.time, "DD-MMM-YYYY - HH:mm").toDate().getTime() === start.getTime();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Normal range filter
|
|
|
|
|
filteredConsumptions = tankConsumptions.filter((record) => {
|
|
|
|
|
const recordTime = moment(record.time, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
return recordTime >= start && recordTime <= end;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// filteredConsumptions.forEach(record => {
|
|
|
|
|
// totalConsumed += parseInt(record.consumption, 10);
|
|
|
|
|
// totalAvailableCapacity += parseInt(record.capacity, 10);
|
|
|
|
@ -6179,10 +6205,14 @@ async function processIotData(hw_Id, data) {
|
|
|
|
|
inputConnection.motor_status = status;
|
|
|
|
|
|
|
|
|
|
if (inputConnection.motor_stop_status === "1" && status === 2 && inputConnection.motor_on_type !== "forced_manual") {
|
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
|
|
|
|
|
const currentTime = moment().tz('Asia/Kolkata');
|
|
|
|
|
const formattedTime = currentTime.format('DD-MMM-YYYY - HH:mm');
|
|
|
|
|
const startInstanceId = `${hw_Id}${formattedTime}`;
|
|
|
|
|
|
|
|
|
|
inputConnection.motor_stop_status = "2";
|
|
|
|
|
inputConnection.motor_on_type = "forced_manual";
|
|
|
|
|
inputConnection.startTime = currentTime;
|
|
|
|
|
inputConnection.startTime = formattedTime;
|
|
|
|
|
inputConnection.start_instance_id = startInstanceId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inputConnection.motor_stop_status === "2" && status === 1) {
|
|
|
|
|