summaryrefslogtreecommitdiff
path: root/guile
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-11-16 22:14:02 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-11-17 11:00:06 +0200
commit46c741ec9a46e8c4b75307a83e520d17d3dda982 (patch)
treed5ae910e22da456e6eb1f81ce95acd9f2abeb39f /guile
parente02df6c7864d71f40d1f88741e27e3a82b9eaca7 (diff)
guile: update scripts
Some minor improvements to the existing scripts
Diffstat (limited to 'guile')
-rw-r--r--guile/mu/plot.scm39
-rw-r--r--guile/mu/script.scm21
-rw-r--r--guile/mu/stats.scm12
-rwxr-xr-xguile/scripts/find-dups.scm2
-rwxr-xr-xguile/scripts/msgs-count.scm8
5 files changed, 44 insertions, 38 deletions
diff --git a/guile/mu/plot.scm b/guile/mu/plot.scm
index adeb80f..cd09e22 100644
--- a/guile/mu/plot.scm
+++ b/guile/mu/plot.scm
@@ -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
diff --git a/guile/mu/script.scm b/guile/mu/script.scm
index 3a62948..45aad8a 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 90ab836..1e73605 100644
--- a/guile/mu/stats.scm
+++ b/guile/mu/stats.scm
@@ -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))
diff --git a/guile/scripts/find-dups.scm b/guile/scripts/find-dups.scm
index 778acfe..c4b6263 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=<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 923e3a5..9a73efe 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 <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))