Skip to content

Commit f915fe6

Browse files
ASCoding11claude
andauthored
Fastest climbing Aisles today (#352)
- **New: "Fastest climbing Aisles today"** panel at the top of the Back Room (right above Playing now), on the Back Room page, the home page's Back Room and the phone page. It ranks Aisles by the Elo their members won today in ranked games, with live green ▲ arrows and each Aisle's top climber. - **How:** `elo.js` now also adds each rated match's change to the player's own node `rooms/elo-day/players/<uid>` (today's New York date, change per game, total). The new `climb.js` listens to that one node and adds it up per Aisle. It writes nothing itself. - `aisles.js`: two small read-only helpers (`list()`, `tag(K)`). Loader lines in `index.html` (home page reveal), `e63334287a3deaa3/index.html` and `e63334287a3deaa3/m/index.html`. README and What's new updated. - Risk: low. One new Realtime Database path under `rooms/` written only by each player's own browser, with the fields the shared rules already require (no rules change). Self-reported like every Back Room stat. Claude-Session: https://claude.ai/code/session_016ZY4GY6KEVGmw5xYZiPbvp Co-authored-by: Claude <noreply@anthropic.com>
1 parent f3be885 commit f915fe6

8 files changed

Lines changed: 183 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

‎e63334287a3deaa3/aisles.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@
10621062
start: start, open: open, close: close, board: board, unboard: unboard, inviteBtn: inviteBtn, admin: admin,
10631063
of: function (u) { var A = aisleOf(u); return A ? { K: A.K, nm: A.nm, tg: A.tg, cl: A.cl, leader: A.leader, members: A.members.slice() } : null; },
10641064
get mine() { var A = mine(); return A ? A.K : ''; },
1065+
// Every Aisle shown (removed ones left out), for climb.js: [{ K, nm, tg, cl, em, members: [uid] }]; and its tag element.
1066+
list: function () { return Object.keys(aisles).map(function (K) { var A = aisles[K]; return { K: K, nm: A.nm, tg: A.tg, cl: A.cl, em: A.em, members: A.members.slice() }; }); },
1067+
tag: function (K) { return aisles[K] ? tagEl(aisles[K]) : null; },
10651068
get ready() { return ready; },
10661069
onChange: function (f) { if (typeof f === 'function') listeners.push(f); },
10671070
// Last week's contest winners (a tie: every Aisle ranked 1) from the boards' checked rows, for wallet.js's weekly

‎e63334287a3deaa3/climb.js‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Fastest climbing Aisles today (Back Room page, home page Back Room and phone page): a live panel right above
3+
* Playing now that ranks Aisles by the Elo their members have gained today in ranked games, with green up-arrows.
4+
*
5+
* Data: elo.js adds every rated match's change to the player's own node rooms/elo-day/players/<uid>
6+
* ({ n, d: New York date 'YYYY-MM-DD', gm: { <game folder>: change }, t: total today }). This file listens to
7+
* rooms/elo-day/players (one small node per player who has ever played ranked; live, so arrows move as matches end),
8+
* keeps only today's nodes (New York time, the same day for everyone), and adds them up per Aisle using
9+
* BackRoomAisles.list() (members as aisles.js resolved them). An Aisle's climb is the sum of its members' totals
10+
* (a loss counts against it); the top five Aisles that are up are shown, each with its best climber. Like every Back
11+
* Room stat it is self-reported, for fun. Nothing is written here. Signs in only through party.js (Party.boot).
12+
*/
13+
(function () {
14+
'use strict';
15+
if (window.BackRoomClimb) return;
16+
var PATH = 'rooms/elo-day/players', SHOW = 5;
17+
var ES = {
18+
'Fastest climbing Aisles today': 'Los Aisles que más suben hoy',
19+
'Elo won in ranked games today. Win a ranked match to push your Aisle up.': 'Elo ganado hoy en partidas con rango. Gana una partida con rango para subir a tu Aisle.',
20+
'No Aisle has climbed yet today. Win a ranked match to put yours on the board.': 'Ningún Aisle ha subido todavía hoy. Gana una partida con rango para poner el tuyo en la tabla.',
21+
'Top climber': 'Quien más sube',
22+
'Elo today': 'Elo hoy',
23+
'members climbing': 'miembros subiendo'
24+
};
25+
function es() { try { return !!(window.BackRoomLang && BackRoomLang.get && BackRoomLang.get() === 'es'); } catch (e) { return false; } }
26+
function T(s) { return es() && ES[s] ? ES[s] : s; }
27+
function nyDay() {
28+
try { return new Intl.DateTimeFormat('en-CA', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()); }
29+
catch (e) { return new Date().toISOString().slice(0, 10); }
30+
}
31+
function byFilter(v) { return window.NameFilter ? window.NameFilter.clean(v) : v; }
32+
function cleanName(s) { return byFilter(String(s == null ? '' : s).replace(/[<>\u0000-\u001f\u007f​-‏‪-‮⁦-⁩]/g, '').replace(/\s+/g, ' ').trim().slice(0, 14)) || 'Player'; }
33+
function fmt(n) { try { return Math.round(n).toLocaleString('en-US'); } catch (e) { return String(Math.round(n)); } }
34+
35+
// ---------------- Styles (on top of party.js's .pty panel styles, like Playing now) ----------------
36+
var css = document.createElement('style');
37+
css.textContent =
38+
'#climbing{padding-top:14px}' +
39+
'.cl-list{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,300px),1fr));gap:8px}' +
40+
'.cl-it{display:flex;align-items:center;gap:10px;background:var(--panel-2);border:1px solid var(--line);border-radius:10px;padding:8px 12px;min-width:0}' +
41+
'.cl-n{font-family:var(--mono);font-weight:600;font-size:13px;color:var(--ink-2);width:1.6em;flex:none;text-align:center}' +
42+
'.cl-it:first-child .cl-n{color:var(--accent)}' +
43+
'.cl-who{display:grid;gap:2px;min-width:0;flex:1;line-height:1.25}' +
44+
'.cl-a{display:flex;align-items:center;gap:6px;min-width:0;font-weight:600}' +
45+
'.cl-a .cl-nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
46+
'.cl-best{font-size:13px;color:var(--ink-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
47+
'.cl-up{flex:none;display:flex;flex-direction:column;align-items:flex-end;line-height:1.1}' +
48+
'.cl-up b{color:var(--up,#1fbf62);font-family:var(--mono);font-size:17px;font-weight:700;white-space:nowrap}' +
49+
'.cl-up small{font-family:var(--mono);font-size:10px;letter-spacing:.06em;text-transform:uppercase;color:var(--ink-2)}' +
50+
'.cl-it.cl-new b{animation:clpop .9s ease-out}' +
51+
'@keyframes clpop{0%{transform:translateY(4px);opacity:.3}60%{transform:translateY(-2px)}100%{transform:none;opacity:1}}' +
52+
'@media (prefers-reduced-motion:reduce){.cl-it.cl-new b{animation:none}}' +
53+
'.cl-empty{margin:0;font-size:14px;color:var(--ink-2)}.cl-empty:empty{display:none}';
54+
document.head.appendChild(css);
55+
56+
// ---------------- Panel ----------------
57+
var sec = document.createElement('section');
58+
sec.id = 'climbing'; sec.setAttribute('aria-label', 'Fastest climbing Aisles today'); sec.hidden = true;
59+
sec.innerHTML = '<div class="pty cl"><div class="pty-top"><h2></h2><p class="pty-sub"></p></div><ol class="cl-list"></ol><p class="cl-empty"></p></div>';
60+
var $h = sec.querySelector('h2'), $sub = sec.querySelector('.pty-sub'), $list = sec.querySelector('.cl-list'), $empty = sec.querySelector('.cl-empty');
61+
// Right above Playing now (or the Party panel), so it's one of the first things on the page. Placed once.
62+
var placed = false;
63+
function place() {
64+
if (placed) return; var pn = document.getElementById('playingnow'), party = document.getElementById('party'), head = document.querySelector('header');
65+
var at = pn || party; if (!at && !head) return;
66+
placed = true;
67+
if (at && at.parentNode) at.parentNode.insertBefore(sec, at); else head.parentNode.insertBefore(sec, head.nextSibling);
68+
if (party) { var mb = getComputedStyle(party).marginBottom; if (parseFloat(mb) > 0) { sec.style.paddingTop = '0'; sec.style.marginBottom = mb; } }
69+
}
70+
71+
// ---------------- Data ----------------
72+
var raw = {}, last = {};
73+
function compute() {
74+
var A = window.BackRoomAisles, today = nyDay(); if (!A || !A.ready || !A.list) return null;
75+
var gain = {};
76+
Object.keys(raw || {}).forEach(function (u) {
77+
var v = raw[u]; if (!v || v.d !== today || !isFinite(+v.t)) return;
78+
gain[u] = { t: Math.max(-2000, Math.min(2000, Math.round(+v.t))), n: cleanName(v.n) };
79+
});
80+
return A.list().map(function (a) {
81+
var sum = 0, best = null, up = 0;
82+
a.members.forEach(function (u) { var g = gain[u]; if (!g) return; sum += g.t; if (g.t > 0) up++; if (!best || g.t > best.t) best = g; });
83+
return { a: a, t: sum, best: best, up: up };
84+
}).filter(function (x) { return x.t > 0; }).sort(function (x, y) { return y.t - x.t || (x.a.nm < y.a.nm ? -1 : 1); });
85+
}
86+
function draw() {
87+
var rows = compute(); if (!rows) return;
88+
place();
89+
$h.textContent = T('Fastest climbing Aisles today');
90+
$sub.textContent = T('Elo won in ranked games today. Win a ranked match to push your Aisle up.');
91+
var A = window.BackRoomAisles, any = A.list().length > 0;
92+
sec.hidden = !any;
93+
$list.textContent = '';
94+
$empty.textContent = rows.length ? '' : T('No Aisle has climbed yet today. Win a ranked match to put yours on the board.');
95+
var now = {};
96+
rows.slice(0, SHOW).forEach(function (x, i) {
97+
var li = document.createElement('li'); li.className = 'cl-it';
98+
if (last[x.a.K] !== undefined && last[x.a.K] < x.t) li.classList.add('cl-new');
99+
now[x.a.K] = x.t;
100+
var n = document.createElement('span'); n.className = 'cl-n'; n.textContent = (i + 1);
101+
var who = document.createElement('div'); who.className = 'cl-who';
102+
var an = document.createElement('div'); an.className = 'cl-a';
103+
var tg = A.tag ? A.tag(x.a.K) : null; if (tg) an.appendChild(tg);
104+
var nm = document.createElement('span'); nm.className = 'cl-nm'; nm.textContent = x.a.nm; an.appendChild(nm);
105+
who.appendChild(an);
106+
if (x.best && x.best.t > 0) { var b = document.createElement('div'); b.className = 'cl-best'; b.textContent = T('Top climber') + ': ' + x.best.n + ' +' + fmt(x.best.t) + (x.up > 1 ? ' · ' + x.up + ' ' + T('members climbing') : ''); who.appendChild(b); }
107+
var up = document.createElement('div'); up.className = 'cl-up';
108+
var v = document.createElement('b'); v.textContent = '▲ +' + fmt(x.t); v.setAttribute('aria-label', '+' + fmt(x.t) + ' Elo today');
109+
var sm = document.createElement('small'); sm.textContent = T('Elo today');
110+
up.append(v, sm);
111+
li.append(n, who, up); $list.appendChild(li);
112+
});
113+
last = now;
114+
}
115+
116+
function start() {
117+
var n = 0;
118+
(function wait() {
119+
if (window.Party && Party.boot && window.BackRoomAisles) {
120+
Party.boot().then(function (b) {
121+
b.db.ref(PATH).on('value', function (s) { raw = s.val() || {}; draw(); });
122+
}).catch(function () {});
123+
if (BackRoomAisles.onChange) BackRoomAisles.onChange(draw);
124+
document.addEventListener('backroom:lang', draw);
125+
setInterval(draw, 60000); // a new day starts the board afresh
126+
return;
127+
}
128+
if (++n < 300) setTimeout(wait, 200);
129+
})();
130+
}
131+
window.BackRoomClimb = { compute: compute, draw: draw, nyDay: nyDay };
132+
if (navigator.webdriver) window.__climb = { set: function (r) { raw = r || {}; draw(); } }; // tests only
133+
start();
134+
})();

‎e63334287a3deaa3/elo.js‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@
116116
} catch (e) {}
117117
}
118118

