* guile: add msgs-count script

This commit is contained in:
djcb 2013-01-27 21:31:26 +02:00
parent d1a42504b2
commit 22e8ae76d7
4 changed files with 75 additions and 1 deletions

View File

@ -707,10 +707,45 @@ probably be a bit more elegant.
about the messages in the database.
@menu
* Basics:: @code{mu:count}, @code{mu:average}, ...
* Tabulating values:: @code{mu:tabulate}
* Most frequent values:: @code{mu:top-n-most-frequent}
@end menu
@node Basics
@section Basics
Let's look at some of the basic statistical operations available, in an
interactive session:
@example
GNU Guile 2.0.5.123-4bd53
Copyright (C) 1995-2012 Free Software Foundation, Inc.
Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.
Enter `,help' for help.
scheme@@(guile-user)> ;; load modules, initialize mu
scheme@@(guile-user)> (use-modules (mu) (mu stats))
scheme@@(guile-user)> (mu:initialize)
scheme@@(guile-user)>
scheme@@(guile-user)> ;; count the number of messages with 'hello' in their subject
scheme@@(guile-user)> (mu:count "subject:hello")
$1 = 162
scheme@@(guile-user)> ;; average the size of messages with hello in their subject
scheme@@(guile-user)> (mu:average mu:size "subject:hello")
$2 = 34597733/81
scheme@@(guile-user)> (exact->inexact $2)
$3 = 427132.506172839
scheme@@(guile-user)> ;; calculate the correlation between message size and
scheme@@(guile-user)> ;; subject length
scheme@@(guile-user)> (mu:correl mu:size (lambda (msg)
(string-length (mu:subject msg))) "subject:hello")
$5 = -0.10804368622292
scheme@@(guile-user)>
@end example
@node Tabulating values
@section Tabulating values

View File

@ -77,7 +77,6 @@ provided, match /all/ messages."
expr)
num))
(define (average lst)
"Calculate the average of a list LST of numbers, or #f if undefined."
(if (null? lst)

View File

@ -17,6 +17,7 @@
include $(top_srcdir)/gtest.mk
EXTRA_DIST= \
msgs-count.scm \
msgs-per-year.scm \
msgs-per-hour.scm \
msgs-per-month.scm \

39
guile/scripts/msgs-count.scm Executable file
View File

@ -0,0 +1,39 @@
#!/bin/sh
exec guile -e main -s $0 $@
!#
;;
;; Copyright (C) 2013 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
;; Free Software Foundation; either version 3, or (at your option) any
;; later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software Foundation,
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
;; 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
(use-modules (mu) (mu script) (mu stats))
(define (count expr text-only)
"Print the total number of messages matching QUERY."
(display (mu:count expr))
(newline))
(define (main args)
(mu:run-stats args count))
;; Local Variables:
;; mode: scheme
;; End: