From dcc3413019f56a3a65bb18ffbccd29e29fd2999d Mon Sep 17 00:00:00 2001 From: James Wernicke Date: Thu, 28 May 2015 14:15:05 -0600 Subject: [PATCH] Changed points restore output to Neale's stupid space delimited format. Added url param 'snapshot' to specify a points snapshot to restore (0-19). Changed points log storage to an array of the 20 most recent points logs. --- install | 2 +- www/restore.html | 25 +++++++++++++++++-------- www/scoreboard.js | 34 ++++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/install b/install index f53a293..8b5f77b 100755 --- a/install +++ b/install @@ -45,7 +45,7 @@ setup() { echo "Figuring out web user..." -for www in www-data http tc _; do +for www in www-data http tc _ _www; do id $www && break done if [ $www = _ ]; then diff --git a/www/restore.html b/www/restore.html index 2c16716..361e0c1 100644 --- a/www/restore.html +++ b/www/restore.html @@ -1,22 +1,31 @@ - Scoreboard - - + Points History -

Scoreboard

-
+
diff --git a/www/scoreboard.js b/www/scoreboard.js index 0d47eef..76486f0 100644 --- a/www/scoreboard.js +++ b/www/scoreboard.js @@ -13,9 +13,15 @@ function scoreboard(element, continuous) { function update(state) { var teamnames = state["teams"]; var pointslog = state["points"]; + var pointshistory = JSON.parse(localStorage.getItem("pointshistory")) || []; + if (pointshistory.length >= 20){ + pointshistory.shift(); + } + pointshistory.push(pointslog); + localStorage.setItem("pointshistory", JSON.stringify(pointshistory)); var highscore = {}; var teams = {}; - + // Dole out points for (var i in pointslog) { var entry = pointslog[i]; @@ -23,18 +29,18 @@ function scoreboard(element, continuous) { var teamhash = entry[1]; var category = entry[2]; var points = entry[3]; - + var team = teams[teamhash] || {__hash__: teamhash}; - + // Add points to team's points for that category team[category] = (team[category] || 0) + points; - + // Record highest score in a category highscore[category] = Math.max(highscore[category] || 0, team[category]); - + teams[teamhash] = team; } - + // Sort by team score function teamScore(t) { var score = 0; @@ -49,7 +55,7 @@ function scoreboard(element, continuous) { function teamCompare(a, b) { return teamScore(a) - teamScore(b); } - + var winners = []; for (var i in teams) { winners.push(teams[i]); @@ -60,12 +66,12 @@ function scoreboard(element, continuous) { } winners.sort(teamCompare); winners.reverse(); - + // Clear out the element we're about to populate while (element.lastChild) { element.removeChild(element.lastChild); } - + // Populate! var topActualScore = winners[0].__score__; @@ -80,26 +86,26 @@ function scoreboard(element, continuous) { var catTeam = team[category] || 0; var catPct = catTeam / catHigh; var width = maxWidth * catPct; - + var bar = document.createElement("span"); bar.classList.add("cat" + ncat); bar.style.width = width + "%"; bar.textContent = category + ": " + catTeam; bar.title = bar.textContent; - + row.appendChild(bar); ncat += 1; } - + var te = document.createElement("span"); te.classList.add("teamname"); te.textContent = teamnames[team.__hash__]; row.appendChild(te); - + element.appendChild(row); } } - + function once() { loadJSON("points.json", update); }