diff --git a/main.py b/main.py index 7f4fbf8..15a258e 100644 --- a/main.py +++ b/main.py @@ -95,10 +95,14 @@ async def handler(request: aiohttp.web.Request): return aiohttp.web.json_response(model.model) +@routes.get('/dealer/{usertoken}') +async def handler(request): + del request # unused + return aiohttp.web.FileResponse('user.html') + @routes.get('/') async def handler(request): del request # unused - return aiohttp.web.FileResponse('index.html') diff --git a/model.py b/model.py index e8e9136..3171de8 100644 --- a/model.py +++ b/model.py @@ -6,9 +6,9 @@ import datetime import hashlib def generate_random_id(_s=set()): - new_id = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower() + new_id = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(32)))[:32].decode().lower() while (new_id in _s): - new_id = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(10)))[:16].decode().lower() + new_id = base64.b32encode(bytearray(random.randint(0, 0xFF) for _ in range(32)))[:32].decode().lower() _s.add(new_id) return new_id diff --git a/scoreboard.json b/scoreboard.json index bf71344..bed49f8 100644 --- a/scoreboard.json +++ b/scoreboard.json @@ -1,39 +1,39 @@ { "users": { "zgzbbdf5ulagy5md": { - "uuid": "zgzbbdf5ulagy5md", + "uuid": "u4zhlm4y2w4alg4adpj3amw67ivhtfbx", "name": "Andi", "score": 78, "maxscore": 100, "timeout": 0 }, "zjik7wdl7yrm6bb3": { - "uuid": "zjik7wdl7yrm6bb3", + "uuid": "bd63gy2wfdk72q3mk6ooesanx4mo33ao", "name": "Felix", "score": 52, "maxscore": 75, "timeout": 0 }, "zp7v3lnpapnndclk": { - "uuid": "zp7v3lnpapnndclk", + "uuid": "5wn24yko36muqoxohczbf53i6p3hx2pa", "name": "Daki", "score": 62, "maxscore": 100, "timeout": 0 }, "2vsxkkw3d547jhqk": { - "uuid": "2vsxkkw3d547jhqk", + "uuid": "iz2z4c5wkxldc2vdjh66zubxcsvb5qjs", "name": "Cindy", "score": 91, "maxscore": 100, "timeout": 0 }, "66w5o44yc7wf7y27": { - "uuid": "66w5o44yc7wf7y27", + "uuid": "pfkkuzo4y2tmopgc5o6n6zvhy7dyvqdy", "name": "Dominik", "score": 46, "maxscore": 50, "timeout": 0 } } -} +} \ No newline at end of file diff --git a/static/js/user.js b/static/js/user.js new file mode 100644 index 0000000..5592100 --- /dev/null +++ b/static/js/user.js @@ -0,0 +1,52 @@ +"use strict" + +function render_scoreboard(data) { + const users = Object.values(data.users); + + users.sort((a, b) => b.score - a.score); + const min_score = users[users.length-1].score, + max_score = users[0].score; + + const tbody = document.querySelector("#scoreboard tbody"); + + while (tbody.children.length) { + tbody.removeChild(tbody.firstChild); + } + + const template = document.querySelector("#scoreboard template"); + + for (const user of users) { + + const clone = template.content.cloneNode(true); + const name = clone.querySelector(".name"), + score = clone.querySelector(".score"), + bar = clone.querySelector(".bar"); + + const score_percent = Math.floor(10 + (user.score - min_score) / (max_score - min_score) * 90) + "%"; + bar.style.width = score_percent; + + name.innerText = user.name; + score.innerText = user.score; + + tbody.appendChild(clone); + } +} + +async function update_scoreboard() { + + const r = await fetch('api/get_public_model', { + method: 'POST', + body: JSON.stringify({}), + }); + + if (r.status !== 200) { + console.log("oh no"); + return; + } + + const data = await r.json(); + render_scoreboard(data); +} + +update_scoreboard(); +setInterval(update_scoreboard, 1000); \ No newline at end of file diff --git a/user.html b/user.html new file mode 100644 index 0000000..33ee0c0 --- /dev/null +++ b/user.html @@ -0,0 +1,65 @@ + + + + +
+ + +Current Washing Coins: | +42 | +
Maximally Available: | +69 | +