2024-07-10 22:03:51 +00:00
|
|
|
#!/usr/bin/env nu
|
|
|
|
|
|
|
|
let chapters = {
|
|
|
|
2: 7,
|
|
|
|
3: 9,
|
|
|
|
4: 19,
|
2024-07-11 15:15:26 +00:00
|
|
|
6: 15,
|
|
|
|
7: 21,
|
|
|
|
8: 22,
|
2024-07-10 22:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let gradients = [
|
|
|
|
[0, [90, 0, 0]],
|
2024-07-11 04:06:20 +00:00
|
|
|
[0.65, [180, 180, 0]],
|
2024-07-10 22:03:51 +00:00
|
|
|
[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" }
|
|
|
|
|
2024-07-11 04:06:20 +00:00
|
|
|
$"<div class=\"cell\" style=\"
|
2024-07-10 22:03:51 +00:00
|
|
|
background-color: ($color);
|
|
|
|
color: ($textColor);
|
|
|
|
\">
|
|
|
|
($k) / ($n)
|
|
|
|
</div>" | str replace -a "\n" ""
|
|
|
|
# $n | math round --precision 1
|
|
|
|
}
|
|
|
|
|
2024-07-11 15:15:26 +00:00
|
|
|
let vizCh = { |n, table|
|
|
|
|
let noExercises = $table | where type != "Exercise"
|
|
|
|
let completed = $noExercises | where completed == "x" | length
|
|
|
|
let total = $noExercises | where type != "Exercise" | length
|
|
|
|
let ratio = if $total != 0 { $completed / $total } else { 0 }
|
|
|
|
let percent = ($ratio * 100 | math round --precision 1)
|
|
|
|
let color = if $n == 0 { "gray" } else { do $interpColor $ratio }
|
|
|
|
let textColor = if $completed == $total { "gold" } else { "white" }
|
|
|
|
|
|
|
|
$"<div data-ch=\"($n)\" class=\"cell\" style=\"
|
|
|
|
background-color: ($color);
|
|
|
|
color: ($textColor);
|
|
|
|
\">
|
|
|
|
<h3>($n)</h3>
|
|
|
|
<small>($completed) / ($total)</small>
|
|
|
|
<small style=\"font-size: 0.5rem;\">($percent)%</small>
|
|
|
|
</div>" | str replace -a "\n" ""
|
|
|
|
}
|
|
|
|
|
2024-07-10 22:03:51 +00:00
|
|
|
let vizChapter = { |n|
|
|
|
|
let nStr = $n | into string
|
|
|
|
let url = $"https://git.mzhang.io/api/v1/repos/school/type-theory/issues/($chapters | get $nStr)"
|
|
|
|
|
2024-07-11 15:15:26 +00:00
|
|
|
let table = curl -s $url
|
2024-07-10 22:03:51 +00:00
|
|
|
| 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 } }
|
2024-07-11 15:15:26 +00:00
|
|
|
|
|
|
|
let table2 = $table
|
2024-07-10 22:03:51 +00:00
|
|
|
| group-by section
|
|
|
|
| transpose
|
|
|
|
| each { $in | update column1 { do $viz ($in | where completed == "x" | length) ($in | length) } }
|
|
|
|
| sort-by -n column0
|
2024-07-11 15:15:26 +00:00
|
|
|
|
|
|
|
let newColumn1 = { column0: "Ch", column1: (do $vizCh $n $table) }
|
|
|
|
let newColumn2 = { column0: "Chnum", column1: $n }
|
|
|
|
|
|
|
|
let table3 = if ($table2 | is-empty) {
|
|
|
|
[$newColumn1, $newColumn2]
|
|
|
|
} else {
|
|
|
|
$table2 | prepend $newColumn1 | prepend $newColumn2
|
|
|
|
}
|
|
|
|
|
|
|
|
$table3
|
2024-07-10 22:03:51 +00:00
|
|
|
| transpose -r
|
|
|
|
}
|
|
|
|
|
|
|
|
$chapters
|
|
|
|
| columns
|
|
|
|
| each { do $vizChapter $in }
|
|
|
|
| reduce {|it, acc| $acc | append $it }
|
2024-07-11 15:15:26 +00:00
|
|
|
| sort-by Chnum
|
|
|
|
| reject Chnum
|
|
|
|
| transpose
|
|
|
|
| sort-by -n column0
|
|
|
|
| transpose -r
|
|
|
|
| move Ch --before 0
|
|
|
|
| to md
|
2024-07-10 22:03:51 +00:00
|
|
|
| tee { save -f html/src/generated/Progress.md }
|
|
|
|
|
|
|
|
# open breakdown.json
|
|
|
|
# | transpose
|
|
|
|
# | each {|row| [$row.column0, $row.column1.ratioCompleted] }
|