diff --git a/toys/muile/mu-stats.scm b/toys/muile/mu-stats.scm index 758860f2..287e4923 100644 --- a/toys/muile/mu-stats.scm +++ b/toys/muile/mu-stats.scm @@ -65,78 +65,96 @@ optional EXPR is provided, only consider messages that match it.\n" (let ((freq (assoc-ref table val))) (set! table (assoc-set! table val (+ 1 (if (eq? freq #f) 0 freq)))))) vals))) EXPR) - (sort table - (lambda(a b) - (if (string? a) - (string (cdr a) (cdr b)))))) - (list-head top (min (length top) N)))) + (top (sort freq (lambda (a b) (< (cdr b) (cdr a) ))))) + (list-head top (min (length freq) N)))) -(define* (mu:stats:top-n-to N #:optional (EXPR "")) - "Get the Top-N To:-recipients. If the optional EXPR is provided, only -consider the messages that match it." +(define* (mu:stats:top-n-to #:optional (N 10) (EXPR "")) + "Get the Top-N To:-recipients. If the optional N is not provided, +use 10. If the optional EXPR is provided, only consider the messages +that match it." (mu:stats:top-n (lambda (msg) (mu:msg:to msg)) N EXPR)) -(define* (mu:stats:top-n-from N #:optional (EXPR "")) - "Get the Top-N senders (From:). If the optional EXPR is provided, -only consider the messages that match it." +(define* (mu:stats:top-n-from #:optional (N 10) (EXPR "")) + "Get the Top-N senders (From:). If the optional N is not provided, +use 10. If the optional EXPR is provided, only consider the messages +that match it." (mu:stats:top-n (lambda (msg) (mu:msg:from msg)) N EXPR)) -(define* (mu:stats:top-n-subject N #:optional (EXPR "")) - "Get the Top-N subjects. If the optional EXPR is provided, -only consider the messages that match it." +(define* (mu:stats:top-n-subject #:optional (N 10) (EXPR "")) + "Get the Top-N subjects. If the optional N is not provided, +use 10. If the optional EXPR is provided, only consider the messages +that match it." (mu:stats:top-n (lambda (msg) (mu:msg:subject msg)) N EXPR)) -(define* (mu:stats:table pairs) +(define (mu:stats:table pairs) "display a list of PAIRS in a table-like fashion" (let ((maxlen 0)) (for-each ;; find the widest in the first col (lambda (pair) - (set! maxlen (max maxlen (string-length - (format #f "~s " (car pair)))))) pairs) + (set! maxlen + (max maxlen (string-length (format #f "~s " (car pair)))))) pairs) (for-each (lambda (pair) - (display (car pair)) - (display (format #f "~v_" (- maxlen (string-length (car pair))))) - (display (cdr pair)) - (newline)) pairs))) + (let ((first (format #f "~s" (car pair))) + (second (format #f "~s" (cdr pair)))) + (display (format #f "~A~v_~A\n" + first (- maxlen (string-length first)) second)))) + pairs))) - +(define (mu:stats:plot pairs) + "plot a table using gnuplot" + ;; create a tmpfile with the data... + (let* ((datafile (tmpnam)) + (output (open datafile (logior O_CREAT O_WRONLY) #O0644))) + (for-each + (lambda (pair) (display (format #f "~A ~A\n" (car pair) (cdr pair)) output)) + pairs) + (close-output-port output) + ;; now, display it. + (system (format #f "gnuplot -p -e 'plot \"~A\" w boxes fs pattern 2'" datafile))))