From eab4b908bc244e019b05b67f2de204de00d5a118 Mon Sep 17 00:00:00 2001 From: Varun Date: Wed, 11 Jun 2025 11:17:42 +0530 Subject: [PATCH] changes --- src/controllers/tanksController.js | 73 +++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 7414b0f0..0b58392c 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -7851,4 +7851,75 @@ exports.compareMeasuredHeight = async (req, reply) => { console.error("Error in compareMeasuredHeight:", err); reply.status(500).send({ message: err.message }); } -}; \ No newline at end of file +}; + + + + +//const ExcelJS = require('exceljs'); +//const IotData = require('../models/IotData'); // adjust the path + +// async function generateAndSaveTankExcel() { +// const startDate = "2025-06-03T00:00:00.000Z"; +// const endDate = new Date().toISOString(); + +// const getFilteredData = async (hardwareId) => { +// const query = { +// hardwareId, +// date: { +// $gte: startDate, +// $lte: endDate, +// }, +// }; + +// console.log(`Fetching data for hardwareId: ${hardwareId}`); +// const results = await IotData.find(query).sort({ date: 1 }); + +// console.log(`Found ${results.length} records for hardwareId ${hardwareId}`); + +// const data = []; + +// for (const entry of results) { +// if (!entry.tanks || !Array.isArray(entry.tanks)) continue; + +// for (const tank of entry.tanks) { +// if (tank.tankhardwareId === 'tank-1' || tank.tankhardwareId === 'tank-2') { +// data.push({ +// hardwareId: entry.hardwareId, +// tankhardwareId: tank.tankhardwareId, +// tankHeight: tank.tankHeight, +// date: tank.date.split('T')[0], // safe because it's a string +// time: tank.time, +// }); +// } +// } +// } + +// console.log(`Filtered ${data.length} tank records for hardwareId ${hardwareId}`); +// return data; +// }; + +// const data140924 = await getFilteredData("140924"); +// const data150924 = await getFilteredData("150924"); + +// const workbook = new ExcelJS.Workbook(); +// const worksheet = workbook.addWorksheet("Tank Data"); + +// worksheet.columns = [ +// { header: "Hardware ID", key: "hardwareId", width: 15 }, +// { header: "Tank ID", key: "tankhardwareId", width: 15 }, +// { header: "Tank Height", key: "tankHeight", width: 15 }, +// { header: "Date", key: "date", width: 15 }, +// { header: "Time", key: "time", width: 15 }, +// ]; + +// const allData = [...data140924, ...data150924]; + +// allData.forEach(row => worksheet.addRow(row)); + +// await workbook.xlsx.writeFile("tank_data.xlsx"); +// console.log("✅ Excel file saved as tank_data.xlsx with rows:", allData.length); +// } + + +// generateAndSaveTankExcel();