Last active
February 19, 2018 10:40
-
-
Save bradleyjkemp/48dffd09a4ffe25f10a805aeae228b0d to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Part II Supervision Calculator</title> | |
</head> | |
<body> | |
<div id="result"></div> | |
<br> | |
<div id="buttons"></div> | |
<script type="text/javascript"> | |
var courses = [ | |
course("<b>Michaelmas</b>", [], 0), | |
course("Bioinformatics", [7, 9], 3), | |
course("Business Studies", [7], 2), | |
course("Denotational Semantics", [7,9], 3), | |
course("DSP", [8,9], 3), | |
course("HCI", [7], 2), | |
course("Information Theory", [7,9], 3), | |
course("NLP", [7,9], 3), | |
course("Principles of Communications", [7,8,9], 6), | |
course("Quantum Computing", [8], 2), | |
course("Types", [8,9], 3), | |
course("", [], 0), | |
course("<b>Lent</b>", [], 0), | |
course("Advanced Graphics", [7,8], 4), | |
course("Comparative Architectures", [7, 8], 4), | |
course("Computer Systems Modelling", [8,9], 3), | |
course("Computer Vision", [8,9], 4), | |
course("E-commerce", [8], 2), | |
course("Information Retrieval", [8], 2), | |
course("Machine Learning", [7,8], 4), | |
course("Mobile and sensor systems", [8,9], 3), | |
course("Optimising Compilers", [7,9], 4), | |
course("Security II", [7,8], 4), | |
course("SoC Design", [8,9], 3), | |
course("Topical Issues", [9], 2), | |
course("", [], 0), | |
course("<b>Easter</b>", [], 0), | |
course("Hoare Logic and Model Checking", [7,9], 3), | |
course("Advanced Algorithms", [7, 9], 3), | |
] | |
function course(name, papers, supervisions) { | |
checkbox = document.createElement('input') | |
checkbox.setAttribute('type', 'checkbox') | |
checkbox.addEventListener('change', calculate) | |
checkbox.setAttribute('id', name) | |
checkbox.setAttribute('name', name) | |
checkbox.metadata = { | |
name: name, | |
papers: papers, | |
supervisions: supervisions, | |
} | |
return checkbox | |
} | |
function calculate() { | |
console.log('calculating') | |
var papersTotal = { | |
7: 0, | |
8: 0, | |
9: 0, | |
} | |
var supervisionTotal = 0 | |
courses.forEach(function (course) { | |
if (course.checked) { | |
course.metadata.papers.forEach(function (paper) { | |
papersTotal[paper] += 1 | |
}) | |
supervisionTotal += course.metadata.supervisions | |
} | |
}) | |
result = document.getElementById('result') | |
result.innerHTML = '' | |
for (var paper in papersTotal) { | |
var line = document.createElement('div') | |
line.innerHTML = 'Paper '+paper+': '+papersTotal[paper] | |
result.appendChild(line) | |
} | |
line = document.createElement('div') | |
line.innerHTML = 'Supervisions: '+supervisionTotal | |
result.appendChild(line) | |
} | |
function render() { | |
buttons = document.getElementById('buttons') | |
courses.forEach(function (button) { | |
buttons.appendChild(button) | |
text = document.createElement('span') | |
text.innerHTML = button.metadata.name+" "+button.metadata.papers+"<br>" | |
buttons.appendChild(text) | |
}) | |
calculate() | |
} | |
if (window.addEventListener) window.addEventListener("load", render, false); | |
else if (window.attachEvent) window.attachEvent("onload", render); | |
else window.onload = render; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment