Commit b1d40966 by bovornsiriampairat

Added Console Log for Execution

parent 39ad325f
......@@ -55,6 +55,11 @@ xml2js.parseString(xmlString, async (err, result) => {
employee: [],
};
let skippedRecords = 0;
let importedRecords = 0;
const startTime = new Date();
for (let i = 1; i < data.length; i++) {
const row = data[i];
const mappedEmployee = {};
......@@ -80,6 +85,10 @@ xml2js.parseString(xmlString, async (err, result) => {
}, []);
jsonData.employee.push(mappedEmployee);
// Calculate progress
const progress = (i / (data.length - 1)) * 100;
console.log(`Progress: ${progress.toFixed(2)}%`);
}
try {
......@@ -99,9 +108,10 @@ xml2js.parseString(xmlString, async (err, result) => {
try {
await client.query(query, values);
console.log('Data inserted successfully.');
importedRecords++;
} catch (err) {
console.error('Error inserting data:', err);
skippedRecords++;
// Add retry logic or handle the error accordingly
}
}
......@@ -109,12 +119,20 @@ xml2js.parseString(xmlString, async (err, result) => {
client.release(); // Release the client back to the pool
const endTime = new Date();
const executionTime = (endTime - startTime) / 1000;
// Convert JSON to string
const jsonString = JSON.stringify(jsonData, null, 2);
// Write JSON to file
fs.writeFileSync(outputFilename, jsonString);
console.log(`Data processed successfully.`);
console.log(`Total records: ${data.length - 1}`);
console.log(`Skipped records: ${skippedRecords}`);
console.log(`Imported records: ${importedRecords}`);
console.log(`Execution time: ${executionTime.toFixed(2)} seconds`);
console.log(`Conversion completed. Output JSON file created: ${outputFilename}`);
} catch (err) {
console.error('Error connecting to the database:', err);
......
......@@ -6,12 +6,12 @@
{
"tagType": "INC",
"formulaid": "INC1",
"value": "50000"
"value": "60000"
},
{
"tagType": "INC",
"formulaid": "INC2",
"value": "0"
"value": "20000"
},
{
"tagType": "INC",
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment