80 lines
No EOL
2.2 KiB
Text
Executable file
80 lines
No EOL
2.2 KiB
Text
Executable file
#!/usr/bin/env nu
|
|
|
|
let chapters = {
|
|
2: 7,
|
|
3: 9,
|
|
4: 19,
|
|
}
|
|
|
|
let gradients = [
|
|
[0, [90, 0, 0]],
|
|
[0.5, [90, 90, 0]],
|
|
[1, [0, 90, 0]],
|
|
]
|
|
|
|
let formatColor = {|color| $"rgb\(($color.0), ($color.1), ($color.2)\)" }
|
|
|
|
let interpColor = {|p|
|
|
let next = ($gradients
|
|
| enumerate
|
|
| skip until { $p <= $in.item.0 }
|
|
| get index).0
|
|
if $next == 0 { return (do $formatColor ($gradients.0.1)) }
|
|
let prev = ($gradients | get ($next - 1))
|
|
let next = ($gradients | get $next)
|
|
let pp = ($p - $prev.0) / ($next.0 - $prev.0)
|
|
|
|
let color = ($prev.1 | zip $next.1 | each {|a| $a.0 * (1 - $pp) + $a.1 * $pp})
|
|
do $formatColor $color
|
|
}
|
|
|
|
let viz = { |k, n|
|
|
let ratio = ($k / $n) | math round --precision 1
|
|
# let color = if n == 0 { "gray" } else if $ratio < 0.25 { "red" } else if $ratio < 0.5 { "orange"} else if $ratio < 0.75 { "yellow"} else { "green" }
|
|
let color = if $n == 0 { "gray" } else { do $interpColor ($k / $n) }
|
|
let textColor = if $k == $n { "gold" } else { "white" }
|
|
|
|
$"<div style=\"
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
aspect-ratio: 1;
|
|
min-height: 80px;
|
|
background-color: ($color);
|
|
color: ($textColor);
|
|
\">
|
|
($k) / ($n)
|
|
</div>" | str replace -a "\n" ""
|
|
# $n | math round --precision 1
|
|
}
|
|
|
|
let vizChapter = { |n|
|
|
let nStr = $n | into string
|
|
let url = $"https://git.mzhang.io/api/v1/repos/school/type-theory/issues/($chapters | get $nStr)"
|
|
|
|
curl -s $url
|
|
| jq -r .body
|
|
| lines
|
|
| rg -o $"\\[\(x| \)\\] \(.*\) \(\\d+\(\\.\\d+\)*\)" -r "$1,$2,$3"
|
|
| from csv --noheaders
|
|
| rename completed type number
|
|
| insert section { if $in.type == "Exercise" { "Exercise" } else { $in.number | split row "." | get 1 } }
|
|
| group-by section
|
|
| transpose
|
|
| each { $in | update column1 { do $viz ($in | where completed == "x" | length) ($in | length) } }
|
|
| sort-by -n column0
|
|
| prepend { column0: "Ch", column1: $n }
|
|
| transpose -r
|
|
}
|
|
|
|
$chapters
|
|
| columns
|
|
| each { do $vizChapter $in }
|
|
| reduce {|it, acc| $acc | append $it }
|
|
| sort-by Ch
|
|
| tee { save -f html/src/generated/Progress.md }
|
|
|
|
|
|
# open breakdown.json
|
|
# | transpose
|
|
# | each {|row| [$row.column0, $row.column1.ratioCompleted] } |