Compare commits

..

4 Commits

Author SHA1 Message Date
bdaneels
0e275a5bc6 First Beta Version complete
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.
2024-12-03 16:39:11 +01:00
bdaneels
6c7aa018cd 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.
2024-12-03 15:16:45 +01:00
bdaneels
05a1b85801 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.
2024-12-03 14:16:44 +01:00
bdaneels
3b4ccefa66 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.
2024-11-27 16:39:20 +01:00
8 changed files with 255 additions and 15 deletions

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
node_modules node_modules
vars.js vars.js
.idea
*.xlsx

35
appendResultsToExcel.js Normal file
View 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;

View File

@ -1,6 +1,10 @@
// Vars
const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]'; const IFRAME_SELECTOR = 'iframe[title="Hoofdinhoud"]';
const CELL_SELECTOR = const CELL_SELECTOR =
'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]'; 'a[title="Sectie uitvouwen Algemene opleidingsonderdelen"]';
const STUDENT_NAME_CELL_SELECTOR = 'span[id="DERIVED_SCC_SUM_PERSON_NAME$5$"]'
const STUDENT_ID_CELL_SELECTOR = 'span[id="SCC_PERS_SA_VW_EMPLID"]'
const STPKT_KEUZE_CELL_SELECTOR = 'a[title="Sectie uitvouwen Keuzeopleidingsonderdelen"]'
/** /**
* Extracted function to get the text content of a node. * Extracted function to get the text content of a node.
@ -37,20 +41,28 @@ async function isStartPakketAvailable(page) {
const contentFrame = await getContentFrame(page); const contentFrame = await getContentFrame(page);
await contentFrame.waitForSelector(CELL_SELECTOR); await contentFrame.waitForSelector(CELL_SELECTOR);
const cell = await contentFrame.$(CELL_SELECTOR); const cell = await contentFrame.$(CELL_SELECTOR);
const cell_keuze = await contentFrame.$(STPKT_KEUZE_CELL_SELECTOR)
if (!cell) { if (!cell ) {
throw new Error( throw new Error(
"Cell inside function isStartPakketAvailable is not defined" "Cell inside function isStartPakketAvailable is not defined"
); );
} }
const isCollapsed = await isAriaExpandedFalse(cell); //object vars
const isCollapsed_main = await isAriaExpandedFalse(cell);
console.log(`Aria-expanded: ${isCollapsed}`); const isCollapsed_keuze = await getIsCollapsedKeuze(cell_keuze);
const isCollapsed = isCollapsed_main && isCollapsed_keuze;
const studName = await getStudName(contentFrame);
const studId = await getStudId(contentFrame);
return { return {
isCollapsed: isCollapsed, isCollapsed: isCollapsed,
// Add more properties here in the future as needed isCollapsed_main: isCollapsed_main,
isCollapsed_keuze: isCollapsed_keuze,
studName: studName,
studId: studId,
// more properties here
}; };
} }
@ -69,4 +81,28 @@ async function isAriaExpandedFalse(node) {
); );
} }
async function getIsCollapsedKeuze(cell_keuze) {
if (cell_keuze) {
return await isAriaExpandedFalse(cell_keuze);
} else {
return false;
}
}
async function getStudName(frame) {
const cell = await frame.$(STUDENT_NAME_CELL_SELECTOR);
if (!cell) {
throw new Error("Cell student name is not defined");
}
return await getNodeTextContent(cell);
}
async function getStudId(frame) {
const cell = await frame.$(STUDENT_ID_CELL_SELECTOR);
if (!cell) {
throw new Error("Cell student id is not defined");
}
return await getNodeTextContent(cell);
}
module.exports = isStartPakketAvailable; module.exports = isStartPakketAvailable;

View File

@ -6,6 +6,10 @@ start dan het script
*/ */
const puppeteer = require("puppeteer"); const puppeteer = require("puppeteer");
const isStartPakketAvailable = require("./evaluateStartPakket"); const isStartPakketAvailable = require("./evaluateStartPakket");
const fs = require("fs");
const saveResultsToExcel = require("./saveResultsToExcel");
const appendToExcel = require("./appendResultsToExcel");
const wait = require("./wait");
async function iterateOverDashboardTable() { async function iterateOverDashboardTable() {
/*connection to local host */ /*connection to local host */
@ -13,6 +17,10 @@ async function iterateOverDashboardTable() {
browserURL: "http://localhost:9222", // Connect to the browser's debugging address browserURL: "http://localhost:9222", // Connect to the browser's debugging address
}); });
//array to store results for Excel export
let results = []
const filename = "DashboardResults.xlsx"
// Get all open pages (tabs) // Get all open pages (tabs)
const pages = await browser.pages(); const pages = await browser.pages();
console.log(`Found ${pages.length} open pages on the browser.`); console.log(`Found ${pages.length} open pages on the browser.`);
@ -49,6 +57,13 @@ async function iterateOverDashboardTable() {
); );
console.log(`Found ${links.length} AA-links to process.`); 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++) { for (let i = 0; i < links.length; i++) {
console.log(`Processing link ${i + 1}`); console.log(`Processing link ${i + 1}`);
@ -61,6 +76,12 @@ async function iterateOverDashboardTable() {
`${tableBodySelector} tr span[title="AA-rapport"] a` `${tableBodySelector} tr span[title="AA-rapport"] a`
); );
if ((i + 1) % 10 === 0) {
console.log('Simulating break, waiting 10 seconds to stay under the radar :)')
await wait(10000)
}
const [newPagePromise] = await Promise.all([ const [newPagePromise] = await Promise.all([
new Promise((resolve) => new Promise((resolve) =>
browser.once("targetcreated", async (target) => { browser.once("targetcreated", async (target) => {
@ -70,24 +91,49 @@ async function iterateOverDashboardTable() {
), ),
links[i].click(), // Simulate the click links[i].click(), // Simulate the click
]); ]);
let result;
const newPage = await newPagePromise; const newPage = await newPagePromise;
try { try {
const evaluationResult = await isStartPakketAvailable(newPage); const evaluationResult = await isStartPakketAvailable(newPage);
if (evaluationResult.isCollapsed) { //Save results for Excel
console.log(`Evaluation succeeded for link ${i + 1}`); result = ({
} else { LinkNumber: i +1,
console.log(`Evaluation failed for link ${i + 1}`); StudentName: evaluationResult.studName || 'N/A',
} StudentID: evaluationResult.studId || "N/A",
IsCollapsed: evaluationResult.isCollapsed ? "Yes" : "No",
IsCollapsedKeuze: evaluationResult.isCollapsed_keuze ? "Yes" : "No",
IsCollapsedMain: evaluationResult.isCollapsed_main ? "Yes" : "No",
})
console.log(`Link ${i + 1 } processed successfully.`);
} catch (error) { } catch (error) {
console.error(`Error processing link ${i + 1}:`, error.message); console.error(`Error processing link ${i + 1}:`, error.message);
// Save error for Excel
result = ({
LinkNumber: i + 1,
StudentName: "Error",
StudentID: "Error",
IsCollapsed: "Error",
IsCollapsedKeuze: "Error",
IsCollapsedMain: "Error",
ErrorStr: error.message,
});
} }
finally {
await newPage.close(); await newPage.close();
}
results.push(result);
appendToExcel(result, filename);
} }
console.log("All links processed."); console.log("All links processed.");
saveResultsToExcel(results, "DashboardResults.xlsx");
console.log("Results saved successfully to DashboardResults.xlsx");
} }
module.exports = iterateOverDashboardTable(); module.exports = iterateOverDashboardTable();

106
package-lock.json generated
View File

@ -9,7 +9,8 @@
"version": "1.0.0", "version": "1.0.0",
"dependencies": { "dependencies": {
"inquirer": "^12.1.0", "inquirer": "^12.1.0",
"puppeteer": "^23.7.0" "puppeteer": "^23.7.0",
"xlsx": "^0.18.5"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
@ -333,6 +334,15 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/adler-32": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz",
"integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/agent-base": { "node_modules/agent-base": {
"version": "7.1.1", "version": "7.1.1",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz",
@ -525,6 +535,19 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/cfb": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz",
"integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==",
"license": "Apache-2.0",
"dependencies": {
"adler-32": "~1.3.0",
"crc-32": "~1.2.0"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/chardet": { "node_modules/chardet": {
"version": "0.7.0", "version": "0.7.0",
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
@ -568,6 +591,15 @@
"node": ">=12" "node": ">=12"
} }
}, },
"node_modules/codepage": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz",
"integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/color-convert": { "node_modules/color-convert": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@ -612,6 +644,18 @@
} }
} }
}, },
"node_modules/crc-32": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
"license": "Apache-2.0",
"bin": {
"crc32": "bin/crc32.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/data-uri-to-buffer": { "node_modules/data-uri-to-buffer": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz",
@ -801,6 +845,15 @@
"pend": "~1.2.0" "pend": "~1.2.0"
} }
}, },
"node_modules/frac": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz",
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/fs-extra": { "node_modules/fs-extra": {
"version": "11.2.0", "version": "11.2.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz",
@ -1370,6 +1423,18 @@
"integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==",
"license": "BSD-3-Clause" "license": "BSD-3-Clause"
}, },
"node_modules/ssf": {
"version": "0.11.2",
"resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz",
"integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==",
"license": "Apache-2.0",
"dependencies": {
"frac": "~1.1.2"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/streamx": { "node_modules/streamx": {
"version": "2.20.1", "version": "2.20.1",
"resolved": "https://registry.npmjs.org/streamx/-/streamx-2.20.1.tgz", "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.20.1.tgz",
@ -1514,6 +1579,24 @@
"integrity": "sha512-H/A06tKD7sS1O1X2SshBVeA5FLycRpjqiBeqGKmBwBDBy28EnRjORxTNe269KSSr5un5qyWi1iL61wLxpd+ZOg==", "integrity": "sha512-H/A06tKD7sS1O1X2SshBVeA5FLycRpjqiBeqGKmBwBDBy28EnRjORxTNe269KSSr5un5qyWi1iL61wLxpd+ZOg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/wmf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz",
"integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/word": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz",
"integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/wrap-ansi": { "node_modules/wrap-ansi": {
"version": "7.0.0", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
@ -1558,6 +1641,27 @@
} }
} }
}, },
"node_modules/xlsx": {
"version": "0.18.5",
"resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz",
"integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==",
"license": "Apache-2.0",
"dependencies": {
"adler-32": "~1.3.0",
"cfb": "~1.2.1",
"codepage": "~1.15.0",
"crc-32": "~1.2.1",
"ssf": "~0.11.2",
"wmf": "~1.0.1",
"word": "~0.3.0"
},
"bin": {
"xlsx": "bin/xlsx.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/y18n": { "node_modules/y18n": {
"version": "5.0.8", "version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",

View File

@ -9,6 +9,7 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"inquirer": "^12.1.0", "inquirer": "^12.1.0",
"puppeteer": "^23.7.0" "puppeteer": "^23.7.0",
"xlsx": "^0.18.5"
} }
} }

11
saveResultsToExcel.js Normal file
View File

@ -0,0 +1,11 @@
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
xlsx.utils.book_append_sheet(workbook, worksheet, "Results"); // Add worksheet to workbook
// Write workbook to file
xlsx.writeFile(workbook, filename);
}
module.exports = saveResultsToExcel;

5
wait.js Normal file
View File

@ -0,0 +1,5 @@
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports = wait;