From 59645ba2687b1cd96e0401c2e3ebc9ce5b8f7a88 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 16 Jul 2011 19:46:52 +0300 Subject: [PATCH] * update guile-stats functions a bit --- toys/muile/mu-stats.scm | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/toys/muile/mu-stats.scm b/toys/muile/mu-stats.scm index 287e4923..316d430e 100644 --- a/toys/muile/mu-stats.scm +++ b/toys/muile/mu-stats.scm @@ -132,7 +132,7 @@ 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 #:optional (port (current-output-port))) "display a list of PAIRS in a table-like fashion" (let ((maxlen 0)) (for-each ;; find the widest in the first col @@ -144,17 +144,12 @@ that match it." (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)))) + first (- maxlen (string-length first)) second) port))) pairs))) - -(define (mu:stats:plot pairs) - "plot a table using gnuplot" - ;; create a tmpfile with the data... + +(define (mu:stats:export pairs) + "export pairs to a temporary file, return its name" (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)))) + (mu:stats:table pairs output) + datafile))