Last active
December 29, 2020 00:36
-
-
Save asciidiego/a93533d614e1de6ab84de657cdd3794f to your computer and use it in GitHub Desktop.
Extract question answers from GRE Magoosh Review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scrapeQuestionsFromMagooshReviewPage() { | |
// I think this only works on Firefox, since they add the tbody element. | |
const table = $('tbody tr') | |
const questions = []; | |
for(let node of table) { | |
const cleanText = t => t.replace(/\n/g,''); | |
const parsedNode = { | |
correct: node.querySelector('.correct-sprite') != null, | |
title: node.querySelectorAll('td')[1].textContent, | |
section: node.querySelectorAll('td')[2].textContent, | |
subject: node.querySelectorAll('td')[3].textContent, | |
difficulty: node.querySelectorAll('td')[4].textContent, | |
userPace: node.querySelectorAll('td')[5].textContent, | |
globalPace: node.querySelectorAll('td')[6].textContent, | |
latestDate: node.querySelectorAll('td')[7].textContent, | |
} | |
const processedNode = { | |
...parsedNode, | |
difficulty: cleanText(parsedNode.difficulty), | |
userPace: cleanText(parsedNode.userPace), | |
globalPace: cleanText(parsedNode.globalPace), | |
}; | |
questions.push(processedNode); | |
} | |
return questions; | |
} | |
function groupBy(data, groupingKey) { | |
return data.reduce( | |
(accumulated, currentSample) => { | |
(accumulated[currentSample[groupingKey]] = accumulated[currentSample[groupingKey]] || []).push(currentSample); | |
return accumulated; | |
}, {} | |
); | |
} | |
function performanceSummary(questions) { | |
const groups = groupBy(questions, 'subject'); | |
const subjects = Object.keys(groups); | |
const resultsBySubject = subjects.reduce((accum, curr) => { | |
const currentSubject = groups[curr]; | |
const currentSubjectResults = currentSubject.map(s => s.correct); | |
const currentSubjectScore = currentSubjectResults.reduce((accum, curr) => accum + curr); | |
const scoreFractionString = `${+currentSubjectScore}/${currentSubjectResults.length}`; | |
const scorePercentage = Math.round(+currentSubjectScore/currentSubjectResults.length * 10000) / 100; | |
accum[curr] = `${scoreFractionString} (${scorePercentage}%)`; | |
return accum; | |
}, {}); | |
return resultsBySubject; | |
} | |
const questions = scrapeQuestionsFromMagooshReviewPage(); | |
const scoreSummary = performanceSummary(questions); | |
console.table(scoreSummary); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment