From e02df6c7864d71f40d1f88741e27e3a82b9eaca7 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 16 Nov 2022 19:09:44 +0200 Subject: [PATCH] guile: move msgs-per-* scripts into histogram.scm --- guile/meson.build | 7 +- guile/scripts/histogram.scm | 127 ++++++++++++++++++++++++++ guile/scripts/msgs-per-day.scm | 49 ---------- guile/scripts/msgs-per-hour.scm | 49 ---------- guile/scripts/msgs-per-month.scm | 50 ---------- guile/scripts/msgs-per-year-month.scm | 52 ----------- guile/scripts/msgs-per-year.scm | 48 ---------- 7 files changed, 128 insertions(+), 254 deletions(-) create mode 100755 guile/scripts/histogram.scm delete mode 100755 guile/scripts/msgs-per-day.scm delete mode 100755 guile/scripts/msgs-per-hour.scm delete mode 100755 guile/scripts/msgs-per-month.scm delete mode 100755 guile/scripts/msgs-per-year-month.scm delete mode 100755 guile/scripts/msgs-per-year.scm diff --git a/guile/meson.build b/guile/meson.build index a427644f..47be36be 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 00000000..b845f281 --- /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 +;; +;; 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=: limit to messages matching query +;; INFO: --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=] [--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 824f5568..00000000 --- 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 -;; -;; 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=: limit to messages matching query -;; INFO: --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 d96f9b6b..00000000 --- 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 -;; -;; 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=: limit to messages matching query -;; INFO: --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 50dbbedb..00000000 --- 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 -;; -;; 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=: limit to messages matching query -;; INFO: --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 33b14476..00000000 --- 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 -;; -;; 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=: limit to messages matching query -;; INFO: --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 242e2998..00000000 --- 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 -;; -;; 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=: limit to messages matching query -;; INFO: --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: