add scribble view for plot lol
This commit is contained in:
parent
5365272e27
commit
06ab477340
72
scripts/plot
72
scripts/plot
|
@ -1,13 +1,14 @@
|
||||||
#!/usr/bin/env racket
|
#!/usr/bin/env racket
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
(require "aoc-lib.rkt" plot)
|
(require "aoc-lib.rkt" plot/no-gui)
|
||||||
(plot-new-window? #t)
|
(provide make-plot)
|
||||||
|
|
||||||
(define data
|
(define (make-plot plot-func)
|
||||||
|
(define data
|
||||||
(aoc-fetch-leaderboard (getenv "AOC_YEAR") (getenv "AOC_LEADERBOARD") (getenv "AOC_SESSION")))
|
(aoc-fetch-leaderboard (getenv "AOC_YEAR") (getenv "AOC_LEADERBOARD") (getenv "AOC_SESSION")))
|
||||||
|
|
||||||
(define (hash-ref* hash path [failure (lambda () (error "no such key" path))])
|
(define (hash-ref* hash path [failure (lambda () (error "no such key" path))])
|
||||||
(define (->symbol el)
|
(define (->symbol el)
|
||||||
(match el
|
(match el
|
||||||
[(? string?) (string->symbol el)]
|
[(? string?) (string->symbol el)]
|
||||||
|
@ -23,14 +24,14 @@
|
||||||
(hash-ref* (hash-ref hash fst) rst failure)
|
(hash-ref* (hash-ref hash fst) rst failure)
|
||||||
(do-failure))]))
|
(do-failure))]))
|
||||||
|
|
||||||
(define members (hash-ref data 'members))
|
(define members (hash-ref data 'members))
|
||||||
(define max-pts (hash-count members))
|
(define max-pts (hash-count members))
|
||||||
(define member-names (make-hash))
|
(define member-names (make-hash))
|
||||||
|
|
||||||
(struct tl-entry [mid day level] #:transparent)
|
(struct tl-entry [mid day level] #:transparent)
|
||||||
(define timeline (make-hash))
|
(define timeline (make-hash))
|
||||||
|
|
||||||
(for ([(mid-in val) (in-hash members)])
|
(for ([(mid-in val) (in-hash members)])
|
||||||
(define mid (string->number (symbol->string mid-in)))
|
(define mid (string->number (symbol->string mid-in)))
|
||||||
(define name (hash-ref val 'name))
|
(define name (hash-ref val 'name))
|
||||||
(hash-set! member-names mid name)
|
(hash-set! member-names mid name)
|
||||||
|
@ -40,48 +41,31 @@
|
||||||
[(app string->number (? number? time))
|
[(app string->number (? number? time))
|
||||||
(hash-update! timeline time (lambda (v) (cons (tl-entry mid day level) v)) '())])))
|
(hash-update! timeline time (lambda (v) (cons (tl-entry mid day level) v)) '())])))
|
||||||
|
|
||||||
(define timestamps (sort (hash-keys timeline) <))
|
(define timestamps (sort (hash-keys timeline) <))
|
||||||
;; vector of day to vector of part to ordered list of solvers
|
|
||||||
; (define chals (for/vector ([day (in-range 1 26)]) (make-vector 2 '())))
|
|
||||||
;
|
|
||||||
; (for ([time (in-list timestamps)])
|
|
||||||
; (for ([solve (in-list (hash-ref timeline time))])
|
|
||||||
; (match-define (tl-entry mid day level) solve)
|
|
||||||
; (define old (vector-ref (vector-ref chals (sub1 day)) (sub1 level)))
|
|
||||||
; (vector-set! (vector-ref chals (sub1 day)) (sub1 level) (append old (list mid)))))
|
|
||||||
;
|
|
||||||
; (define (total-points mem)
|
|
||||||
; ;; day 1 is worth no points u___u
|
|
||||||
; (for*/sum ([day (in-range 2 26)] [level (in-range 1 3)])
|
|
||||||
; (define solves-for-day (vector-ref (vector-ref chals (sub1 day)) (sub1 level)))
|
|
||||||
; (match (index-of solves-for-day mem)
|
|
||||||
; [#f 0]
|
|
||||||
; [x (- max-pts x)])))
|
|
||||||
; (total-points 1067937)
|
|
||||||
|
|
||||||
(define point-values (make-hash))
|
(define point-values (make-hash))
|
||||||
(for* ([day (in-range 1 26)] [level (in-range 1 3)])
|
(for* ([day (in-range 1 26)] [level (in-range 1 3)])
|
||||||
(hash-set! point-values (cons day level)
|
(hash-set! point-values (cons day level)
|
||||||
(if (= day 1)
|
(if (= day 1)
|
||||||
0 ; day 1 is worth no points u___u
|
0 ; day 1 is worth no points u___u
|
||||||
max-pts)))
|
max-pts)))
|
||||||
|
|
||||||
(define point-tls (make-hash))
|
(define point-tls (make-hash))
|
||||||
(for ([(mid _) (in-hash member-names)])
|
(for ([(mid _) (in-hash member-names)])
|
||||||
(hash-set! point-tls mid (vector)))
|
(hash-set! point-tls mid (vector)))
|
||||||
|
|
||||||
(define (get-last-pts data)
|
(define (get-last-pts data)
|
||||||
(if (vector-empty? data)
|
(if (vector-empty? data)
|
||||||
0
|
0
|
||||||
(vector-ref (vector-ref data (sub1 (vector-length data))) 1)))
|
(vector-ref (vector-ref data (sub1 (vector-length data))) 1)))
|
||||||
|
|
||||||
(define (set-pts! mid time pts)
|
(define (set-pts! mid time pts)
|
||||||
(hash-update! point-tls mid
|
(hash-update! point-tls mid
|
||||||
(lambda (m-tl)
|
(lambda (m-tl)
|
||||||
(vector-append m-tl (vector (vector time (get-last-pts m-tl))
|
(vector-append m-tl (vector (vector time (get-last-pts m-tl))
|
||||||
(vector time pts))))))
|
(vector time pts))))))
|
||||||
|
|
||||||
(for ([time (in-list timestamps)])
|
(for ([time (in-list timestamps)])
|
||||||
(for ([solve (in-list (hash-ref timeline time))])
|
(for ([solve (in-list (hash-ref timeline time))])
|
||||||
(match-define (tl-entry mid day level) solve)
|
(match-define (tl-entry mid day level) solve)
|
||||||
(define key (cons day level))
|
(define key (cons day level))
|
||||||
|
@ -91,17 +75,18 @@
|
||||||
(hash-set! point-values key (max 0 (sub1 pts)))
|
(hash-set! point-values key (max 0 (sub1 pts)))
|
||||||
(set-pts! mid time (+ old-pts pts))))
|
(set-pts! mid time (+ old-pts pts))))
|
||||||
|
|
||||||
(define now (current-seconds))
|
(define now (current-seconds))
|
||||||
(for ([(mid data) (in-hash point-tls)])
|
(for ([(mid data) (in-hash point-tls)])
|
||||||
(define pts (get-last-pts data))
|
(define pts (get-last-pts data))
|
||||||
(set-pts! mid now pts))
|
(set-pts! mid now pts))
|
||||||
|
|
||||||
(plot-x-ticks (date-ticks))
|
(plot-x-ticks (date-ticks))
|
||||||
(define ordered-mids
|
(define ordered-mids
|
||||||
(sort (hash-keys point-tls)
|
(sort (hash-keys point-tls)
|
||||||
(lambda (a b)
|
(lambda (a b)
|
||||||
(>= (get-last-pts (hash-ref point-tls a)) (get-last-pts (hash-ref point-tls b))))))
|
(>= (get-last-pts (hash-ref point-tls a)) (get-last-pts (hash-ref point-tls b))))))
|
||||||
(plot (for/list ([mid (in-list ordered-mids)])
|
(plot-func
|
||||||
|
(for/list ([mid (in-list ordered-mids)])
|
||||||
(lines (hash-ref point-tls mid)
|
(lines (hash-ref point-tls mid)
|
||||||
#:label (format "~a (~a pts)" (hash-ref member-names mid)
|
#:label (format "~a (~a pts)" (hash-ref member-names mid)
|
||||||
(get-last-pts (hash-ref point-tls mid)))
|
(get-last-pts (hash-ref point-tls mid)))
|
||||||
|
@ -109,4 +94,9 @@
|
||||||
#:style mid
|
#:style mid
|
||||||
#:width 2))
|
#:width 2))
|
||||||
#:x-label "date/time"
|
#:x-label "date/time"
|
||||||
#:y-label "points")
|
#:y-label "points"))
|
||||||
|
|
||||||
|
(module+ main
|
||||||
|
(require plot)
|
||||||
|
(plot-new-window? #t)
|
||||||
|
(make-plot plot))
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
html, body { background: black; color: white; font-family: monospace; }
|
||||||
|
|
||||||
|
h1, h2, h3, p { font-family: monospace; }
|
|
@ -0,0 +1,10 @@
|
||||||
|
#lang scribble/base
|
||||||
|
|
||||||
|
@(require plot/no-gui racket "plot")
|
||||||
|
|
||||||
|
@title[#:style '(toc-hidden no-sidebar no-index no-toc+aux)]{BLÁHAJ score chart}
|
||||||
|
|
||||||
|
meow
|
||||||
|
|
||||||
|
@(parameterize ([plot-width 2048] [plot-height 1024])
|
||||||
|
(make-plot plot-pict))
|
Loading…
Reference in New Issue