master^2
Varun 4 months ago
parent 6fccf490fc
commit eab4b908bc

@ -7852,3 +7852,74 @@ exports.compareMeasuredHeight = async (req, reply) => {
reply.status(500).send({ message: err.message }); reply.status(500).send({ message: err.message });
} }
}; };
//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();

Loading…
Cancel
Save