changes in tanks consumption

master^2
Varun 6 months ago
parent f9d25e8eba
commit 0c8719a3c5

@ -1205,18 +1205,37 @@ exports.consumption = async (request, reply) => {
const isSameTime = start.getTime() === end.getTime();
// const isSameTime = start.getTime() === end.getTime();
// const isEndToday = moment(end).isSame(moment(), 'day');
// if (isSameTime || !isEndToday) {
// // If single timestamp OR end is not today, only use records
// consumption = total_consumption_from_records;
// } else {
// // If end is today, add real-time values
// consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
// }
const isSameTime = start.getTime() === end.getTime();
const isEndToday = moment(end).isSame(moment(), 'day');
if (isSameTime || !isEndToday) {
// If single timestamp OR end is not today, only use records
if (isSameTime && isEndToday) {
// Start and End are same AND it's today => only realtime tank calc
consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel;
} else if (isSameTime && !isEndToday) {
// Same time and NOT today => only record data
consumption = total_consumption_from_records;
} else {
// If end is today, add real-time values
} else if (!isSameTime && isEndToday) {
// Range query ending today => combine record + realtime
consumption = (waterlevel_at_midnight + total_water_added_from_midnight) - waterlevel + total_consumption_from_records;
} else {
// Range query not ending today => only record data
consumption = total_consumption_from_records;
}
// const isSameTime = start.getTime() === end.getTime();
// const isToday = moment(start).isSame(moment(), 'day');

Loading…
Cancel
Save