From a00714cce961bac40fc3237067b1caca6d0381e3 Mon Sep 17 00:00:00 2001 From: Tom Hummel Date: Sat, 27 Sep 2025 10:16:13 -0700 Subject: [PATCH] Add puzzle score percentile displays --- layouts/index.html | 2 ++ layouts/partials/puzzle-score-percentile.html | 18 ++++++++++++++++++ layouts/w/single.html | 5 ++++- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 layouts/partials/puzzle-score-percentile.html diff --git a/layouts/index.html b/layouts/index.html index ea23988b0..7ae47925e 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -60,6 +60,7 @@

🕰 Recent Puzzles

Puzzle Turns Score + Percentile {{ range first 5 $wordles }} @@ -68,6 +69,7 @@

🕰 Recent Puzzles

{{ index .Params.puzzles 0 }} {{ partialCached "guess-count.html" . .File.Path }}{{- cond (eq .Params.state.hardMode true) "*" "" -}} {{ partialCached "puzzle-score.html" . .File.Path }} + {{ (partialCached "puzzle-score-percentile.html" . .File.Path) | lang.FormatNumber 1 }}% {{ end }} diff --git a/layouts/partials/puzzle-score-percentile.html b/layouts/partials/puzzle-score-percentile.html new file mode 100644 index 000000000..32f4d59ee --- /dev/null +++ b/layouts/partials/puzzle-score-percentile.html @@ -0,0 +1,18 @@ +{{ $score := partialCached "puzzle-score.html" . .File.Path }} +{{ $wordles := where .Site.RegularPages "Section" "w" }} +{{ $total := len $wordles }} +{{ $less := 0 }} +{{ $equal := 0 }} +{{ range $puzzle := $wordles }} + {{ $otherScore := partialCached "puzzle-score.html" $puzzle $puzzle.File.Path }} + {{ if lt $otherScore $score }} + {{ $less = add $less 1 }} + {{ else if eq $otherScore $score }} + {{ $equal = add $equal 1 }} + {{ end }} +{{ end }} +{{ $percentile := 0.0 }} +{{ if gt $total 0 }} + {{ $percentile = mul (div (float (add $less $equal)) $total) 100 }} +{{ end }} +{{ return $percentile }} diff --git a/layouts/w/single.html b/layouts/w/single.html index 2a02ad78f..438ac8476 100644 --- a/layouts/w/single.html +++ b/layouts/w/single.html @@ -268,7 +268,10 @@

{{.Title}}

- Puzzle Score: {{ partialCached "puzzle-score.html" . .File.Path }} + {{ $puzzleScore := partialCached "puzzle-score.html" . .File.Path }} + {{ $puzzlePercentile := partialCached "puzzle-score-percentile.html" . .File.Path }} + Puzzle Score: {{ $puzzleScore }} + (Percentile: {{ $puzzlePercentile | lang.FormatNumber 1 }}%) {{ partialCached "puzzle-score-detail.html" . .File.Path }}