From 22e8ae76d7592ae6453cb83ac62eb87457549024 Mon Sep 17 00:00:00 2001 From: djcb Date: Sun, 27 Jan 2013 21:31:26 +0200 Subject: [PATCH] * guile: add msgs-count script --- guile/mu-guile.texi | 35 ++++++++++++++++++++++++++++++++ guile/mu/stats.scm | 1 - guile/scripts/Makefile.am | 1 + guile/scripts/msgs-count.scm | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 guile/scripts/msgs-count.scm diff --git a/guile/mu-guile.texi b/guile/mu-guile.texi index 808028f9..21c98c60 100644 --- a/guile/mu-guile.texi +++ b/guile/mu-guile.texi @@ -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 diff --git a/guile/mu/stats.scm b/guile/mu/stats.scm index f2f296c1..0a8f0e69 100644 --- a/guile/mu/stats.scm +++ b/guile/mu/stats.scm @@ -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) diff --git a/guile/scripts/Makefile.am b/guile/scripts/Makefile.am index 47ffa65f..fe381174 100644 --- a/guile/scripts/Makefile.am +++ b/guile/scripts/Makefile.am @@ -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 \ diff --git a/guile/scripts/msgs-count.scm b/guile/scripts/msgs-count.scm new file mode 100755 index 00000000..4d4be164 --- /dev/null +++ b/guile/scripts/msgs-count.scm @@ -0,0 +1,39 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2013 Dirk-Jan C. Binnema +;; +;; 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=: limit to messages matching query +;; INFO: --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: