├── demo.gif ├── .jshintrc ├── README.md ├── main.css ├── LICENSE ├── index.html └── main.js /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcolussetti/adventofcode-percenter/HEAD/demo.gif -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase": true, 3 | "quotmark": "double", 4 | "asi": true, 5 | "esversion": 8 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # adventofcode-percenter 2 | 3 | Generate some basic graphs & find how you're doing overall (Top X%) for each day and solution. This is super basic honestly. 4 | 5 | You can use it from https://aocstats.marcolussetti.com 6 | 7 | ## Demo 8 | 9 | ![](demo.gif) 10 | 11 | ## Contributing 12 | If for any reason you feel compelled to contribute, pull requests are of course very welcome. For major changes, please open an issue first to discuss what you would like to change. 13 | 14 | When merged in, changes get autodeployed from master via Netlify. 15 | 16 | ## License 17 | [MIT](https://choosealicense.com/licenses/mit/) 18 | -------------------------------------------------------------------------------- /main.css: -------------------------------------------------------------------------------- 1 | .container { 2 | padding: 1rem; 3 | } 4 | 5 | .center-container { 6 | display: flex; 7 | align-items: center; 8 | justify-content: center; 9 | } 10 | 11 | .container > div { 12 | padding: 0.5rem; 13 | } 14 | 15 | #results-container { 16 | display: none; 17 | } 18 | 19 | footer.footer { 20 | padding: 0.25rem; 21 | width: 100%; 22 | } 23 | 24 | body { 25 | display: flex; 26 | min-height: 100vh; 27 | flex-direction: column; 28 | } 29 | 30 | #wrapper { 31 | flex: 1; 32 | } 33 | 34 | 35 | .section { 36 | padding: 0; 37 | } 38 | 39 | 40 | td { 41 | text-align: right !important; 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Marco Lussetti. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Advent of Code 2022 - Enhanced Stats / Rank to Percent 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | Fork me on GitHub 20 |
21 |
22 |
23 |
24 |
25 |

26 | Advent of Code - Enhanced Stats 27 |

28 |

29 | Statistics beyond the global leaderboard 30 |

31 |
32 | 33 |
34 |
35 |

Copy your stats from the personal 37 | leaderboard into the text field below.

