added waterlevel percentage in tanks schema

master
Bhaskar 1 year ago
parent a1a8410c2a
commit 1c36f3006f

@ -318,9 +318,38 @@ exports.getTanklevels = async (req, reply) => {
updated_data.forEach((tank) => { updated_data.forEach((tank) => {
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10); const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
const capacity = parseInt(tank.capacity.replace(/,/g, ''), 10); const capacity = parseInt(tank.capacity.replace(/,/g, ''), 10);
const waterlevelPercentage = ((waterlevel / capacity) * 100).toFixed(2);
tank.waterlevelPercentage = waterlevelPercentage; // Add water level percentage to each tank object
console.log(`Processing tank: ${tank.tankName}`); console.log(`Processing tank: ${tank.tankName}`);
console.log(`Type of Water: ${tank.typeOfWater}, Location: ${tank.tankLocation}, Waterlevel: ${waterlevel}, Capacity: ${capacity}`); console.log(`Type of Water: ${tank.typeOfWater}, Location: ${tank.tankLocation}, Waterlevel: ${waterlevel}, Capacity: ${capacity}, Waterlevel Percentage: ${waterlevelPercentage}%`);
// Calculate and add water level percentages for inputConnections
if (tank.connections.inputConnections) {
tank.connections.inputConnections.forEach(inputConnection => {
if (inputConnection.water_level && inputConnection.capacity) {
const inputWaterLevel = parseInt(inputConnection.water_level.replace(/,/g, ''), 10);
const inputCapacity = parseInt(inputConnection.capacity.replace(/,/g, ''), 10);
inputConnection.waterlevelPercentage = ((inputWaterLevel / inputCapacity) * 100).toFixed(2);
} else {
inputConnection.waterlevelPercentage = null;
}
});
}
// Calculate and add water level percentages for outputConnections
if (tank.connections.outputConnections) {
tank.connections.outputConnections.forEach(outputConnection => {
if (outputConnection.water_level && outputConnection.capacity) {
const outputWaterLevel = parseInt(outputConnection.water_level.replace(/,/g, ''), 10);
const outputCapacity = parseInt(outputConnection.capacity.replace(/,/g, ''), 10);
outputConnection.waterlevelPercentage = ((outputWaterLevel / outputCapacity) * 100).toFixed(2);
} else {
outputConnection.waterlevelPercentage = null;
}
});
}
// Summing up the total water levels and capacities
if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') { if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
sumSumpDrinkingWater += waterlevel; sumSumpDrinkingWater += waterlevel;
sumSumpDrinkingWaterCapacity += capacity; sumSumpDrinkingWaterCapacity += capacity;

@ -32,67 +32,68 @@ const RoleSchema = new Schema({ name: String });
const tanksSchema = new mongoose.Schema({ const tanksSchema = new mongoose.Schema({
hardwareId: { type: String }, hardwareId: { type: String },
InstallerId: { type: String, default: null }, InstallerId: { type: String, default: null },
tankhardwareId: { type: String }, tankhardwareId: { type: String },
hardwareId_type: { type: String }, hardwareId_type: { type: String },
hardwareId_company: { type: String }, hardwareId_company: { type: String },
customerId: { type: String, default: null }, customerId: { type: String, default: null },
tankName: { type: String, default: null }, tankName: { type: String, default: null },
blockName: { type: String, default: null }, blockName: { type: String, default: null },
capacity: { type: String, default: "0" }, capacity: { type: String, default: "0" },
height: { type: String, default: "0" }, height: { type: String, default: "0" },
tankLocation: { type: String, default: null }, tankLocation: { type: String, default: null },
waterCapacityPerCm:{ type: String, default: "0" }, waterCapacityPerCm: { type: String, default: "0" },
typeOfWater: { type: String, default: null }, typeOfWater: { type: String, default: null },
waterlevel: { type: String, default: "0" }, waterlevel: { type: String, default: "0" },
waterlevel_at_midnight:{ type: String,default:"0" }, waterlevel_at_midnight: { type: String, default: "0" },
total_water_added_from_midnight:{ type: String,default:"0" }, total_water_added_from_midnight: { type: String, default: "0" },
auto_min_percentage :{ type: String, default: "20" }, auto_min_percentage: { type: String, default: "20" },
reserved_percentage:{type: String,default:"20"}, reserved_percentage: { type: String, default: "20" },
auto_max_percentage :{ type: String, default: "80" }, auto_max_percentage: { type: String, default: "80" },
connections: { connections: {
source: { type: String }, source: { type: String },
inputConnections: [ inputConnections: [
{ {
inputConnections: { type: String }, inputConnections: { type: String },
input_type: { type: String }, input_type: { type: String },
inputismotor: { type: Boolean, }, inputismotor: { type: Boolean },
motor_id:{ type: String ,default: null}, motor_id: { type: String, default: null },
motor_status: { type: String, default: "0" }, motor_status: { type: String, default: "0" },
auto_mode:{type:String,default:"inactive"}, auto_mode: { type: String, default: "inactive" },
motor_stop_status: { type: String, default: "1" }, motor_stop_status: { type: String, default: "1" },
motor_on_type :{ type: String, default: "manual" }, motor_on_type: { type: String, default: "manual" },
capacity:{ type: String ,default: null}, capacity: { type: String, default: null },
water_level:{ type: String ,default: null}, water_level: { type: String, default: null },
manual_threshold_percentage:{type: String, default: "90"}, manual_threshold_percentage: { type: String, default: "90" },
manual_threshold_time:{type: String, default: null}, manual_threshold_time: { type: String, default: null },
threshold_type:{type: String, default: "percentage"}, threshold_type: { type: String, default: "percentage" },
startTime:{type: String,default:null}, startTime: { type: String, default: null },
start_instance_id:{type:String,default:null}, start_instance_id: { type: String, default: null },
stopTime:{type: String,default:null} stopTime: { type: String, default: null },
} waterlevelPercentage: { type: String, default: null } // Added field
], }
outputConnections: [ ],
{ outputConnections: [
outputConnections: { type: String }, {
output_type: { type: String }, outputConnections: { type: String },
outputismotor: { type: Boolean, }, output_type: { type: String },
motor_id:{ type: String ,default: null}, outputismotor: { type: Boolean },
motor_status: { type: String, default: "0" }, motor_id: { type: String, default: null },
motor_stop_status: { type: String, default: "1" }, motor_status: { type: String, default: "0" },
capacity:{ type: String ,default: null}, motor_stop_status: { type: String, default: "1" },
water_level:{ type: String ,default: null}, capacity: { type: String, default: null },
manual_threshold_percentage:{type: String, default: "90"}, water_level: { type: String, default: null },
manual_threshold_time:{type: String, default: null}, manual_threshold_percentage: { type: String, default: "90" },
threshold_type:{type: String, default: "percentage"}, manual_threshold_time: { type: String, default: null },
threshold_type: { type: String, default: "percentage" },
} waterlevelPercentage: { type: String, default: null } // Added field
] }
} ]
}); }
});

Loading…
Cancel
Save