mirror of https://github.com/djcb/mu.git
guile: update scripts
Some minor improvements to the existing scripts
This commit is contained in:
parent
e02df6c786
commit
46c741ec9a
|
@ -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
|
;; 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
|
;; under the terms of the GNU General Public License as published by the
|
||||||
|
@ -26,12 +26,12 @@
|
||||||
(define (export-pairs pairs)
|
(define (export-pairs pairs)
|
||||||
"Write a temporary file with the list of PAIRS in table format, and
|
"Write a temporary file with the list of PAIRS in table format, and
|
||||||
return the file name."
|
return the file name."
|
||||||
(let* ((datafile (tmpnam))
|
(let* ((output (mkstemp "/tmp/mu-guile-XXXXXX" "w"))
|
||||||
(output (open datafile (logior O_CREAT O_WRONLY) #O0600)))
|
(datafile (port-filename output)))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda(pair)
|
(lambda(pair)
|
||||||
(display (format #f "~a ~a\n" (car pair) (cdr pair)) output))
|
(display (format #f "~a ~a\n" (car pair) (cdr pair)) output))
|
||||||
pairs)
|
pairs)
|
||||||
(close output)
|
(close output)
|
||||||
datafile))
|
datafile))
|
||||||
|
|
||||||
|
@ -62,18 +62,21 @@ EXTRA-GNUPLOT-OPTS is a list
|
||||||
of any additional options for gnuplot."
|
of any additional options for gnuplot."
|
||||||
(if (not (find-program-in-path "gnuplot"))
|
(if (not (find-program-in-path "gnuplot"))
|
||||||
(error "cannot find 'gnuplot' in path"))
|
(error "cannot find 'gnuplot' in path"))
|
||||||
(let ((datafile (export-pairs data))
|
(when (zero? (length data))
|
||||||
(gnuplot (open-pipe "gnuplot -p" OPEN_WRITE)))
|
(error "No data for plotting"))
|
||||||
(display (string-append
|
(let* ((datafile (export-pairs data))
|
||||||
"reset\n"
|
(gnuplot (open-pipe "gnuplot -p" OPEN_WRITE))
|
||||||
"set term " (or output "dumb") "\n"
|
(recipe
|
||||||
"set title \"" title "\"\n"
|
(string-append
|
||||||
"set xlabel \"" x-label "\"\n"
|
"reset\n"
|
||||||
"set ylabel \"" y-label "\"\n"
|
"set term " (or output "dumb") "\n"
|
||||||
"set boxwidth 0.9\n"
|
"set title \"" title "\"\n"
|
||||||
(string-join extra-gnuplot-opts "\n")
|
"set xlabel \"" x-label "\"\n"
|
||||||
"plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid\n")
|
"set ylabel \"" y-label "\"\n"
|
||||||
gnuplot)
|
"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)))
|
(close-pipe gnuplot)))
|
||||||
|
|
||||||
;; backward compatibility
|
;; backward compatibility
|
||||||
|
|
|
@ -38,16 +38,17 @@ arguments). Possible arguments are:
|
||||||
searchexpr (a search query)
|
searchexpr (a search query)
|
||||||
then call FUNC with args SEARCHEXPR and OUTPUT."
|
then call FUNC with args SEARCHEXPR and OUTPUT."
|
||||||
(setlocale LC_ALL "")
|
(setlocale LC_ALL "")
|
||||||
(let* ((optionspec '((muhome (value #t))
|
(let* ((optionspec '((muhome (value #t))
|
||||||
(query (value #t))
|
(query (value #t))
|
||||||
(output (value #f))
|
(output (value #f))
|
||||||
(help (single-char #\h) (value #f))))
|
(time-unit (value #t)) ;; Ignore.
|
||||||
(options (getopt-long args optionspec))
|
(help (single-char #\h) (value #f))))
|
||||||
(query (option-ref options 'query #f))
|
(options (getopt-long args optionspec))
|
||||||
(help (option-ref options 'help #f))
|
(query (option-ref options 'query #f))
|
||||||
(output (option-ref options 'output #f))
|
(help (option-ref options 'help #f))
|
||||||
(muhome (option-ref options 'muhome #f))
|
(output (option-ref options 'output #f))
|
||||||
(restargs (option-ref options '() #f)))
|
(muhome (option-ref options 'muhome #f))
|
||||||
|
(restargs (option-ref options '() #f)))
|
||||||
(if help (help-and-exit))
|
(if help (help-and-exit))
|
||||||
(mu:initialize muhome)
|
(mu:initialize muhome)
|
||||||
(func (or query "") output)))
|
(func (or query "") output)))
|
||||||
|
|
|
@ -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
|
;; 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
|
;; 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
|
;; func to add a value to our table
|
||||||
(update-table
|
(update-table
|
||||||
(lambda (val)
|
(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)))))))
|
(set! table (assoc-set! table val (1+ old-freq)))))))
|
||||||
(mu:for-each-message
|
(mu:for-each-message
|
||||||
(lambda(msg)
|
(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))
|
(take (sort (mu:tabulate func expr) less) n))
|
||||||
|
|
||||||
(define* (mu:top-n-most-frequent func n #:optional (expr #t))
|
(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))
|
(top-n func (lambda (a b) (> (cdr a) (cdr b))) n expr))
|
||||||
|
|
||||||
(define* (mu:count #:optional (expr #t))
|
(define* (mu:count #:optional (expr #t))
|
||||||
"Count the number of messages matching EXPR. If EXPR is not
|
"Count the number of messages matching EXPR. If EXPR is not
|
||||||
provided, match /all/ messages."
|
provided, match /all/ messages."
|
||||||
|
@ -100,7 +101,8 @@ EXPR (or #t for all). Returns #f if undefined."
|
||||||
|
|
||||||
(define* (mu:stddev func #:optional (expr #t))
|
(define* (mu:stddev func #:optional (expr #t))
|
||||||
"Get the standard deviation the the values of FUNC applied to all
|
"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))))
|
(stddev (map func (mu:message-list expr))))
|
||||||
|
|
||||||
(define* (mu:max func #:optional (expr #t))
|
(define* (mu:max func #:optional (expr #t))
|
||||||
|
|
|
@ -19,7 +19,7 @@ exec guile -e main -s $0 $@
|
||||||
;; along with this program; if not, write to the Free Software Foundation,
|
;; along with this program; if not, write to the Free Software Foundation,
|
||||||
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
;; INFO: find duplicate messages
|
;; INFO: Find duplicate messages
|
||||||
;; INFO: options:
|
;; INFO: options:
|
||||||
;; INFO: --muhome=<muhome>: path to mu home dir
|
;; INFO: --muhome=<muhome>: path to mu home dir
|
||||||
;; INFO: --delete: delete all but the first one (experimental, be careful!)
|
;; INFO: --delete: delete all but the first one (experimental, be careful!)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
exec guile -e main -s $0 $@
|
exec guile -e main -s $0 $@
|
||||||
!#
|
!#
|
||||||
;;
|
;; Copyright (C) 2022 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
;; Copyright (C) 2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
||||||
;;
|
;;
|
||||||
;; This program is free software; you can redistribute it and/or modify it
|
;; 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
|
;; 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,
|
;; along with this program; if not, write to the Free Software Foundation,
|
||||||
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
;; 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: options:
|
||||||
;; INFO: --query=<query>: limit to messages matching query
|
;; 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))
|
(use-modules (mu) (mu script) (mu stats))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue