From 0d976023eb0622d91428ad1150fdfd5304424a09 Mon Sep 17 00:00:00 2001
From: andrewzpu <66804382+andrewzpu@users.noreply.github.com>
Date: Wed, 8 May 2024 01:39:24 -0700
Subject: [PATCH 01/11] Set Up House Points Tracker
---
frontend/src/Pages/House.svelte | 177 ++++++++++++++++++++++++++++++++
1 file changed, 177 insertions(+)
create mode 100644 frontend/src/Pages/House.svelte
diff --git a/frontend/src/Pages/House.svelte b/frontend/src/Pages/House.svelte
new file mode 100644
index 00000000..5a68ae26
--- /dev/null
+++ b/frontend/src/Pages/House.svelte
@@ -0,0 +1,177 @@
+
+
+
+
+
+
+
+
+
+
Houses
+
+ {#if window.innerWidth > 769}
+
+
+
+ {:else}
+
+
+
+ {/if}
+
+
+
\ No newline at end of file
From c52acfc51e707d9d42490151adb1f7e977d51cb1 Mon Sep 17 00:00:00 2001
From: andrewzpu <66804382+andrewzpu@users.noreply.github.com>
Date: Wed, 8 May 2024 01:42:36 -0700
Subject: [PATCH 02/11] Added house tab to side bar
---
frontend/src/Components/Sidebar.svelte | 1 +
1 file changed, 1 insertion(+)
diff --git a/frontend/src/Components/Sidebar.svelte b/frontend/src/Components/Sidebar.svelte
index e42bb64d..8a56228b 100644
--- a/frontend/src/Components/Sidebar.svelte
+++ b/frontend/src/Components/Sidebar.svelte
@@ -67,6 +67,7 @@
{#if adminStatus}
InducteesOutreach
+ Houses
{/if}
Logout
From b344e365a0e58a62b89b68018a182a0deec89243 Mon Sep 17 00:00:00 2001
From: andrewzpu <66804382+andrewzpu@users.noreply.github.com>
Date: Wed, 8 May 2024 01:47:25 -0700
Subject: [PATCH 03/11] Forgot to include route in App.svelte
---
frontend/src/App.svelte | 2 ++
frontend/src/Components/Sidebar.svelte | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte
index e8b669a3..b7d83b34 100644
--- a/frontend/src/App.svelte
+++ b/frontend/src/App.svelte
@@ -8,6 +8,7 @@
//import ProfileEdit from "./Pages/ProfileEdit.svelte";
import Inductees from "./Pages/Inductees.svelte";
import Outreach from "./Pages/Outreach.svelte";
+ import House from "./Pages/House.svelte";
async function getAdminStatus() {
let response = await fetch(`/api/permissions/`);
@@ -45,6 +46,7 @@
+
diff --git a/frontend/src/Components/Sidebar.svelte b/frontend/src/Components/Sidebar.svelte
index 8a56228b..b109356d 100644
--- a/frontend/src/Components/Sidebar.svelte
+++ b/frontend/src/Components/Sidebar.svelte
@@ -67,7 +67,7 @@
{#if adminStatus}
InducteesOutreach
- Houses
+ Houses
{/if}
Logout
From c5ed89c1a1687a8fe40cf8133ea92a89c0c6bd82 Mon Sep 17 00:00:00 2001
From: andrewzpu <66804382+andrewzpu@users.noreply.github.com>
Date: Sun, 26 May 2024 23:18:30 -0700
Subject: [PATCH 04/11] Changed House Points Chart to include switching to Bar
Chart
---
frontend/src/Pages/House.svelte | 113 ++++++++++++++++++++++------
frontend/src/Pages/Inductees.svelte | 2 +-
2 files changed, 93 insertions(+), 22 deletions(-)
diff --git a/frontend/src/Pages/House.svelte b/frontend/src/Pages/House.svelte
index 5a68ae26..1ca13f41 100644
--- a/frontend/src/Pages/House.svelte
+++ b/frontend/src/Pages/House.svelte
@@ -1,6 +1,5 @@
@@ -15,7 +14,7 @@
// key should be safe to leave public since it is restricted to only the spreadsheet api
const key = "AIzaSyAlVjsRdCfuHsRt5RXriI2dLDrAjwMiP0Y"
const year1 = 2023 // change year based on firsty half of school year (ie 24/25 --> year1 = 2024)
- const title = "House Points Spring 2024"
+ const title = "Spring 2024 Points"
const colors = ['Orange', 'Green', 'Purple', 'Yellow', 'Blue']
// Range D1 to Z1 is to get house names (assuming they may change)
@@ -37,6 +36,7 @@
let houses = [];
let max = 0;
+ // get list of house names from spreadsheet (in case they change)
fetch(housesURL)
.then(res => {
return res.json();
@@ -47,7 +47,7 @@
})
.catch(error => console.log(error));
-
+ // get points data from spreadsheet
fetch(dataURL)
.then(res => {
return res.json();
@@ -61,12 +61,14 @@
function updateData() {
let currRow = 0;
- dateData = [];
numData = [];
hoverData = [];
+
+ // Keeps track of accumulating scores over time (each spreadsheet row only shows points earned at that event)
prevTemp = [0,0,0,0,0]
while(data[currRow][0] != '') {
+ // get dates
const dateString = data[currRow][0]
const month = parseInt(dateString.substring(0, dateString.indexOf('/'))) - 1
const day = parseInt(dateString.substring(dateString.indexOf('/') + 1))
@@ -78,12 +80,16 @@
let numTemp = data[currRow].slice(3)
let hoverTemp = []
+ // for each row of data, add point values on top of existing point values
for (let i = 0; i < numTemp.length; i++) {
numTemp[i] = parseFloat(numTemp[i]) + prevTemp[i];
- hoverTemp.push(numTemp[i] + "\n" + data[currRow][i + 3] + " points earned\n" + data[currRow][1] + "\n" + date.toLocaleDateString('en-US'))
+ hoverTemp.push("House " + houses[i] + "\n" + "\n" + numTemp[i] + " Points\n" + data[currRow][i + 3] + " points earned\n" + data[currRow][1] + date.toLocaleDateString("en-US"))
}
- dateData.push(date)
+
+ // numData is all the points data
numData.push(numTemp)
+
+ // hoverData is the tooltips that appear when hovering over a point on the line graph
hoverData.push(hoverTemp)
currRow++;
prevTemp = numTemp;
@@ -93,38 +99,48 @@
max = Math.max(...rowMax) * 1.3
}
+ // on resize, redraw the chart to fit hopefully
window.addEventListener("resize", () => {
tryDrawChart();
});
function tryDrawChart() {
- console.log("try");
+ // first make sure that data has been retrieved
if (!data || houses.length === 0) {
return;
}
- console.log("success")
-
updateData();
- var dataTable = new google.visualization.DataTable();
- dataTable.addColumn('date', 'Day');
+ // Building Line Chart
+
+ var lineDataTable = new google.visualization.DataTable();
+ lineDataTable.addColumn('number', 'Event Number');
for (let i = 0; i < houses.length; i++) {
- dataTable.addColumn('number', houses[i]);
- dataTable.addColumn({type:'string', role:'tooltip'});
+ lineDataTable.addColumn('number', houses[i]);
+ lineDataTable.addColumn({type:'string', role:'tooltip'});
}
+
+ // Initialize Starting Point (all houses start at 0 points)
+ let startRow = [0]
+ for (let i = 0; i < houses.length; i++) {
+ startRow.push(0)
+ startRow.push("House " + houses[i] + "\nStarting Point\n0 Points")
+ }
+ lineDataTable.addRow(startRow)
+ // add each row of data (each row represents 1 event)
for (let i = 0; i < numData.length; i++) {
- let newRow = [dateData[i]]
+ let newRow = [i + 1]
for (let j = 0; j < houses.length; j++) {
newRow.push(numData[i][j])
newRow.push(hoverData[i][j]);
}
- dataTable.addRow(newRow)
+ lineDataTable.addRow(newRow)
}
- var options = {
+ var lineOptions = {
legend: 'right',
title: title,
width: '100%',
@@ -138,25 +154,72 @@
}
},
hAxis: {
- title: "Houses"
+ title: "Event Count",
+ gridlines: { count: 20}
}
};
+ // Building Bar Chart
+
+ // get last entry in numData (current scores)
+ var currentScores = numData[numData.length - 1]
+
+ barData = [['House', 'Points', { role: 'style'}]]
+
+ // add each house, score, color triplet one by one
+ for (var i = 0; i < houses.length; i++) {
+ barData.push([houses[i], currentScores[i], colors[i]])
+ }
+
+ // convert to google Data Table
+ var barDataTable = google.visualization.arrayToDataTable(barData)
+
+ var barOptions = {
+ title: title,
+ width: '100%',
+ height: '100%',
+ legend: { position: "none" },
+ vAxis: {
+ title: "House Points",
+ viewWindow: {
+ min: 0,
+ max: max
+ }
+ },
+ hAxis: {
+ title: "Houses",
+ }
+ }
+
+ // Draw default chart (line chart)
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
- chart.draw(dataTable, options);
+ chart.draw(lineDataTable, lineOptions);
+
+ // Add button listener to switch to line chart
+ document.getElementById("line_button").addEventListener("click", () => {
+ var lineChart = new google.visualization.LineChart(document.getElementById('chart_div'));
+ lineChart.draw(lineDataTable, lineOptions);
+ })
+
+ // Add button listener to switch to bar chart
+ document.getElementById("bar_button").addEventListener("click", () => {
+ var barChart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
+ barChart.draw(barDataTable, barOptions)
+ })
}
} else {
+ // if google hasn't loaded in yet, retry in a sec
setTimeout(LoadGoogle, 30);
}
}
-
+
LoadGoogle();
-
Houses
+
House Points
{#if window.innerWidth > 769}
@@ -167,11 +230,19 @@
{/if}
+
+
+
+
\ No newline at end of file
diff --git a/frontend/src/Pages/Inductees.svelte b/frontend/src/Pages/Inductees.svelte
index 3ccb6a11..9205125e 100644
--- a/frontend/src/Pages/Inductees.svelte
+++ b/frontend/src/Pages/Inductees.svelte
@@ -174,7 +174,7 @@