mirror of https://github.com/djcb/mu.git
* guile: some update for the output format
This commit is contained in:
parent
b7324d5af6
commit
b7219aaf82
|
@ -45,24 +45,29 @@ not found."
|
||||||
(if (access? progpath X_OK) ;; is
|
(if (access? progpath X_OK) ;; is
|
||||||
progpath
|
progpath
|
||||||
#f))))
|
#f))))
|
||||||
2
|
|
||||||
(define* (mu:plot-histogram data title x-label y-label #:optional (text-only #f) (extra-gnuplot-opts '()))
|
(define* (mu:plot-histogram data title x-label y-label output
|
||||||
"Plot DATA with TITLE, X-LABEL and X-LABEL. If TEXT-ONLY is true,
|
#:optional (extra-gnuplot-opts '()))
|
||||||
display using raw text, otherwise, use a graphical window. DATA is a
|
"Plot DATA with TITLE, X-LABEL and X-LABEL using the gnuplot
|
||||||
list of cons-pairs (X . Y)."
|
program. DATA is a list of cons-pairs (X . Y). OUTPUT is a string
|
||||||
|
that determines the type of output that gnuplot produces, depending on
|
||||||
|
the system. Which options are available depends on the particulars for
|
||||||
|
the gnuplot installation, but typical examples would be \"dumb\" for
|
||||||
|
text-only display, \"wxterm\" to write to a graphical window, or
|
||||||
|
\"png\" to write a PNG-image to stdout. EXTRA-GNUPLOT-OPTS are any
|
||||||
|
additional options for gnuplot."
|
||||||
(if (not (find-program-in-path "gnuplot"))
|
(if (not (find-program-in-path "gnuplot"))
|
||||||
(error "cannot find 'gnuplot' in path"))
|
(error "cannot find 'gnuplot' in path"))
|
||||||
|
|
||||||
(let ((datafile (export-pairs data))
|
(let ((datafile (export-pairs data))
|
||||||
(gnuplot (open-pipe "gnuplot -p" OPEN_WRITE)))
|
(gnuplot (open-pipe "gnuplot -p" OPEN_WRITE)))
|
||||||
(display (string-append
|
(display (string-append
|
||||||
"reset\n"
|
"reset\n"
|
||||||
"set term " (if text-only "dumb" "wxt") "\n"
|
"set term " (or output "dumb") "\n"
|
||||||
"set title \"" title "\"\n"
|
"set title \"" title "\"\n"
|
||||||
"set xlabel \"" x-label "\"\n"
|
"set xlabel \"" x-label "\"\n"
|
||||||
"set ylabel \"" y-label "\"\n"
|
"set ylabel \"" y-label "\"\n"
|
||||||
"set boxwidth 0.9\n"
|
"set boxwidth 0.9\n"
|
||||||
(string-join extra-gnuplot-opts "\n")
|
(string-join extra-gnuplot-opts "\n")
|
||||||
"plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid\n")
|
"plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid\n")
|
||||||
gnuplot)
|
gnuplot)
|
||||||
(close-pipe gnuplot)))
|
(close-pipe gnuplot)))
|
||||||
|
|
|
@ -34,23 +34,23 @@ Interpret argument-list ARGS (like command-line
|
||||||
arguments). Possible arguments are:
|
arguments). Possible arguments are:
|
||||||
--help (show some help and exit)
|
--help (show some help and exit)
|
||||||
--muhome (path to alternative mu home directory)
|
--muhome (path to alternative mu home directory)
|
||||||
--textonly (don't show any graphical windows)
|
--output (a string describing the output, e.g. \"dumb\", \"png\" \"wxt\")
|
||||||
searchexpr (a search query)
|
searchexpr (a search query)
|
||||||
then call FUNC with args SEARCHEXPR and TEXTONLY."
|
then call FUNC with args SEARCHEXPR and OUTPUT."
|
||||||
(setlocale LC_ALL "")
|
(setlocale LC_ALL "")
|
||||||
(let* ((optionspec '( (muhome (value #t))
|
(let* ((optionspec '((muhome (value #t))
|
||||||
(query (value #t))
|
(query (value #t))
|
||||||
(textonly (value #f))
|
(output (value #f))
|
||||||
(help (single-char #\h) (value #f))))
|
(help (single-char #\h) (value #f))))
|
||||||
(options (getopt-long args optionspec))
|
(options (getopt-long args optionspec))
|
||||||
(query (option-ref options 'query #f))
|
(query (option-ref options 'query #f))
|
||||||
(help (option-ref options 'help #f))
|
(help (option-ref options 'help #f))
|
||||||
(textonly (option-ref options 'textonly #f))
|
(output (option-ref options 'output #f))
|
||||||
(muhome (option-ref options 'muhome #f))
|
(muhome (option-ref options 'muhome #f))
|
||||||
(restargs (option-ref options '() #f)))
|
(restargs (option-ref options '() #f)))
|
||||||
(if help (help-and-exit))
|
(if help (help-and-exit))
|
||||||
(mu:initialize muhome)
|
(mu:initialize muhome)
|
||||||
(func (or query "") textonly)))
|
(func (or query "") output)))
|
||||||
|
|
||||||
;; Local Variables:
|
;; Local Variables:
|
||||||
;; mode: scheme
|
;; mode: scheme
|
||||||
|
|
|
@ -19,18 +19,19 @@ exec guile -e main -s $0 $@
|
||||||
;; along with this program; if not, write to the Free Software Foundation,
|
;; along with this program; if not, write to the Free Software Foundation,
|
||||||
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
;; INFO: graph the number of messages per day
|
;; INFO: graph the number of messages per day (using gnuplot)
|
||||||
;; INFO: options:
|
;; INFO: options:
|
||||||
;; INFO: --query=<query>: limit to messages matching query
|
;; INFO: --query=<query>: limit to messages matching query
|
||||||
;; INFO: --muhome=<muhome>: path to mu home dir
|
;; INFO: --muhome=<muhome>: path to mu home dir
|
||||||
;; INFO: --textonly: output in text-only format
|
;; INFO: --output: the output format, such as "png", "wxt"
|
||||||
|
;; INFO: (depending on the environment)
|
||||||
|
|
||||||
(use-modules (mu) (mu script) (mu stats) (mu plot))
|
(use-modules (mu) (mu script) (mu stats) (mu plot))
|
||||||
|
|
||||||
(define (per-day expr text-only)
|
(define (per-day expr output)
|
||||||
"Count the total number of messages for each weekday (0-6 for
|
"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
|
Sun..Sat) that match EXPR. OUTPUT corresponds to the output format, as
|
||||||
display, otherwise, use a graphical window."
|
per gnuplot's 'set terminal'."
|
||||||
(mu:plot-histogram
|
(mu:plot-histogram
|
||||||
(mu:weekday-numbers->names
|
(mu:weekday-numbers->names
|
||||||
(sort (mu:tabulate
|
(sort (mu:tabulate
|
||||||
|
@ -38,7 +39,7 @@ display, otherwise, use a graphical window."
|
||||||
(tm:wday (localtime (mu:date msg)))) expr)
|
(tm:wday (localtime (mu:date msg)))) expr)
|
||||||
(lambda (x y) (< (car x) (car y)))))
|
(lambda (x y) (< (car x) (car y)))))
|
||||||
(format #f "Messages per weekday matching ~a" expr)
|
(format #f "Messages per weekday matching ~a" expr)
|
||||||
"Day" "Messages" text-only))
|
"Day" "Messages" output))
|
||||||
|
|
||||||
(define (main args)
|
(define (main args)
|
||||||
(mu:run-stats args per-day))
|
(mu:run-stats args per-day))
|
||||||
|
|
Loading…
Reference in New Issue