mirror of https://github.com/djcb/mu.git
* guile: add msgs-count script
This commit is contained in:
parent
d1a42504b2
commit
22e8ae76d7
|
@ -707,10 +707,45 @@ probably be a bit more elegant.
|
||||||
about the messages in the database.
|
about the messages in the database.
|
||||||
|
|
||||||
@menu
|
@menu
|
||||||
|
* Basics:: @code{mu:count}, @code{mu:average}, ...
|
||||||
* Tabulating values:: @code{mu:tabulate}
|
* Tabulating values:: @code{mu:tabulate}
|
||||||
* Most frequent values:: @code{mu:top-n-most-frequent}
|
* Most frequent values:: @code{mu:top-n-most-frequent}
|
||||||
@end menu
|
@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
|
@node Tabulating values
|
||||||
@section Tabulating values
|
@section Tabulating values
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,6 @@ provided, match /all/ messages."
|
||||||
expr)
|
expr)
|
||||||
num))
|
num))
|
||||||
|
|
||||||
|
|
||||||
(define (average lst)
|
(define (average lst)
|
||||||
"Calculate the average of a list LST of numbers, or #f if undefined."
|
"Calculate the average of a list LST of numbers, or #f if undefined."
|
||||||
(if (null? lst)
|
(if (null? lst)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
include $(top_srcdir)/gtest.mk
|
include $(top_srcdir)/gtest.mk
|
||||||
|
|
||||||
EXTRA_DIST= \
|
EXTRA_DIST= \
|
||||||
|
msgs-count.scm \
|
||||||
msgs-per-year.scm \
|
msgs-per-year.scm \
|
||||||
msgs-per-hour.scm \
|
msgs-per-hour.scm \
|
||||||
msgs-per-month.scm \
|
msgs-per-month.scm \
|
||||||
|
|
|
@ -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:
|
Loading…
Reference in New Issue