add scribble view for plot lol

This commit is contained in:
xenia 2020-12-04 23:59:00 -05:00
parent 5365272e27
commit 06ab477340
3 changed files with 99 additions and 96 deletions

View File

@ -1,13 +1,14 @@
#!/usr/bin/env racket
#lang racket
(require "aoc-lib.rkt" plot)
(plot-new-window? #t)
(require "aoc-lib.rkt" plot/no-gui)
(provide make-plot)
(define data
(define (make-plot plot-func)
(define data
(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)
(match el
[(? string?) (string->symbol el)]
@ -23,14 +24,14 @@
(hash-ref* (hash-ref hash fst) rst failure)
(do-failure))]))
(define members (hash-ref data 'members))
(define max-pts (hash-count members))
(define member-names (make-hash))
(define members (hash-ref data 'members))
(define max-pts (hash-count members))
(define member-names (make-hash))
(struct tl-entry [mid day level] #:transparent)
(define timeline (make-hash))
(struct tl-entry [mid day level] #:transparent)
(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 name (hash-ref val 'name))
(hash-set! member-names mid name)
@ -40,48 +41,31 @@
[(app string->number (? number? time))
(hash-update! timeline time (lambda (v) (cons (tl-entry mid day level) v)) '())])))
(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 timestamps (sort (hash-keys timeline) <))
(define point-values (make-hash))
(for* ([day (in-range 1 26)] [level (in-range 1 3)])
(define point-values (make-hash))
(for* ([day (in-range 1 26)] [level (in-range 1 3)])
(hash-set! point-values (cons day level)
(if (= day 1)
0 ; day 1 is worth no points u___u
max-pts)))
(define point-tls (make-hash))
(for ([(mid _) (in-hash member-names)])
(define point-tls (make-hash))
(for ([(mid _) (in-hash member-names)])
(hash-set! point-tls mid (vector)))
(define (get-last-pts data)
(define (get-last-pts data)
(if (vector-empty? data)
0
(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
(lambda (m-tl)
(vector-append m-tl (vector (vector time (get-last-pts m-tl))
(vector time pts))))))
(for ([time (in-list timestamps)])
(for ([time (in-list timestamps)])
(for ([solve (in-list (hash-ref timeline time))])
(match-define (tl-entry mid day level) solve)
(define key (cons day level))
@ -91,17 +75,18 @@
(hash-set! point-values key (max 0 (sub1 pts)))
(set-pts! mid time (+ old-pts pts))))
(define now (current-seconds))
(for ([(mid data) (in-hash point-tls)])
(define now (current-seconds))
(for ([(mid data) (in-hash point-tls)])
(define pts (get-last-pts data))
(set-pts! mid now pts))
(plot-x-ticks (date-ticks))
(define ordered-mids
(plot-x-ticks (date-ticks))
(define ordered-mids
(sort (hash-keys point-tls)
(lambda (a 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)
#:label (format "~a (~a pts)" (hash-ref member-names mid)
(get-last-pts (hash-ref point-tls mid)))
@ -109,4 +94,9 @@
#:style mid
#:width 2))
#:x-label "date/time"
#:y-label "points")
#:y-label "points"))
(module+ main
(require plot)
(plot-new-window? #t)
(make-plot plot))

3
scripts/plot.css Normal file
View File

@ -0,0 +1,3 @@
html, body { background: black; color: white; font-family: monospace; }
h1, h2, h3, p { font-family: monospace; }

10
scripts/plot.scrbl Normal file
View File

@ -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))