diff --git a/guile/mu/plot.scm b/guile/mu/plot.scm index adeb80f5..cd09e224 100644 --- a/guile/mu/plot.scm +++ b/guile/mu/plot.scm @@ -1,5 +1,5 @@ ;; -;; Copyright (C) 2011-2013 Dirk-Jan C. Binnema +;; Copyright (C) 2011-2022 Dirk-Jan C. Binnema ;; ;; This program is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by the @@ -26,12 +26,12 @@ (define (export-pairs pairs) "Write a temporary file with the list of PAIRS in table format, and return the file name." - (let* ((datafile (tmpnam)) - (output (open datafile (logior O_CREAT O_WRONLY) #O0600))) + (let* ((output (mkstemp "/tmp/mu-guile-XXXXXX" "w")) + (datafile (port-filename output))) (for-each - (lambda(pair) - (display (format #f "~a ~a\n" (car pair) (cdr pair)) output)) - pairs) + (lambda(pair) + (display (format #f "~a ~a\n" (car pair) (cdr pair)) output)) + pairs) (close output) datafile)) @@ -62,18 +62,21 @@ EXTRA-GNUPLOT-OPTS is a list of any additional options for gnuplot." (if (not (find-program-in-path "gnuplot")) (error "cannot find 'gnuplot' in path")) - (let ((datafile (export-pairs data)) - (gnuplot (open-pipe "gnuplot -p" OPEN_WRITE))) - (display (string-append - "reset\n" - "set term " (or output "dumb") "\n" - "set title \"" title "\"\n" - "set xlabel \"" x-label "\"\n" - "set ylabel \"" y-label "\"\n" - "set boxwidth 0.9\n" - (string-join extra-gnuplot-opts "\n") - "plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid\n") - gnuplot) + (when (zero? (length data)) + (error "No data for plotting")) + (let* ((datafile (export-pairs data)) + (gnuplot (open-pipe "gnuplot -p" OPEN_WRITE)) + (recipe + (string-append + "reset\n" + "set term " (or output "dumb") "\n" + "set title \"" title "\"\n" + "set xlabel \"" x-label "\"\n" + "set ylabel \"" y-label "\"\n" + "set boxwidth 0.9\n" + (string-join extra-gnuplot-opts "\n") + "plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid title \"\"\n"))) + (display recipe gnuplot) (close-pipe gnuplot))) ;; backward compatibility diff --git a/guile/mu/script.scm b/guile/mu/script.scm index 3a629488..45aad8aa 100644 --- a/guile/mu/script.scm +++ b/guile/mu/script.scm @@ -38,16 +38,17 @@ arguments). Possible arguments are: searchexpr (a search query) then call FUNC with args SEARCHEXPR and OUTPUT." (setlocale LC_ALL "") - (let* ((optionspec '((muhome (value #t)) - (query (value #t)) - (output (value #f)) - (help (single-char #\h) (value #f)))) - (options (getopt-long args optionspec)) - (query (option-ref options 'query #f)) - (help (option-ref options 'help #f)) - (output (option-ref options 'output #f)) - (muhome (option-ref options 'muhome #f)) - (restargs (option-ref options '() #f))) + (let* ((optionspec '((muhome (value #t)) + (query (value #t)) + (output (value #f)) + (time-unit (value #t)) ;; Ignore. + (help (single-char #\h) (value #f)))) + (options (getopt-long args optionspec)) + (query (option-ref options 'query #f)) + (help (option-ref options 'help #f)) + (output (option-ref options 'output #f)) + (muhome (option-ref options 'muhome #f)) + (restargs (option-ref options '() #f))) (if help (help-and-exit)) (mu:initialize muhome) (func (or query "") output))) diff --git a/guile/mu/stats.scm b/guile/mu/stats.scm index 90ab8362..1e73605f 100644 --- a/guile/mu/stats.scm +++ b/guile/mu/stats.scm @@ -1,5 +1,5 @@ ;; -;; Copyright (C) 2011-2013 Dirk-Jan C. Binnema +;; Copyright (C) 2011-2022 Dirk-Jan C. Binnema ;; ;; This program is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by the @@ -47,7 +47,7 @@ get back a list like ;; func to add a value to our table (update-table (lambda (val) - (let ((old-freq (or (assoc-ref table val) 0))) + (let ((old-freq (or (assoc-ref table val) 0))) (set! table (assoc-set! table val (1+ old-freq))))))) (mu:for-each-message (lambda(msg) @@ -65,9 +65,10 @@ returns #t if A < B, #f otherwise), and then take the first N." (take (sort (mu:tabulate func expr) less) n)) (define* (mu:top-n-most-frequent func n #:optional (expr #t)) - "Take the results of (mu:tabulate FUNC EXPR), and return the N items with the highest frequency." + "Take the results of (mu:tabulate FUNC EXPR), and return the N items +with the highest frequency." (top-n func (lambda (a b) (> (cdr a) (cdr b))) n expr)) - + (define* (mu:count #:optional (expr #t)) "Count the number of messages matching EXPR. If EXPR is not provided, match /all/ messages." @@ -100,7 +101,8 @@ EXPR (or #t for all). Returns #f if undefined." (define* (mu:stddev func #:optional (expr #t)) "Get the standard deviation the the values of FUNC applied to all -messages matching EXPR (or #t for all). This is the 'population' stddev, not the 'sample' stddev. Returns #f if undefined." +messages matching EXPR (or #t for all). This is the 'population' stddev, +not the 'sample' stddev. Returns #f if undefined." (stddev (map func (mu:message-list expr)))) (define* (mu:max func #:optional (expr #t)) diff --git a/guile/scripts/find-dups.scm b/guile/scripts/find-dups.scm index 778acfed..c4b62634 100755 --- a/guile/scripts/find-dups.scm +++ b/guile/scripts/find-dups.scm @@ -19,7 +19,7 @@ exec guile -e main -s $0 $@ ;; along with this program; if not, write to the Free Software Foundation, ;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -;; INFO: find duplicate messages +;; INFO: Find duplicate messages ;; INFO: options: ;; INFO: --muhome=: path to mu home dir ;; INFO: --delete: delete all but the first one (experimental, be careful!) diff --git a/guile/scripts/msgs-count.scm b/guile/scripts/msgs-count.scm index 923e3a58..9a73efe6 100755 --- a/guile/scripts/msgs-count.scm +++ b/guile/scripts/msgs-count.scm @@ -1,8 +1,7 @@ #!/bin/sh exec guile -e main -s $0 $@ !# -;; -;; Copyright (C) 2013 Dirk-Jan C. Binnema +;; Copyright (C) 2022 Dirk-Jan C. Binnema ;; ;; This program is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by the @@ -19,10 +18,11 @@ exec guile -e main -s $0 $@ ;; along with this program; if not, write to the Free Software Foundation, ;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -;; INFO: graph the number of messages per day (using gnuplot) + +;; INFO: Count the number of messages matching some query ;; INFO: options: ;; INFO: --query=: limit to messages matching query -;; INFO: --muhome=: path to mu home dir +;; INFO: --muhome=: path to mu home dir (optional) (use-modules (mu) (mu script) (mu stats))