summaryrefslogtreecommitdiff
path: root/guile
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-11-16 19:09:44 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2022-11-17 11:00:06 +0200
commite02df6c7864d71f40d1f88741e27e3a82b9eaca7 (patch)
tree412caa203d20faa7dccf4e0c7094f78a795f4fff /guile
parentfc899c09628a82b05e43249b033e55fc7edbd28e (diff)
guile: move msgs-per-* scripts into histogram.scm
Diffstat (limited to 'guile')
-rw-r--r--guile/meson.build7
-rwxr-xr-xguile/scripts/histogram.scm127
-rwxr-xr-xguile/scripts/msgs-per-day.scm49
-rwxr-xr-xguile/scripts/msgs-per-hour.scm49
-rwxr-xr-xguile/scripts/msgs-per-month.scm50
-rwxr-xr-xguile/scripts/msgs-per-year-month.scm52
-rwxr-xr-xguile/scripts/msgs-per-year.scm48
7 files changed, 128 insertions, 254 deletions
diff --git a/guile/meson.build b/guile/meson.build
index a427644..47be36b 100644
--- a/guile/meson.build
+++ b/guile/meson.build
@@ -99,12 +99,7 @@ install_data(['mu.scm','mu/script.scm', 'mu/message.scm', 'mu/stats.scm', 'mu/pl
mu_guile_scripts=[
join_paths('scripts', 'find-dups.scm'),
join_paths('scripts', 'msgs-count.scm'),
- join_paths('scripts', 'msgs-per-day.scm'),
- join_paths('scripts', 'msgs-per-hour.scm'),
- join_paths('scripts', 'msgs-per-month.scm'),
- join_paths('scripts', 'msgs-per-year-month.scm'),
- join_paths('scripts', 'msgs-per-year.scm')
-]
+ join_paths('scripts', 'histogram.scm')]
mu_guile_script_dir=join_paths(datadir, 'mu', 'scripts')
install_data(mu_guile_scripts, install_dir: mu_guile_script_dir)
diff --git a/guile/scripts/histogram.scm b/guile/scripts/histogram.scm
new file mode 100755
index 0000000..b845f28
--- /dev/null
+++ b/guile/scripts/histogram.scm
@@ -0,0 +1,127 @@
+#!/bin/sh
+exec guile -e main -s $0 $@
+!#
+;; Copyright (C) 2022 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.
+
+;; INFO: Histogram of the number of messages per time-unit
+;; INFO: Options:
+;; INFO: --query=<query>: limit to messages matching query
+;; INFO: --muhome=<muhome>: path to mu home dir
+;; INFO: --time-unit: hour|day|month|year|month-year
+;; INFO: --output: the output format, such as "png", "wxt"
+;; INFO: (depending on the environment)
+
+(use-modules (mu) (mu stats) (mu plot)
+ (ice-9 getopt-long) (ice-9 format))
+
+(define (per-hour expr output)
+ "Count the total number of messages per hour that match EXPR.
+OUTPUT corresponds to the output format, as per gnuplot's 'set terminal'."
+ (mu:plot-histogram
+ (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" output))
+
+
+(define (per-day expr output)
+ "Count the total number of messages for each weekday (0-6 for
+Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
+per gnuplot's 'set terminal'."
+ (mu:plot-histogram
+ (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" output))
+
+(define (per-month expr output)
+ "Count the total number of messages per month that match EXPR.
+OUTPUT corresponds to the output format, as per gnuplot's 'set terminal'."
+ (mu:plot-histogram
+ (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" output))
+
+(define (per-year expr output)
+ "Count the total number of messages per year that match EXPR. OUTPUT corresponds
+to the output format, as per gnuplot's 'set terminal'."
+ (mu:plot-histogram
+ (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" output))
+
+
+(define (per-year-month expr output)
+ "Count the total number of messages for each year and month that match EXPR.
+OUTPUT corresponds to the output format, as per gnuplot's 'set terminal'."
+ (mu:plot-histogram
+ (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" output))
+
+(define (main args)
+ (let* ((optionspec
+ '((time-unit (value #t))
+ (query (value #t))
+ (muhome (value #t))
+ (output (value #t))
+ (help (single-char #\h) (value #f))))
+ (options (getopt-long args optionspec))
+ (help (option-ref options 'help #f))
+ (time-unit (option-ref options 'time-unit "year"))
+ (muhome (option-ref options 'muhome #f))
+ (query (option-ref options 'query ""))
+ (output (option-ref options 'output "dumb"))
+ (rest (option-ref options '() #f))
+ (func
+ (cond
+ ((equal? time-unit "hour") per-hour)
+ ((equal? time-unit "day") per-day)
+ ((equal? time-unit "month") per-month)
+ ((equal? time-unit "year") per-year)
+ ((equal? time-unit "year-month") per-year-month)
+ (else #f))))
+ (setlocale LC_ALL "")
+ (unless func
+ (display "error: unknown time-unit\n")
+ (set! help #t))
+ (if help
+ (begin
+ (display
+ (string-append "parameters: [--help] [--output=dumb|png|wxt] "
+ "[--muhome=<muhome>] [--query=<query>]"
+ "[--time-unit=hour|day|month|year|year-month]"))
+ (newline))
+ (begin
+ (mu:initialize muhome)
+ (func query output)))))
+
+;; Local Variables:
+;; mode: scheme
+;; End:
diff --git a/guile/scripts/msgs-per-day.scm b/guile/scripts/msgs-per-day.scm
deleted file mode 100755
index 824f556..0000000
--- a/guile/scripts/msgs-per-day.scm
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-exec guile -e main -s $0 $@
-!#
-;;
-;; Copyright (C) 2012-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: graph the number of messages per day (using gnuplot)
-;; INFO: options:
-;; INFO: --query=<query>: limit to messages matching query
-;; INFO: --muhome=<muhome>: path to mu home dir
-;; INFO: --output: the output format, such as "png", "wxt"
-;; INFO: (depending on the environment)
-
-(use-modules (mu) (mu script) (mu stats) (mu plot))
-
-(define (per-day expr output)
- "Count the total number of messages for each weekday (0-6 for
-Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
-per gnuplot's 'set terminal'."
- (mu:plot-histogram
- (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" output))
-
-(define (main args)
- (mu:run-stats args per-day))
-
-;; Local Variables:
-;; mode: scheme
-;; End:
diff --git a/guile/scripts/msgs-per-hour.scm b/guile/scripts/msgs-per-hour.scm
deleted file mode 100755
index d96f9b6..0000000
--- a/guile/scripts/msgs-per-hour.scm
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/sh
-exec guile -e main -s $0 $@
-!#
-;;
-;; Copyright (C) 2012-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: graph the number of messages per day (using gnuplot)
-;; INFO: options:
-;; INFO: --query=<query>: limit to messages matching query
-;; INFO: --muhome=<muhome>: path to mu home dir
-;; INFO: --output: the output format, such as "png", "wxt"
-;; INFO: (depending on the environment)
-
-(use-modules (mu) (mu script) (mu stats) (mu plot))
-
-(define (per-hour expr output)
- "Count the total number of messages for each weekday (0-6 for
-Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
-per gnuplot's 'set terminal'."
- (mu:plot-histogram
- (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" output))
-
-(define (main args)
- (mu:run-stats args per-hour))
-
-;; Local Variables:
-;; mode: scheme
-;; End:
diff --git a/guile/scripts/msgs-per-month.scm b/guile/scripts/msgs-per-month.scm
deleted file mode 100755
index 50dbbed..0000000
--- a/guile/scripts/msgs-per-month.scm
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-exec guile -e main -s $0 $@
-!#
-;;
-;; Copyright (C) 2012-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: graph the number of messages per day (using gnuplot)
-;; INFO: options:
-;; INFO: --query=<query>: limit to messages matching query
-;; INFO: --muhome=<muhome>: path to mu home dir
-;; INFO: --output: the output format, such as "png", "wxt"
-;; INFO: (depending on the environment)
-
-(use-modules (mu) (mu script) (mu stats) (mu plot))
-
-(define (per-month expr output)
- "Count the total number of messages for each weekday (0-6 for
-Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
-per gnuplot's 'set terminal'."
- (mu:plot-histogram
- (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" output))
-
-(define (main args)
- (mu:run-stats args per-month))
-
-;; Local Variables:
-;; mode: scheme
-;; End:
diff --git a/guile/scripts/msgs-per-year-month.scm b/guile/scripts/msgs-per-year-month.scm
deleted file mode 100755
index 33b1447..0000000
--- a/guile/scripts/msgs-per-year-month.scm
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/bin/sh
-exec guile -e main -s $0 $@
-!#
-;;
-;; Copyright (C) 2012-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: graph the number of messages per day (using gnuplot)
-;; INFO: options:
-;; INFO: --query=<query>: limit to messages matching query
-;; INFO: --muhome=<muhome>: path to mu home dir
-;; INFO: --output: the output format, such as "png", "wxt"
-;; INFO: (depending on the environment)
-
-(use-modules (mu) (mu script) (mu stats) (mu plot))
-
-(define (per-year-month expr output)
- "Count the total number of messages for each weekday (0-6 for
-Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
-per gnuplot's 'set terminal'."
- (mu:plot-histogram
- (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" output))
-
-(define (main args)
- (mu:run-stats args per-year-month))
-
-;; Local Variables:
-;; mode: scheme
-;; End:
diff --git a/guile/scripts/msgs-per-year.scm b/guile/scripts/msgs-per-year.scm
deleted file mode 100755
index 242e299..0000000
--- a/guile/scripts/msgs-per-year.scm
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/bin/sh
-exec guile -e main -s $0 $@
-!#
-;;
-;; Copyright (C) 2012-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: graph the number of messages per day (using gnuplot)
-;; INFO: options:
-;; INFO: --query=<query>: limit to messages matching query
-;; INFO: --muhome=<muhome>: path to mu home dir
-;; INFO: --output: the output format, such as "png", "wxt"
-;; INFO: (depending on the environment)
-
-(use-modules (mu) (mu script) (mu stats) (mu plot))
-
-(define (per-year expr output)
- "Count the total number of messages for each weekday (0-6 for
-Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
-per gnuplot's 'set terminal'."
- (mu:plot-histogram
- (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" output))
-
-(define (main args)
- (mu:run-stats args per-year))
-
-;; Local Variables:
-;; mode: scheme
-;; End: