Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,5 +783,13 @@ modulesData =
}
],
"totalCredits": 60
},
"year3": {
"modules": [],
"totalCredits": 60
},
"year4": {
"modules": [],
"totalCredits": 60
}
}
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ <h1 class="topText">Imperial CS Tracker</h1>
<div class="tabs">
<button class="tablinks" onclick="switchCourse('year1')" id="year1">Computing Year 1</button>
<button class="tablinks" onclick="switchCourse('year2')" id="year2">Computing Year 2</button>
<button class="tablinks" onclick="switchCourse('year3')" id="year3">Computing Year 3</button>
<button class="tablinks" onclick="switchCourse('year4')" id="year4">Computing Year 4</button>
</div>

<div id="main">
Expand Down
180 changes: 174 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,85 @@ function loadCourseData(course) {
const data = modulesData[course];
html = "<tr><th>Module</th><th>Tasks</th><th>Score</th></tr>"
for(const module of data.modules){
for(const task of module.tasks){
if(task.id=='a'){
html += `<tr><td rowspan="${module.tasks.length}"><span class="module">${module.name}</span><br><span class="small">(${module.credits} credits - ${(module.credits/data.totalCredits*100).toFixed(2)}%)</span><br><b id="p${module.id}">0.00%</b><br><br><div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="${'b'+module.id}"></div></div><span class="small" id="${'m'+module.id}">--/100% of module</span><br><span class="small" id="${'a'+module.id}">--/--% of all</span><div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="${'bc'+module.id}"></div></div><span class="small" id="${'mc'+module.id}">--/--% of module</span><br><span class="small" id="${'ac'+module.id}">--/--% of all</span></td>`
}else{
html += `<tr>`
for (const task of module.tasks) {
// Module cell
if (task.id == 'a') {
html += `<tr>
<td rowspan="${module.tasks.length}">
<span class="module">${module.name}</span><br>
<span class="small">(${module.credits} credits - ${(module.credits / data.totalCredits * 100).toFixed(2)}%)</span><br>
<b id="p${module.id}">0.00%</b><br><br>
<div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="b${module.id}"></div></div>
<span class="small" id="m${module.id}">--/100% of module</span><br>
<span class="small" id="a${module.id}">--/--% of all</span>
<div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="bc${module.id}"></div></div>
<span class="small" id="mc${module.id}">--/--% of module</span><br>
<span class="small" id="ac${module.id}">--/--% of all</span>
${(course === 'year3' || course === 'year4') ? `<br><button onclick="deleteModule(${module.id})" style="margin-top: 5px;">Delete Module</button>` : ''}
</td>`;
} else {
html += `<tr>`;
}

// Task cells
const isCustomYear = (course === 'year3' || course === 'year4');
if (isCustomYear) {
html += `
<td class="${task.type}">${task.name}</br>
<span class="small">(${(task.weight * 100).toFixed(2)}%)</span><br>
</td>
<td>
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
<div>
Score: <input type="number" min="0" max="${task.maxScore}" id="i${module.id + task.id}" onchange="update()"> /${task.maxScore}
</div>
<div>
Weight: <input type="number" min="0" max="100" step="0.1" value="${(task.weight * 100).toFixed(1)}"
id="w${module.id + task.id}" onchange="updateWeight(${module.id}, '${task.id}')" style="width: 60px">%
</div>
</div>
<div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="b${module.id + task.id}"></div></div>
<span class="small" id="t${module.id + task.id}">--/100% of ${task.type === 'test' ? 'exam' : 'coursework'}</span><br>
<span class="small" id="m${module.id + task.id}">--/100% of module</span><br>
<span class="small" id="a${module.id + task.id}">--/100% of all</span>
</td>
</tr>`;
} else {
html += `
<td class="${task.type}">${task.name}<br>
<span class="small">(${(task.weight * 100).toFixed(2)}%)</span><br>
<span class="small">(${task.date})</span>
</td>
<td>
<input type="number" min="0" max="${task.maxScore}" id="i${module.id + task.id}" onchange="update()"> /${task.maxScore}
<div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="b${module.id + task.id}"></div></div>
<span class="small" id="t${module.id + task.id}">--/100% of task</span><br>
<span class="small" id="m${module.id + task.id}">--/100% of module</span><br>
<span class="small" id="a${module.id + task.id}">--/100% of all</span>
</td>
</tr>`;
}
html += `<td class="${task.type}">${task.name}<br><span class="small">(${(task.weight*100).toFixed(2)}%)</span><br><span class="small">(${task.date})</span></td><td><input type="number" min="0" max="${task.maxScore}" id="${'i'+module.id+task.id}" onchange="update()"> /${task.maxScore}<div class="progress-bar"><div class="progress-bar-inner" style="width:0%" id="${'b'+module.id+task.id}"></div></div><span class="small" id="${'t'+module.id+task.id}">--/100% of task</span><br><span class="small" id="${'m'+module.id+task.id}">--/100% of module</span><br><span class="small" id="${'a'+module.id+task.id}">--/100% of all</span></td></tr>`
}
}

// Add the new module section for year 3 and year 4
if (course === 'year3' || course === 'year4') {
html += `
<tr>
<td colspan="3" style="text-align: center; padding: 20px; background-color: rgba(204,136,255,0.1);">
<h3>Add New Module</h3>
<input type="text" id="newModuleName" placeholder="module name" style="margin: 5px;"><br>
<input type="number" id="newModuleCredits" placeholder="credits" style="margin: 5px;"><br>
<input type="number" id="newTaskCount" placeholder="num of courseworks" style="margin: 5px;"><br>
<select id="hasExam" style="margin: 5px;">
<option value="yes">Exam</option>
<option value="no">No Exam</option>
</select><br>
<button onclick="addNewModule()" style="margin: 5px;">Add Module</button>
</td>
</tr>
`;
}
return html
}

Expand Down Expand Up @@ -122,7 +192,105 @@ function update(){
saveCourseScore(currentCourse);
}

function addNewModule() {
const moduleName = document.getElementById('newModuleName').value;
const moduleCredits = parseFloat(document.getElementById('newModuleCredits').value);
const courseworkCount = parseInt(document.getElementById('newTaskCount').value);

if (!moduleName || isNaN(moduleCredits) || isNaN(courseworkCount) || courseworkCount < 0) {
alert('Please fill in all fields correctly');
return;
}

const hasExam = document.getElementById('hasExam').value === 'yes';
const examWeight = hasExam ? 0.8 : 0; // 80% weight for exam if it exists
const remainingWeight = 1 - examWeight;

const newModule = {
id: modulesData[currentCourse].modules.length,
name: moduleName,
credits: moduleCredits,
tasks: []
};

for (let i = 0; i < courseworkCount; i++) {
newModule.tasks.push({
id: String.fromCharCode(97 + i), // a, b, c, ...
name: `CW${i + 1}`,
type: 'cw',
maxScore: 100,
weight: remainingWeight / courseworkCount,
date: 'TBD'
});
}

if (hasExam) {
newModule.tasks.push({
id: String.fromCharCode(97 + courseworkCount),
name: 'Final Exam',
type: 'test',
maxScore: 100,
weight: examWeight,
date: 'TBD'
});
}

modulesData[currentCourse].modules.push(newModule);
modulesData[currentCourse].totalCredits = modulesData[currentCourse].modules.reduce((sum, module) => sum + module.credits, 0);
saveCourseData(currentCourse);
switchCourse(currentCourse);
}

function deleteModule(moduleId) {
modulesData[currentCourse].modules = modulesData[currentCourse].modules.filter(m => m.id !== moduleId);
modulesData[currentCourse].totalCredits = modulesData[currentCourse].modules.reduce((sum, module) => sum + module.credits, 0);
saveCourseData(currentCourse);
switchCourse(currentCourse);
}

function updateWeight(moduleId, taskId) {
const module = modulesData[currentCourse].modules.find(m => m.id === moduleId);
const task = module.tasks.find(t => t.id === taskId);
const weightInput = document.getElementById('w' + moduleId + taskId);
const newWeightPercent = parseFloat(weightInput.value);

if (isNaN(newWeightPercent) || newWeightPercent < 0 || newWeightPercent > 100) {
alert('Weight must be between 0 and 100');
weightInput.value = (task.weight * 100).toFixed(1);
return;
}

// Calculate total of other weights
const totalOtherWeights = module.tasks
.filter(t => t.id !== taskId)
.reduce((sum, t) => sum + t.weight, 0);

if (totalOtherWeights + (newWeightPercent / 100) > 1) {
alert('Total weights cannot exceed 100%. Current other weights: ' +
(totalOtherWeights * 100).toFixed(1) + '%');
weightInput.value = (task.weight * 100).toFixed(1);
return;
}

task.weight = newWeightPercent / 100;
saveCourseData(currentCourse);
update();
}

function saveCourseData(course) {
localStorage['moduleData_' + course] = JSON.stringify(modulesData[course]);
}

function loadSavedCourseData(course) {
const savedData = localStorage['moduleData_' + course];
if (savedData) {
modulesData[course] = JSON.parse(savedData);
}
}

window.onload = function() {
fixScore();
loadSavedCourseData('year3'); // Load custom year 3 modules
loadSavedCourseData('year4'); // Load custom year 4 modules
switchCourse(currentCourse);
}