119+
// ---------------- Today's climb ----------------
120+
// Every rated match adds its change to rooms/elo-day/players/<uid> ({ d: the New York date, gm: { <folder>: change
121+
// today }, t: the total }), started afresh on a new day. climb.js adds these up per Aisle for the Back Room's
122+
// "Fastest climbing Aisles today". One small node per player, so the Back Room reads one place instead of every game's.
123+
function nyDay() {
124+
try { return new Intl.DateTimeFormat('en-CA', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()); }
125+
catch (e) { return new Date().toISOString().slice(0, 10); }
126+
}
127+
function day(delta) {
128+
var c = conn(); if (!c || !isFinite(delta)) return;
129+
try {
130+
var ref = c.db.ref('rooms/elo-day/players/' + c.uid);
131+
timeout(ref.once('value'), 5000).then(function (s) {
132+
if (!s) return; // couldn't read: don't overwrite today's total with just this match
133+
var v = s.val() || {}, d = nyDay(), gm = {};
134+
if (v.d === d && v.gm && typeof v.gm === 'object') Object.keys(v.gm).forEach(function (k) { if (/^[a-z0-9-]{1,32}$/.test(k) && isFinite(+v.gm[k])) gm[k] = Math.round(+v.gm[k]); });
135+
gm[GAME] = (gm[GAME] || 0) + Math.round(delta);
136+
var t = 0; Object.keys(gm).forEach(function (k) { t += gm[k]; });
137+
return ref.set({ n: myName(), c: '#8b95b8', x: 0, z: 0, h: 0, ts: c.F.database.ServerValue.TIMESTAMP, d: d, gm: gm, t: t });
138+
}).catch(function () {});
139+
} catch (e) {}
140+
}
141+
119142
// ---------------- Rank-up share card ----------------
120143
// After a rated match, flex.js (loaded only now) checks for a new tier or a top-100 place and offers a share card.
121144
function flex(res) {
@@ -164,7 +187,7 @@
164187
var res = { game: GAME, before: before, after: Math.round(rank.r), delta: Math.round(rank.r) - before, humans: humans.length, w: w };
165188
show(res.before, res.after, res.delta);
166189
try { document.dispatchEvent(new CustomEvent('backroom:elo', { detail: res })); } catch (e) {}
167-
flex(res);
190+
flex(res); day(res.delta);
168191
busy = false; return res;
169192
}).catch(function () { busy = false; return null; });
170193
} catch (e) { busy = false; return Promise.resolve(null); }

