guile: update scripts

Some minor improvements to the existing scripts
This commit is contained in:
Dirk-Jan C. Binnema 2022-11-16 22:14:02 +02:00
parent e02df6c786
commit 46c741ec9a
5 changed files with 44 additions and 38 deletions

View File

@ -1,5 +1,5 @@
;;
;; Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;; Copyright (C) 2011-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;;
;; 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

View File

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

View File

@ -1,5 +1,5 @@
;;
;; Copyright (C) 2011-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;; Copyright (C) 2011-2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;;
;; 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))

View File

@ -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=<muhome>: path to mu home dir
;; INFO: --delete: delete all but the first one (experimental, be careful!)

View File

@ -1,8 +1,7 @@
#!/bin/sh
exec guile -e main -s $0 $@
!#
;;
;; Copyright (C) 2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;; Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;;
;; 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=<query>: limit to messages matching query
;; INFO: --muhome=<muhome>: path to mu home dir
;; INFO: --muhome=<muhome>: path to mu home dir (optional)
(use-modules (mu) (mu script) (mu stats))