From 74e62a80677d5158b0573d37e27e59030a5fa7d8 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Thu, 4 Jan 2024 18:51:59 +0530 Subject: sortable tables --- index.html | 111 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 68 insertions(+), 43 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index e403cdc..201bee2 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ CU Boulder Grades Database - + @@ -14,7 +14,7 @@

iNeedATitle

Loading database...

- +
@@ -44,6 +44,30 @@
+
+

By Subject

+

...

+
+

By A&S Division

+

Useful for finding electives

+

Find classes, and average grade for a given A&S Division

+ + + + + +
+
+


@@ -127,18 +151,13 @@ }, null, 2); } - function getClassesByInstructor() { - let instructor = document.getElementById("instructor").value; - - let query = `SELECT Subject || ' ' || Course as "Class", CourseTitle as "Title", GROUP_CONCAT(DISTINCT YearTerm) AS YearTerms, ROUND(AVG(AVG_GRD), 2) AS "Average Grade", ROUND(AVG(PCT_A), 2) as "% A", ROUND(AVG(PCT_B), 2) as "% B", ROUND(AVG(PCT_C_MINUS_OR_BELOW), 2) as "% C- and below", ROUND(AVG(N_GRADE)) as "Average No. of Students" FROM raw_data AS main WHERE insname1 = "${instructor.toUpperCase()}" OR insname2 = "${instructor.toUpperCase()}" OR insname3 = "${instructor.toUpperCase()}" GROUP BY CourseTitle` - console.log(query); - - const results = db.exec(query); + function createTable(results, className) { const result = results[0]; const columns = result.columns; const rows = result.values; - const tableContainer = document.getElementById("table-container"); + const tableContainer = document.getElementById(className); const table = document.createElement("table"); + table.classList.add("sortable") const thead = document.createElement("thead"); const tbody = document.createElement("tbody"); const headerRow = document.createElement("tr"); @@ -173,48 +192,54 @@ tableContainer.appendChild(table); } + function getClassesByInstructor() { + let instructor = document.getElementById("instructor").value; + + let query = `SELECT Subject || ' ' || Course as "Class", CourseTitle as "Title", GROUP_CONCAT(DISTINCT YearTerm) AS YearTerms, ROUND(AVG(AVG_GRD), 2) AS "Average Grade", ROUND(AVG(PCT_A), 2) as "% A", ROUND(AVG(PCT_B), 2) as "% B", ROUND(AVG(PCT_C_MINUS_OR_BELOW), 2) as "% C- and below", ROUND(AVG(N_GRADE)) as "Average No. of Students" FROM raw_data AS main WHERE insname1 = "${instructor.toUpperCase()}" OR insname2 = "${instructor.toUpperCase()}" OR insname3 = "${instructor.toUpperCase()}" GROUP BY CourseTitle` + console.log(query); + + const results = db.exec(query); + createTable(results, "table-container") + sorttable.makeSortable(document.getElementById("table-container").children[0]); + } + function getClassesByClassCode() { let classCode = document.getElementById("classCode").value; - let query = `SELECT YearTerm as "Year-Term", insname1 as Instructor, AVG_GRD as "Average Grade", PCT_A as "% A", PCT_B as "% B", PCT_C_MINUS_OR_BELOW as "% C- and below", N_GRADE as "No. Graded" FROM raw_data WHERE Subject || ' ' || Course = '${classCode.toUpperCase()}';` + let query = `SELECT YearTerm as "YearTerms", insname1 as Instructor, AVG_GRD as "Average Grade", PCT_A as "% A", PCT_B as "% B", PCT_C_MINUS_OR_BELOW as "% C- and below", N_GRADE as "No. Graded" FROM raw_data WHERE Subject || ' ' || Course = '${classCode.toUpperCase()}';` const results = db.exec(query); - const result = results[0]; - const columns = result.columns; - const rows = result.values; - const tableContainer = document.getElementById("table-container-class-codes"); - const table = document.createElement("table"); - const thead = document.createElement("thead"); - const tbody = document.createElement("tbody"); - const headerRow = document.createElement("tr"); + createTable(results, "table-container-class-codes") + sorttable.makeSortable(document.getElementById("table-container-class-codes").children[0]); + } - for (let i = 0; i < columns.length; i++) { - const headerCell = document.createElement("th"); - headerCell.textContent = columns[i]; - headerRow.appendChild(headerCell); + function getClassesByDivision() { + let division = document.getElementById("division").value + let grade = document.getElementById("grade").value + + switch (grade) { + case 'upper': + grade = "BETWEEN 3000 and 4999"; + break; + case 'lower': + grade = "BETWEEN 0000 and 2999"; + break; + case 'both': + grade = "BETWEEN 0000 and 4999"; + break; + case 'grad': + grade = ">= 5000" + break; + default: + grade = ">= 0"; } - thead.appendChild(headerRow); + let query = `SELECT DISTINCT Subject || ' ' || Course AS "Class Code", CourseTitle as "Title", AVG(AVG_GRD) AS "Average Grade" FROM raw_data WHERE (CrsPBADiv = '${division}' AND COURSE ${grade} ) AND Subject != 'APPM' GROUP BY "Class Code", "Title"` - for (let i = 0; i < rows.length; i++) { - const row = document.createElement("tr"); - for (let j = 0; j < rows[i].length; j++) { - const cell = document.createElement("td"); - if (columns[j] === "Year-Term") { - cell.textContent = convertYearTerm(rows[i][j]); - } else if (!isNaN(rows[i][j]) && rows[i][j] !== null) { - cell.textContent = parseFloat(rows[i][j]).toFixed(2); - } else { - cell.textContent = rows[i][j]; - } - row.appendChild(cell); - } - tbody.appendChild(row); - } + console.log(query); - table.appendChild(thead); - table.appendChild(tbody); - tableContainer.innerHTML = ""; - tableContainer.appendChild(table); + const results = db.exec(query); + createTable(results, "table-container-division") + sorttable.makeSortable(document.getElementById("table-container-division").children[0]); } function convertYearTerm(yearTerms) { -- cgit v1.2.3