|
|
|
@ -311,6 +311,11 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
let sumOverheadDrinkingWaterCapacity = 0;
|
|
|
|
|
let sumSumpBoreWaterCapacity = 0;
|
|
|
|
|
let sumOverheadBoreWaterCapacity = 0;
|
|
|
|
|
|
|
|
|
|
let totalInputPercentage = 0;
|
|
|
|
|
let inputCount = 0;
|
|
|
|
|
let totalOutputPercentage = 0;
|
|
|
|
|
let outputCount = 0;
|
|
|
|
|
|
|
|
|
|
const updated_data = await Tank.find({ customerId: customerId });
|
|
|
|
|
console.log("updated_data", updated_data);
|
|
|
|
@ -330,6 +335,8 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
const inputWaterLevel = parseInt(inputConnection.water_level.replace(/,/g, ''), 10);
|
|
|
|
|
const inputCapacity = parseInt(inputConnection.capacity.replace(/,/g, ''), 10);
|
|
|
|
|
inputConnection.waterlevelPercentage = ((inputWaterLevel / inputCapacity) * 100).toFixed(2);
|
|
|
|
|
totalInputPercentage += parseFloat(inputConnection.waterlevelPercentage);
|
|
|
|
|
inputCount++;
|
|
|
|
|
} else {
|
|
|
|
|
inputConnection.waterlevelPercentage = null;
|
|
|
|
|
}
|
|
|
|
@ -343,6 +350,8 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
const outputWaterLevel = parseInt(outputConnection.water_level.replace(/,/g, ''), 10);
|
|
|
|
|
const outputCapacity = parseInt(outputConnection.capacity.replace(/,/g, ''), 10);
|
|
|
|
|
outputConnection.waterlevelPercentage = ((outputWaterLevel / outputCapacity) * 100).toFixed(2);
|
|
|
|
|
totalOutputPercentage += parseFloat(outputConnection.waterlevelPercentage);
|
|
|
|
|
outputCount++;
|
|
|
|
|
} else {
|
|
|
|
|
outputConnection.waterlevelPercentage = null;
|
|
|
|
|
}
|
|
|
|
@ -369,9 +378,15 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
const buildingName = user ? user.buildingName : null;
|
|
|
|
|
const address1 = user ? user.profile.address1 : null;
|
|
|
|
|
|
|
|
|
|
// Calculate average percentages
|
|
|
|
|
const inputWaterlevelPercentage = inputCount > 0 ? (totalInputPercentage / inputCount).toFixed(2) : null;
|
|
|
|
|
const outputWaterlevelPercentage = outputCount > 0 ? (totalOutputPercentage / outputCount).toFixed(2) : null;
|
|
|
|
|
|
|
|
|
|
const responseData = {
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: updated_data,
|
|
|
|
|
inputWaterlevelPercentage: inputWaterlevelPercentage,
|
|
|
|
|
outputWaterlevelPercentage: outputWaterlevelPercentage,
|
|
|
|
|
totalDrinkingWaterInSump: sumSumpDrinkingWater,
|
|
|
|
|
totalDrinkingWaterInOverhead: sumOverheadDrinkingWater,
|
|
|
|
|
totalBoreWaterInSump: sumSumpBoreWater,
|
|
|
|
@ -398,7 +413,6 @@ exports.getTanklevels = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const intervals = {};
|
|
|
|
|
let sump_water_levels=[];
|
|
|
|
|
let supplier_tanks = [];
|
|
|
|
|