Enhance logging with student details in evaluation
Updated `iterateOverDashboardTable.js` to include student name and ID in log output. Added functions in `evaluateStartPakket.js` to fetch student name and ID from specified selectors. Adjusted `.gitignore` to exclude `.idea` directory.
This commit is contained in:
parent
05a1b85801
commit
6c7aa018cd
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
node_modules
|
||||
vars.js
|
||||
.idea
|
||||
*.xlsx
|
35
appendResultsToExcel.js
Normal file
35
appendResultsToExcel.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const xlsx = require("xlsx");
|
||||
const fs = require("fs");
|
||||
|
||||
function appendToExcel(newResult, filename) {
|
||||
let workbook;
|
||||
|
||||
// Load existing file if it exists
|
||||
if (fs.existsSync(filename)) {
|
||||
workbook = xlsx.readFile(filename);
|
||||
} else {
|
||||
workbook = xlsx.utils.book_new();
|
||||
}
|
||||
|
||||
const sheetName = "Results";
|
||||
let worksheet = workbook.Sheets[sheetName];
|
||||
|
||||
// If the worksheet doesn't exist, create it
|
||||
if (!worksheet) {
|
||||
worksheet = xlsx.utils.json_to_sheet([]);
|
||||
xlsx.utils.book_append_sheet(workbook, worksheet, sheetName);
|
||||
}
|
||||
|
||||
// Get existing data from the worksheet
|
||||
const data = xlsx.utils.sheet_to_json(worksheet);
|
||||
data.push(newResult); // Add new result
|
||||
|
||||
// Update worksheet with new data
|
||||
const updatedWorksheet = xlsx.utils.json_to_sheet(data);
|
||||
workbook.Sheets[sheetName] = updatedWorksheet;
|
||||
|
||||
// Write updated workbook to file
|
||||
xlsx.writeFile(workbook, filename);
|
||||
}
|
||||
|
||||
module.exports = appendToExcel;
|
|
@ -6,9 +6,10 @@ start dan het script
|
|||
*/
|
||||
const puppeteer = require("puppeteer");
|
||||
const isStartPakketAvailable = require("./evaluateStartPakket");
|
||||
const xlsx = require("xlsx");
|
||||
const fs = require("fs");
|
||||
const saveResultsToExcel = require("./saveResultsToExcel");
|
||||
const appendToExcel = require("./appendResultsToExcel");
|
||||
const wait = require("./wait");
|
||||
|
||||
async function iterateOverDashboardTable() {
|
||||
/*connection to local host */
|
||||
|
@ -18,6 +19,7 @@ async function iterateOverDashboardTable() {
|
|||
|
||||
//array to store results for Excel export
|
||||
let results = []
|
||||
const filename = "DashboardResults.xlsx"
|
||||
|
||||
// Get all open pages (tabs)
|
||||
const pages = await browser.pages();
|
||||
|
@ -55,6 +57,12 @@ async function iterateOverDashboardTable() {
|
|||
);
|
||||
console.log(`Found ${links.length} AA-links to process.`);
|
||||
|
||||
// Initialize Excel file if it doesn't exist
|
||||
if (!fs.existsSync(filename)) {
|
||||
saveResultsToExcel([], filename); // Create empty file
|
||||
console.log(`Initialized new Excel file: ${filename}`);
|
||||
}
|
||||
|
||||
// process links
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
console.log(`Processing link ${i + 1}`);
|
||||
|
@ -68,6 +76,8 @@ async function iterateOverDashboardTable() {
|
|||
`${tableBodySelector} tr span[title="AA-rapport"] a`
|
||||
);
|
||||
|
||||
if ((i + 1) % 10 === 0) {await wait(10000)}
|
||||
|
||||
const [newPagePromise] = await Promise.all([
|
||||
new Promise((resolve) =>
|
||||
browser.once("targetcreated", async (target) => {
|
||||
|
@ -77,6 +87,7 @@ async function iterateOverDashboardTable() {
|
|||
),
|
||||
links[i].click(), // Simulate the click
|
||||
]);
|
||||
let result;
|
||||
|
||||
const newPage = await newPagePromise;
|
||||
|
||||
|
@ -84,7 +95,7 @@ async function iterateOverDashboardTable() {
|
|||
const evaluationResult = await isStartPakketAvailable(newPage);
|
||||
|
||||
//Save results for Excel
|
||||
results.push({
|
||||
result = ({
|
||||
LinkNumber: i +1,
|
||||
StudentName: evaluationResult.studName || 'N/A',
|
||||
StudentID: evaluationResult.studId || "N/A",
|
||||
|
@ -97,7 +108,7 @@ async function iterateOverDashboardTable() {
|
|||
} catch (error) {
|
||||
console.error(`Error processing link ${i + 1}:`, error.message);
|
||||
// Save error for Excel
|
||||
results.push({
|
||||
result = ({
|
||||
LinkNumber: i + 1,
|
||||
StudentName: "Error",
|
||||
StudentID: "Error",
|
||||
|
@ -109,6 +120,8 @@ async function iterateOverDashboardTable() {
|
|||
finally {
|
||||
await newPage.close();
|
||||
}
|
||||
results.push(result);
|
||||
appendToExcel(result, filename);
|
||||
}
|
||||
|
||||
console.log("All links processed.");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const xlsx = require("xlsx");
|
||||
function saveResultsToExcel(data, filename) {
|
||||
const workbook = xlsx.utils.book_new(); // Create a new workbook
|
||||
const worksheet = xlsx.utils.json_to_sheet(data); // Convert data to worksheet
|
||||
|
|
Loading…
Reference in New Issue
Block a user