‎e63334287a3deaa3/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ <h3>Flood Crew</h3>
12201220
<script src="/e63334287a3deaa3/aisles.js" defer></script>
12211221
<script src="/e63334287a3deaa3/avismiles.js" defer></script>
12221222
<script src="/e63334287a3deaa3/playingnow.js" defer></script>
1223+
<script src="/e63334287a3deaa3/climb.js" defer></script> <!-- Fastest climbing Aisles today (climb.js) -->
12231224
<script src="/e63334287a3deaa3/door.js" defer></script>
12241225
<script src="/e63334287a3deaa3/seasons.js" defer></script>
12251226
<script src="/e63334287a3deaa3/events.js" defer></script>

‎e63334287a3deaa3/m/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ <h1><span data-door>ASC</span>oding <span>games</span></h1>
395395
// Avis miles (avismiles.js): the claim dialog, opened from the Online panel or #avis-miles.
396396
var avm=document.createElement('script');avm.src=B+'avismiles.js';document.body.appendChild(avm);
397397
var pn=document.createElement('script');pn.src=B+'playingnow.js';document.body.appendChild(pn);
398+
var cl=document.createElement('script');cl.src=B+'climb.js';document.body.appendChild(cl); // Fastest climbing Aisles today (climb.js)
398399
// Your school (school.js): fills in the [data-school] box under the header.
399400
var sk=document.createElement('script');sk.src=B+'school.js';document.body.appendChild(sk);
400401

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"kind": "feature",
3+
"title": "Fastest climbing Aisles today",
4+
"tags": ["Aisles", "Elo"],
5+
"items": [
6+
"A new board at the top of the Back Room shows which Aisles are climbing fastest today, with live green arrows.",
7+
"It adds up the Elo every member wins in ranked games today, and names each Aisle's top climber.",
8+
"It starts fresh every day, so any Aisle can top it."
9+
],
10+
"es": {
11+
"Fastest climbing Aisles today": "Los Aisles que más suben hoy",
12+
"Aisles": "Aisles",
13+
"Elo": "Elo",
14+
"A new board at the top of the Back Room shows which Aisles are climbing fastest today, with live green arrows.": "Una nueva tabla arriba del Back Room muestra qué Aisles están subiendo más rápido hoy, con flechas verdes en vivo.",
15+
"It adds up the Elo every member wins in ranked games today, and names each Aisle's top climber.": "Suma el Elo que cada miembro gana hoy en partidas con rango y nombra a quien más sube en cada Aisle.",
16+
"It starts fresh every day, so any Aisle can top it.": "Empieza de cero cada día, así que cualquier Aisle puede llegar arriba."
17+
}
18+
}

‎index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ <h3>Productivity</h3>
441441
if(/^xj-[0-9a-z]{16}$/.test(room)){try{sessionStorage.setItem('aisle:inv',room.slice(3))}catch(e){}room=''}
442442
var ai=document.createElement('script');ai.src=dir+'aisles.js';document.body.appendChild(ai);
443443
var pn=document.createElement('script');pn.src=dir+'playingnow.js';document.body.appendChild(pn); // Playing now: public parties' games (playingnow.js)
444+
var cb=document.createElement('script');cb.src=dir+'climb.js';document.body.appendChild(cb); // Fastest climbing Aisles today (climb.js)
444445
// The seasonal look (seasons.js) is only for the Back Room, so the home page loads it once the Back Room is open.
445446
var se=document.createElement('script');se.src=dir+'seasons.js';document.body.appendChild(se);
446447
// The Turkey Week switch (events.js) is a button in the Back Room's header, which was copied in above; this fills it in.

0 commit comments

Comments
 (0)