|
|
|
@ -824,52 +824,35 @@ let supplier_tanks = [];
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.consumption = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const tanks = await Tank.find({ customerId,tankLocation:"overhead"});
|
|
|
|
|
const tankData = [];
|
|
|
|
|
for (const tank of tanks) {
|
|
|
|
|
const tankId = tank._id;
|
|
|
|
|
const waterlevel_at_midnight = parseInt(tank.waterlevel_at_midnight.replace(/,/g, ''), 10);
|
|
|
|
|
const total_water_added_from_midnight = parseInt(tank.total_water_added_from_midnight.replace(/,/g, ''), 10);
|
|
|
|
|
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
|
|
const tankname = tank.tankName
|
|
|
|
|
const consumption = (waterlevel_at_midnight+total_water_added_from_midnight)-waterlevel
|
|
|
|
|
|
|
|
|
|
tankData.push({ tankname, waterLevel: newWaterLevel });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(newWaterLevel);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
reply.send({ status_code: 200, tankData });
|
|
|
|
|
|
|
|
|
|
return { message: 'Water level updates started' };
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
// exports.consumption = async (request, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const customerId = req.params.customerId;
|
|
|
|
|
// const tanks = await Tank.find({ customerId,tankLocation:"overhead"});
|
|
|
|
|
// const tankData = [];
|
|
|
|
|
// for (const tank of tanks) {
|
|
|
|
|
// const tankId = tank._id;
|
|
|
|
|
// const waterlevel_at_midnight = parseInt(tank.waterlevel_at_midnight.replace(/,/g, ''), 10);
|
|
|
|
|
// const total_water_added_from_midnight = parseInt(tank.total_water_added_from_midnight.replace(/,/g, ''), 10);
|
|
|
|
|
// const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
|
|
|
|
|
|
// const tankname = tank.tankName
|
|
|
|
|
// const consumption = (waterlevel_at_midnight+total_water_added_from_midnight)-waterlevel
|
|
|
|
|
|
|
|
|
|
// tankData.push({ tankname, waterLevel: consumption });
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// const { customerId } = request.params;
|
|
|
|
|
|
|
|
|
|
// const tank = await Tank.find({ customerId, tankLocation:"overhead" });
|
|
|
|
|
// // console.log(newWaterLevel);
|
|
|
|
|
|
|
|
|
|
// if (!tank) {
|
|
|
|
|
// return reply.status(404).send({ error: 'Tank not found' });
|
|
|
|
|
// }
|
|
|
|
|
// reply.send({ status_code: 200, tankData });
|
|
|
|
|
|
|
|
|
|
// // Here you can process and return the consumption data as needed
|
|
|
|
|
// return reply.send(tank);
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// request.log.error(error);
|
|
|
|
|
// return reply.status(500).send({ error: 'Internal Server Error' });
|
|
|
|
|
// return { message: 'Water level updates started' };
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function parseDateTime(dateTimeStr) {
|
|
|
|
@ -884,6 +867,7 @@ function parseDateTime(dateTimeStr) {
|
|
|
|
|
|
|
|
|
|
exports.consumption = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
const { customerId } = request.params;
|
|
|
|
|
const { startDate, stopDate } = request.body;
|
|
|
|
|
|
|
|
|
@ -898,7 +882,7 @@ exports.consumption = async (request, reply) => {
|
|
|
|
|
const total_water_added_from_midnight = parseInt(tank.total_water_added_from_midnight.replace(/,/g, ''), 10);
|
|
|
|
|
const waterlevel = parseInt(tank.waterlevel.replace(/,/g, ''), 10);
|
|
|
|
|
const tankname = tank.tankName;
|
|
|
|
|
|
|
|
|
|
console.log(waterlevel_at_midnight,total_water_added_from_midnight,waterlevel)
|
|
|
|
|
const tankConsumptions = await TankConsumptionSchema.find({
|
|
|
|
|
customerId,
|
|
|
|
|
tankName: tank.tankName,
|
|
|
|
|