consumed water till night

master
varun 1 year ago
parent 556931e871
commit bcaed8bac0

@ -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);
// 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);
}
reply.send({ status_code: 200, tankData });
// const tankname = tank.tankName
// const consumption = (waterlevel_at_midnight+total_water_added_from_midnight)-waterlevel
return { message: 'Water level updates started' };
} catch (err) {
throw boom.boomify(err);
}
// tankData.push({ tankname, waterLevel: consumption });
// // console.log(newWaterLevel);
// try {
// const { customerId } = request.params;
// }
// reply.send({ status_code: 200, tankData });
// const tank = await Tank.find({ customerId, tankLocation:"overhead" });
// return { message: 'Water level updates started' };
// } catch (err) {
// throw boom.boomify(err);
// }
// if (!tank) {
// return reply.status(404).send({ error: 'Tank not found' });
// }
// // 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' });
// }
};
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,

@ -45,11 +45,6 @@ const tanksSchema = new mongoose.Schema({
waterCapacityPerCm:{ type: String, default: "0" },
typeOfWater: { type: String, default: null },
waterlevel: { type: String, default: "0" },
tankLocation: { type: String, default: null },
motor_status: { type: String, default: "1" },
motor_stop_status: { type: String, default: "1" },
motor_speed: { type: String, default: "100" },
motor_temperature: { type: String, default: "0" },
waterlevel_at_midnight:{ type: String,default:"0" },
total_water_added_from_midnight:{ type: String,default:"0" },
auto_min_percentage :{ type: String, default: "20" },

@ -308,8 +308,45 @@ module.exports = function (fastify, opts, next) {
});
// fastify.route({
// method: "PUT",
// url: "/api/consumption/:customerId",
// schema: {
// tags: ["Tank"],
// summary: "This is for getting consumption",
// params: {
// required: ["customerId"],
// type: "object",
// properties: {
// customerId: {
// type: "string",
// description: "customerId",
// },
// },
// },
// body: {
// type: "object",
// properties: {
// startDate:{ type: "string" },
// stopDate:{type:"string"},
// },
// },
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// //preHandler: fastify.auth([fastify.authenticate]),
// handler: tanksController.consumption,
// });
fastify.route({
method: "GET",
method: "PUT",
url: "/api/consumption/:customerId",
schema: {
tags: ["Tank"],
@ -324,19 +361,17 @@ module.exports = function (fastify, opts, next) {
},
},
},
// querystring: {
// tankName: {type: 'string'}
// },
body: {
type: "object",
// required: ['phone'],
properties: {
startDate:{ type: "string" },
stopDate:{type:"string"},
body: {
type: "object",
// required: ['phone'],
properties: {
startDate:{ type: "string" },
stopDate:{type:"string"},
},
},
},
},
security: [
{
basicAuth: [],
@ -347,6 +382,12 @@ module.exports = function (fastify, opts, next) {
handler: tanksController.consumption,
});
fastify.route({
method: "PUT",
url: "/api/calculateCapacity",

Loading…
Cancel
Save