38 |
39 | 40 |
41 |
42 |
43 | 55 |
56 |
57 |
58 | 59 |
60 | 63 |
64 | 65 |
67 |
68 | 69 |
70 |
71 | 72 | 73 | 74 |
75 | 76 |
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 |
DayPart 1: RankPart 1: Top %Part 2: RankPart 2: Top %
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | let yourStats 2 | let globalStats 3 | 4 | function processYourStats() { 5 | const inputString = document.querySelector("#input-textarea").value 6 | const lines = inputString.split("\n").map(line => line.trim().split(/\s+/)).filter(line => /^\d+$/.test(line[0])) 7 | const yourStats = lines.map(line => { 8 | return { 9 | day: parseInt(line[0]), 10 | stats: [ 11 | { time: line[1], rank: parseInt(line[2]), score: parseInt(line[3]) }, 12 | { time: line[4], rank: parseInt(line[5]), score: parseInt(line[6]) } 13 | ] 14 | } 15 | }) 16 | 17 | return yourStats.sort((a, b) => a.day > b.day) 18 | } 19 | 20 | function processGlobalStats(year) { 21 | // TODO: replace with a caching system 22 | return fetch(`https://marcors.ferned.net/https://adventofcode.com/${year}/stats`) 23 | .then(resp => resp.text()) 24 | .then(text => new DOMParser().parseFromString(text, "text/html")) 25 | .then(html => html.querySelector("pre.stats")) 26 | .then(statsElement => { 27 | // console.log(statsElement) 28 | const statsLines = statsElement.textContent.trim().split("\n").map(line => line.trim().split(/\s+/)).filter(line => /^\d+$/.test(line[0])) 29 | 30 | return statsLines.map(line => [parseInt(line[0]), parseInt(line[1]), parseInt(line[2])]) 31 | }) 32 | .then(result => result.sort((a, b) => a[0] - b[0])) 33 | .catch() 34 | } 35 | 36 | function discretizeRawPercent(rawPercent) { 37 | const buckets = [0.001, 0.005, 0.01, 0.025, 0.05, 0.10, 0.25, 0.33, 0.50, 0.75, 1.0] 38 | return buckets.filter(bucketEnd => bucketEnd >= rawPercent)[0] * 100 39 | } 40 | 41 | function plotPerformance(comparedStats, rankOnly = false) { 42 | document.querySelector("#results-chart").innerHTML = ""; 43 | document.querySelector("#results-chart").appendChild(document.createElement("canvas")) 44 | 45 | const ctx = document.querySelector("#results-chart>canvas").getContext("2d") 46 | 47 | new Chart(ctx, { 48 | type: "line", 49 | 50 | data: { 51 | labels: comparedStats.map(entry => `${(entry[0])}`), 52 | datasets: [ 53 | { 54 | label: "Part 1", 55 | backgroundColor: "#1a85ff", 56 | borderColor: "#1a85ff", 57 | pointBackgroundColor: "#1a85ff", 58 | pointBorderColor: "#1a85ff", 59 | fill: false, 60 | data: comparedStats.map(entry => rankOnly ? entry[1] : entry[2]) 61 | }, 62 | { 63 | label: "Part 2", 64 | backgroundColor: "#d41159", 65 | borderColor: "#d41159", 66 | pointBackgroundColor: "#d41159", 67 | pointBorderColor: "#d41159backgroundColor", 68 | fill: false, 69 | data: comparedStats.map(entry => rankOnly ? entry[2] : entry[4]) 70 | }, 71 | ] 72 | }, 73 | 74 | options: { 75 | scales: { 76 | yAxes: [{ 77 | ticks: { 78 | callback: function (value, index, values) { 79 | return rankOnly ? value : `${~~(value * 100)}%` 80 | } 81 | } 82 | }] 83 | } 84 | } 85 | }) 86 | } 87 | 88 | function generateStats(totalUsers = false, rankOnly = false) { 89 | console.log(`totalUsers: ${totalUsers}. rankOnly: ${rankOnly}`) 90 | document.querySelector("#results-body").innerHTML = ""; 91 | 92 | const yourStatsCompared = yourStats.map((val) => { 93 | const partOneTotal = !totalUsers ? globalStats[val.day - 1][1] + globalStats[val.day - 1][2] : globalStats[0][1] + globalStats[0][2] 94 | const partTwoTotal = !totalUsers ? globalStats[val.day - 1][1] : globalStats[0][1] + globalStats[0][2] 95 | 96 | if (rankOnly) 97 | return [val.day, val.stats[0].rank, val.stats[1].rank] 98 | else 99 | return [ 100 | val.day, 101 | val.stats[0].rank, 102 | val.stats[0].rank / partOneTotal, 103 | val.stats[1].rank, 104 | val.stats[1].rank / partTwoTotal 105 | ] 106 | }).sort((a, b) => a[0] - b[0]) 107 | 108 | yourStatsCompared.map(row => { 109 | const rowEl = document.createElement("tr") 110 | row.forEach((item, i) => { 111 | let element = document.createElement("td") 112 | element.innerHTML = i % 2 == 0 && i > 0 && !Number.isNaN(item) && !rankOnly ? `Top ${discretizeRawPercent(item)}%` : !Number.isNaN(item) ? `${item}` : "—" 113 | rowEl.appendChild(element) 114 | }) 115 | 116 | document.querySelector("#results-body").appendChild(rowEl) 117 | }) 118 | 119 | if (rankOnly) 120 | [...document.querySelectorAll("#results-table th")].map(el => { if (el.textContent.includes("%")) el.style.display = "none" }) 121 | else 122 | [...document.querySelectorAll("#results-table th")].map(el => { el.style.display = "table-cell" }); 123 | 124 | const buttons = [...document.querySelectorAll(".buttons-container>button")] 125 | 126 | buttons.map(button => button.className = "button is-small"); 127 | if (rankOnly) { 128 | buttons[2].classList.add("is-success") 129 | buttons[2].classList.add("is-selected") 130 | } else if (totalUsers) { 131 | buttons[1].classList.add("is-success") 132 | buttons[1].classList.add("is-selected") 133 | } else { 134 | buttons[0].classList.add("is-success") 135 | buttons[0].classList.add("is-selected") 136 | } 137 | 138 | plotPerformance(yourStatsCompared, rankOnly = rankOnly) 139 | } 140 | 141 | async function handleInput() { 142 | const year = document.querySelector("#year-selector").value 143 | 144 | yourStats = processYourStats() 145 | if (yourStats.length == 0) { 146 | alert("You need to put something in here...") 147 | return -1 148 | } 149 | globalStats = await processGlobalStats(year) 150 | 151 | generateStats() 152 | 153 | document.querySelector("#results-container").style.display = "block" 154 | document.querySelector("#form-container").style.display = "none" 155 | } 156 | 157 | document.addEventListener("DOMContentLoaded", function () { 158 | document.querySelector("#compute-button").addEventListener("click", handleInput) 159 | 160 | document.querySelector("#per-day-selector").addEventListener("click", generateStats.bind(null, false, false)) 161 | document.querySelector("#total-users-selector").addEventListener("click", generateStats.bind(null, true, false)) 162 | document.querySelector("#rank-only-selector").addEventListener("click", generateStats.bind(null, false, true)) 163 | }, false); 164 | --------------------------------------------------------------------------------