From 391f2a43eb2939eb41bf0153bb9887f96a2e1a25 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Thu, 14 Jul 2011 22:21:32 +0300 Subject: [PATCH] * mu-stats.scm: support optional arguments (define*) and top-n --- toys/muile/mu-stats.scm | 88 +++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/toys/muile/mu-stats.scm b/toys/muile/mu-stats.scm index 7f1b158b..758860f2 100644 --- a/toys/muile/mu-stats.scm +++ b/toys/muile/mu-stats.scm @@ -16,19 +16,17 @@ ;; along with this program; if not, write to the Free Software Foundation, ;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - ;; some guile/scheme functions to get various statistics of my mu ;; message store. ;; note, this is a rather inefficient way to calculate the number; for ;; demonstration purposes only -(define (mu:stats:count EXPR) +(define* (mu:stats:count #:optional (EXPR "")) "Count the total number of messages. If the optional EXPR is provided, only count the messages that match it.\n" (mu:store:foreach (lambda(msg) #f) EXPR)) - -(define (mu:stats:average FUNC EXPR) +(define* (mu:stats:average FUNC #:optional (EXPR "")) "Count the average of the result of applying FUNC on all messages. If the optional EXPR is provided, only consider the messages that match it.\n" @@ -37,14 +35,12 @@ that match it.\n" (lambda(msg) (set! sum (+ sum (FUNC msg)))) EXPR))) (if (= n 0) 0 (exact->inexact (/ sum n))))) - -(define (mu:stats:average-size EXPR) +(define* (mu:stats:average-size #:optional (EXPR "")) "Calculate the average message size. If the optional EXPR is provided, only consider the messages that match it.\n" (mu:stats:average (lambda(msg) (mu:msg:size msg)) EXPR)) - -(define (mu:stats:average-recipient-number EXPR) +(define* (mu:stats:average-recipient-number #:optional (EXPR "")) "Calculate the average number of recipients (To: + CC: + Bcc:). If the optional EXPR is provided, only consider the messages that match it.\n" @@ -53,42 +49,94 @@ it.\n" (length (mu:msg:cc msg)) (length (mu:msg:bcc msg)))) EXPR)) -(define (mu:stats:frequency FUNC EXPR) - "FUNC is a function that takes a Msg and returns some number between -0 and (cdr a) (cdr b)))))) + (list-head top (min (length top) 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." + (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." + (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." + (mu:stats:top-n + (lambda (msg) (mu:msg:subject msg)) N EXPR)) + +(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) + (for-each + (lambda (pair) + (display (car pair)) + (display (format #f "~v_" (- maxlen (string-length (car pair))))) + (display (cdr pair)) + (newline)) pairs))) + +