From 6d19880cedcd1d0db802014399dc714c1b781761 Mon Sep 17 00:00:00 2001 From: djcb Date: Fri, 19 Oct 2012 00:49:14 +0300 Subject: [PATCH] * guile: add a bunch of statistics scripts --- guile/scripts/stats/msg-per-year.scm | 41 +++++++ guile/scripts/stats/msg-stats.scm | 128 -------------------- guile/scripts/stats/msgs-per-day.scm | 42 +++++++ guile/scripts/stats/msgs-per-hour.scm | 44 +++++++ guile/scripts/stats/msgs-per-month.scm | 43 +++++++ guile/scripts/stats/msgs-per-year-month.scm | 45 +++++++ guile/scripts/stats/msgs-per-year.scm | 42 +++++++ 7 files changed, 257 insertions(+), 128 deletions(-) create mode 100755 guile/scripts/stats/msg-per-year.scm delete mode 100755 guile/scripts/stats/msg-stats.scm create mode 100755 guile/scripts/stats/msgs-per-day.scm create mode 100755 guile/scripts/stats/msgs-per-hour.scm create mode 100755 guile/scripts/stats/msgs-per-month.scm create mode 100755 guile/scripts/stats/msgs-per-year-month.scm create mode 100755 guile/scripts/stats/msgs-per-year.scm diff --git a/guile/scripts/stats/msg-per-year.scm b/guile/scripts/stats/msg-per-year.scm new file mode 100755 index 00000000..e9001157 --- /dev/null +++ b/guile/scripts/stats/msg-per-year.scm @@ -0,0 +1,41 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2012 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. + +(use-modules (mu) (mu script) (mu stats) (mu plot)) + +(define (per-year expr text-only) + "Count the total number of messages for each weekday (0-6 for +Sun..Sat) that match EXPR. If TEXT-ONLY is true, use a plain-text +display, otherwise, use a graphical window." + (mu:plot + (sort (mu:tabulate + (lambda (msg) + (+ 1900 (tm:year (localtime (mu:date msg))))) expr) + (lambda (x y) (< (car x) (car y)))) + (format #f "Messages per year matching ~a" expr) + "Year" "Messages" text-only)) + +(define (main args) + (mu:run args per-year)) + +;; Local Variables: +;; mode: scheme +;; End: diff --git a/guile/scripts/stats/msg-stats.scm b/guile/scripts/stats/msg-stats.scm deleted file mode 100755 index 18a3a47b..00000000 --- a/guile/scripts/stats/msg-stats.scm +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/sh -exec guile -e main -s $0 $@ -!# -;; -;; Copyright (C) 2011-2012 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. -(setlocale LC_ALL "") - -(use-modules (ice-9 getopt-long) (ice-9 optargs) (ice-9 popen) (ice-9 format)) -(use-modules (mu) (mu stats) (mu plot)) - -(define (per-hour expr plain-text) - "Count the total number of messages for each weekday (0-6 for -Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text -display, otherwise, use a graphical window." - (mu:plot - (sort - (mu:tabulate - (lambda (msg) - (tm:hour (localtime (mu:date msg)))) expr) - (lambda (x y) (< (car x) (car y)))) - (format #f "Messages per hour matching ~a" expr) "Hour" "Messages" plain-text)) - -(define (per-day expr plain-text) - "Count the total number of messages for each weekday (0-6 for -Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text -display, otherwise, use a graphical window." - (mu:plot - (mu:weekday-numbers->names - (sort (mu:tabulate - (lambda (msg) - (tm:wday (localtime (mu:date msg)))) expr) - (lambda (x y) (< (car x) (car y))))) - (format #f "Messages per weekday matching ~a" expr) "Day" "Messages" plain-text)) - -(define (per-month expr plain-text) - "Count the total number of messages for each weekday (0-6 for -Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text -display, otherwise, use a graphical window." - (mu:plot - (mu:month-numbers->names - (sort - (mu:tabulate - (lambda (msg) - (tm:mon (localtime (mu:date msg)))) expr) - (lambda (x y) (< (car x) (car y))))) - (format #f "Messages per month matching ~a" expr) "Month" "Messages" plain-text)) - - -(define (per-year-month expr plain-text) - "Count the total number of messages for each weekday (0-6 for -Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text -display, otherwise, use a graphical window." - (mu:plot - (sort (mu:tabulate - (lambda (msg) - (string->number - (format #f "~d~2'0d" - (+ 1900 (tm:year (localtime (mu:date msg)))) - (tm:mon (localtime (mu:date msg)))))) - expr) - (lambda (x y) (< (car x) (car y)))) - (format #f "Messages per year/month matching ~a" expr) - "Year/Month" "Messages" plain-text)) - - - -(define (per-year expr plain-text) - "Count the total number of messages for each weekday (0-6 for -Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text -display, otherwise, use a graphical window." - (mu:plot - (sort (mu:tabulate - (lambda (msg) - (+ 1900 (tm:year (localtime (mu:date msg))))) expr) - (lambda (x y) (< (car x) (car y)))) - (format #f "Messages per year matching ~a" expr) "Year" "Messages" plain-text)) - - -(define (main args) - (let* ((optionspec '( (muhome (value #t)) - (what (value #t)) - (text (value #f)) - (help (single-char #\h) (value #f)))) - (options (getopt-long args optionspec)) - (msg (string-append - "usage: mu-msg-stats [--help] [--text] " - "[--muhome=] " - "--what= [searchexpr]\n")) - (help (option-ref options 'help #f)) - (what (option-ref options 'what #f)) - (text (option-ref options 'text #f)) - (muhome (option-ref options 'muhome #f)) - (restargs (option-ref options '() #f)) - (expr (if restargs (string-join restargs) ""))) - (if (or help (not what)) - (begin - (display msg) - (exit (if help 0 1)))) - (mu:initialize muhome) - (cond - ((string= what "per-hour") (per-hour expr text)) - ((string= what "per-day") (per-day expr text)) - ((string= what "per-month") (per-month expr text)) - ((string= what "per-year-month") (per-year-month expr text)) - ((string= what "per-year") (per-year expr text)) - (else (begin - (display msg) - (exit 1)))))) - -;; Local Variables: -;; mode: scheme -;; End: diff --git a/guile/scripts/stats/msgs-per-day.scm b/guile/scripts/stats/msgs-per-day.scm new file mode 100755 index 00000000..da4a9c9a --- /dev/null +++ b/guile/scripts/stats/msgs-per-day.scm @@ -0,0 +1,42 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2012 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. + +(use-modules (mu) (mu script) (mu stats) (mu plot)) + +(define (per-day expr text-only) + "Count the total number of messages for each weekday (0-6 for +Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text +display, otherwise, use a graphical window." + (mu:plot + (mu:weekday-numbers->names + (sort (mu:tabulate + (lambda (msg) + (tm:wday (localtime (mu:date msg)))) expr) + (lambda (x y) (< (car x) (car y))))) + (format #f "Messages per weekday matching ~a" expr) + "Day" "Messages" text-only)) + +(define (main args) + (mu:run args per-day)) + +;; Local Variables: +;; mode: scheme +;; End: diff --git a/guile/scripts/stats/msgs-per-hour.scm b/guile/scripts/stats/msgs-per-hour.scm new file mode 100755 index 00000000..325f5d23 --- /dev/null +++ b/guile/scripts/stats/msgs-per-hour.scm @@ -0,0 +1,44 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2012 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. + +(use-modules (mu) (mu script) (mu stats) (mu plot)) + + +(define (per-hour expr text-only) + "Count the total number of messages for each weekday (0-6 for +Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text +display, otherwise, use a graphical window." + (mu:plot + (sort + (mu:tabulate + (lambda (msg) + (tm:hour (localtime (mu:date msg)))) expr) + (lambda (x y) (< (car x) (car y)))) + (format #f "Messages per hour matching ~a" expr) + "Hour" "Messages" text-only)) + + +(define (main args) + (mu:run args per-hour)) + +;; Local Variables: +;; mode: scheme +;; End: diff --git a/guile/scripts/stats/msgs-per-month.scm b/guile/scripts/stats/msgs-per-month.scm new file mode 100755 index 00000000..504ad1f6 --- /dev/null +++ b/guile/scripts/stats/msgs-per-month.scm @@ -0,0 +1,43 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2012 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. + +(use-modules (mu) (mu script) (mu stats) (mu plot)) + +(define (per-month expr text-only) + "Count the total number of messages for each weekday (0-6 for +Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text +display, otherwise, use a graphical window." + (mu:plot + (mu:month-numbers->names + (sort + (mu:tabulate + (lambda (msg) + (tm:mon (localtime (mu:date msg)))) expr) + (lambda (x y) (< (car x) (car y))))) + (format #f "Messages per month matching ~a" expr) + "Month" "Messages" text-only)) + +(define (main args) + (mu:run args per-month)) + +;; Local Variables: +;; mode: scheme +;; End: diff --git a/guile/scripts/stats/msgs-per-year-month.scm b/guile/scripts/stats/msgs-per-year-month.scm new file mode 100755 index 00000000..796662d5 --- /dev/null +++ b/guile/scripts/stats/msgs-per-year-month.scm @@ -0,0 +1,45 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2012 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. + +(use-modules (mu) (mu script) (mu stats) (mu plot)) + +(define (per-year-month expr text-only) + "Count the total number of messages for each weekday (0-6 for +Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text +display, otherwise, use a graphical window." + (mu:plot + (sort (mu:tabulate + (lambda (msg) + (string->number + (format #f "~d~2'0d" + (+ 1900 (tm:year (localtime (mu:date msg)))) + (tm:mon (localtime (mu:date msg)))))) + expr) + (lambda (x y) (< (car x) (car y)))) + (format #f "Messages per year/month matching ~a" expr) + "Year/Month" "Messages" text-only)) + +(define (main args) + (mu:run args per-year-month)) + +;; Local Variables: +;; mode: scheme +;; End: diff --git a/guile/scripts/stats/msgs-per-year.scm b/guile/scripts/stats/msgs-per-year.scm new file mode 100755 index 00000000..75bc4787 --- /dev/null +++ b/guile/scripts/stats/msgs-per-year.scm @@ -0,0 +1,42 @@ +#!/bin/sh +exec guile -e main -s $0 $@ +!# +;; +;; Copyright (C) 2012 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. + +(use-modules (mu) (mu script) (mu stats) (mu plot)) + +(define (per-year expr text-only) + "Count the total number of messages for each weekday (0-6 for +Sun..Sat) that match EXPR. If TEXT-ONLY is true, use a plain-text +display, otherwise, use a graphical window." + (mu:plot + (sort (mu:tabulate + (lambda (msg) + (+ 1900 (tm:year (localtime (mu:date msg))))) expr) + (lambda (x y) (< (car x) (car y)))) + (format #f "Messages per year matching ~a" expr) + "Year" "Messages" text-only)) + + +(define (main args) + (mu:run args per-year)) + +;; Local Variables: +;; mode: scheme +;; End: