mirror of https://github.com/dirtbags/moth.git
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.
This commit is contained in:
parent
ca365e729f
commit
e10e4a539b
2
install
2
install
|
@ -45,7 +45,7 @@ setup() {
|
||||||
|
|
||||||
|
|
||||||
echo "Figuring out web user..."
|
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
|
id $www && break
|
||||||
done
|
done
|
||||||
if [ $www = _ ]; then
|
if [ $www = _ ]; then
|
||||||
|
|
|
@ -1,22 +1,31 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Scoreboard</title>
|
<title>Points History</title>
|
||||||
<link rel="stylesheet" href="style.css" type="text/css">
|
|
||||||
<script src="scoreboard.js" async></script>
|
|
||||||
<script>
|
<script>
|
||||||
function init() {
|
function init() {
|
||||||
var pointslog = JSON.parse(localStorage.getItem("points"));
|
|
||||||
for (point in points){
|
function getParameterByName(name) {
|
||||||
console.log(point);
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||||
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
||||||
|
results = regex.exec(location.search);
|
||||||
|
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pointsDiv = document.getElementById("pointslog");
|
||||||
|
var pointshistory = JSON.parse(localStorage.getItem("pointshistory"));
|
||||||
|
// get snapshot specified by query param or else most recent snapshot
|
||||||
|
var i = parseInt(getParameterByName("snapshot")) || pointshistory.length-1;
|
||||||
|
var snapshot = pointshistory[i];
|
||||||
|
pointsDiv.innerHTML = snapshot.map(function(entry){
|
||||||
|
return entry.join(" ");
|
||||||
|
}).join("<br>");
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", init);
|
window.addEventListener("load", init);
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Scoreboard</h1>
|
<div id="pointslog"></div>
|
||||||
<div id="scoreboard"></div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -13,9 +13,15 @@ function scoreboard(element, continuous) {
|
||||||
function update(state) {
|
function update(state) {
|
||||||
var teamnames = state["teams"];
|
var teamnames = state["teams"];
|
||||||
var pointslog = state["points"];
|
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 highscore = {};
|
||||||
var teams = {};
|
var teams = {};
|
||||||
|
|
||||||
// Dole out points
|
// Dole out points
|
||||||
for (var i in pointslog) {
|
for (var i in pointslog) {
|
||||||
var entry = pointslog[i];
|
var entry = pointslog[i];
|
||||||
|
@ -23,18 +29,18 @@ function scoreboard(element, continuous) {
|
||||||
var teamhash = entry[1];
|
var teamhash = entry[1];
|
||||||
var category = entry[2];
|
var category = entry[2];
|
||||||
var points = entry[3];
|
var points = entry[3];
|
||||||
|
|
||||||
var team = teams[teamhash] || {__hash__: teamhash};
|
var team = teams[teamhash] || {__hash__: teamhash};
|
||||||
|
|
||||||
// Add points to team's points for that category
|
// Add points to team's points for that category
|
||||||
team[category] = (team[category] || 0) + points;
|
team[category] = (team[category] || 0) + points;
|
||||||
|
|
||||||
// Record highest score in a category
|
// Record highest score in a category
|
||||||
highscore[category] = Math.max(highscore[category] || 0, team[category]);
|
highscore[category] = Math.max(highscore[category] || 0, team[category]);
|
||||||
|
|
||||||
teams[teamhash] = team;
|
teams[teamhash] = team;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by team score
|
// Sort by team score
|
||||||
function teamScore(t) {
|
function teamScore(t) {
|
||||||
var score = 0;
|
var score = 0;
|
||||||
|
@ -49,7 +55,7 @@ function scoreboard(element, continuous) {
|
||||||
function teamCompare(a, b) {
|
function teamCompare(a, b) {
|
||||||
return teamScore(a) - teamScore(b);
|
return teamScore(a) - teamScore(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
var winners = [];
|
var winners = [];
|
||||||
for (var i in teams) {
|
for (var i in teams) {
|
||||||
winners.push(teams[i]);
|
winners.push(teams[i]);
|
||||||
|
@ -60,12 +66,12 @@ function scoreboard(element, continuous) {
|
||||||
}
|
}
|
||||||
winners.sort(teamCompare);
|
winners.sort(teamCompare);
|
||||||
winners.reverse();
|
winners.reverse();
|
||||||
|
|
||||||
// Clear out the element we're about to populate
|
// Clear out the element we're about to populate
|
||||||
while (element.lastChild) {
|
while (element.lastChild) {
|
||||||
element.removeChild(element.lastChild);
|
element.removeChild(element.lastChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate!
|
// Populate!
|
||||||
var topActualScore = winners[0].__score__;
|
var topActualScore = winners[0].__score__;
|
||||||
|
|
||||||
|
@ -80,26 +86,26 @@ function scoreboard(element, continuous) {
|
||||||
var catTeam = team[category] || 0;
|
var catTeam = team[category] || 0;
|
||||||
var catPct = catTeam / catHigh;
|
var catPct = catTeam / catHigh;
|
||||||
var width = maxWidth * catPct;
|
var width = maxWidth * catPct;
|
||||||
|
|
||||||
var bar = document.createElement("span");
|
var bar = document.createElement("span");
|
||||||
bar.classList.add("cat" + ncat);
|
bar.classList.add("cat" + ncat);
|
||||||
bar.style.width = width + "%";
|
bar.style.width = width + "%";
|
||||||
bar.textContent = category + ": " + catTeam;
|
bar.textContent = category + ": " + catTeam;
|
||||||
bar.title = bar.textContent;
|
bar.title = bar.textContent;
|
||||||
|
|
||||||
row.appendChild(bar);
|
row.appendChild(bar);
|
||||||
ncat += 1;
|
ncat += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var te = document.createElement("span");
|
var te = document.createElement("span");
|
||||||
te.classList.add("teamname");
|
te.classList.add("teamname");
|
||||||
te.textContent = teamnames[team.__hash__];
|
te.textContent = teamnames[team.__hash__];
|
||||||
row.appendChild(te);
|
row.appendChild(te);
|
||||||
|
|
||||||
element.appendChild(row);
|
element.appendChild(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function once() {
|
function once() {
|
||||||
loadJSON("points.json", update);
|
loadJSON("points.json", update);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue