mirror of https://github.com/djcb/mu.git
Fix handling of --text option in `msg-graphs' example
The previous implementation of `msg-graphs` called `mu:plots/mu:plot` with output set to `#t` when the option `--text` was passed. This caused an error in the `string-append` call in `mu:plot` since the expression `(or output "dumb")` evaluated to the symbol `#t` rather than a string. This commit fixes this by making sure that `mu:plot` is called with `output` set to `"dumb"` when the option `--text` is passed to `msg-graphs`, and with `output` set to `"wxt"` (the default multi-platform graphical output device in `gnuplot`) otherwise. This is done by essentially making the code of `msg-graphs` agree with the plotting code in the `guile/scripts` directory.
This commit is contained in:
parent
7498760084
commit
c4e037c16f
|
@ -24,34 +24,34 @@ exec guile -e main -s $0 $@
|
||||||
(use-modules (mu) (mu stats) (mu plot))
|
(use-modules (mu) (mu stats) (mu plot))
|
||||||
;;(use-modules (mu) (mu message) (mu stats) (mu plot))
|
;;(use-modules (mu) (mu message) (mu stats) (mu plot))
|
||||||
|
|
||||||
(define (per-hour expr plain-text)
|
(define (per-hour 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
|
||||||
Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text
|
match EXPR. OUTPUT corresponds to the output format, as per gnuplot's 'set
|
||||||
display, otherwise, use a graphical window."
|
terminal'."
|
||||||
(mu:plot
|
(mu:plot
|
||||||
(sort
|
(sort
|
||||||
(mu:tabulate
|
(mu:tabulate
|
||||||
(lambda (msg)
|
(lambda (msg)
|
||||||
(tm:hour (localtime (mu:date msg)))) expr)
|
(tm:hour (localtime (mu:date msg)))) expr)
|
||||||
(lambda (x y) (< (car x) (car y))))
|
(lambda (x y) (< (car x) (car y))))
|
||||||
(format #f "Messages per hour matching ~a" expr) "Hour" "Messages" plain-text))
|
(format #f "Messages per hour matching ~a" expr) "Hour" "Messages" output))
|
||||||
|
|
||||||
(define (per-day expr plain-text)
|
(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
|
||||||
Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text
|
match EXPR. OUTPUT corresponds to the output format, as per gnuplot's 'set
|
||||||
display, otherwise, use a graphical window."
|
terminal'."
|
||||||
(mu:plot
|
(mu:plot
|
||||||
(mu:weekday-numbers->names
|
(mu:weekday-numbers->names
|
||||||
(sort (mu:tabulate
|
(sort (mu:tabulate
|
||||||
(lambda (msg)
|
(lambda (msg)
|
||||||
(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) "Day" "Messages" plain-text))
|
(format #f "Messages per weekday matching ~a" expr) "Day" "Messages" output))
|
||||||
|
|
||||||
(define (per-month expr plain-text)
|
(define (per-month 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
|
||||||
Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text
|
match EXPR. OUTPUT corresponds to the output format, as per gnuplot's 'set
|
||||||
display, otherwise, use a graphical window."
|
terminal'."
|
||||||
(mu:plot
|
(mu:plot
|
||||||
(mu:month-numbers->names
|
(mu:month-numbers->names
|
||||||
(sort
|
(sort
|
||||||
|
@ -59,13 +59,13 @@ display, otherwise, use a graphical window."
|
||||||
(lambda (msg)
|
(lambda (msg)
|
||||||
(tm:mon (localtime (mu:date msg)))) expr)
|
(tm:mon (localtime (mu:date msg)))) expr)
|
||||||
(lambda (x y) (< (car x) (car y)))))
|
(lambda (x y) (< (car x) (car y)))))
|
||||||
(format #f "Messages per month matching ~a" expr) "Month" "Messages" plain-text))
|
(format #f "Messages per month matching ~a" expr) "Month" "Messages" output))
|
||||||
|
|
||||||
|
|
||||||
(define (per-year-month expr plain-text)
|
(define (per-year-month 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
|
||||||
Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text
|
match EXPR. OUTPUT corresponds to the output format, as per gnuplot's 'set
|
||||||
display, otherwise, use a graphical window."
|
terminal'."
|
||||||
(mu:plot
|
(mu:plot
|
||||||
(sort (mu:tabulate
|
(sort (mu:tabulate
|
||||||
(lambda (msg)
|
(lambda (msg)
|
||||||
|
@ -76,20 +76,20 @@ display, otherwise, use a graphical window."
|
||||||
expr)
|
expr)
|
||||||
(lambda (x y) (< (car x) (car y))))
|
(lambda (x y) (< (car x) (car y))))
|
||||||
(format #f "Messages per year/month matching ~a" expr)
|
(format #f "Messages per year/month matching ~a" expr)
|
||||||
"Year/Month" "Messages" plain-text))
|
"Year/Month" "Messages" output))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define (per-year expr plain-text)
|
(define (per-year 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
|
||||||
Sun..Sat) that match EXPR. If PLAIN-TEXT is true, use a plain-text
|
match EXPR. OUTPUT corresponds to the output format, as per gnuplot's 'set
|
||||||
display, otherwise, use a graphical window."
|
terminal'."
|
||||||
(mu:plot
|
(mu:plot
|
||||||
(sort (mu:tabulate
|
(sort (mu:tabulate
|
||||||
(lambda (msg)
|
(lambda (msg)
|
||||||
(+ 1900 (tm:year (localtime (mu:date msg))))) expr)
|
(+ 1900 (tm:year (localtime (mu:date msg))))) expr)
|
||||||
(lambda (x y) (< (car x) (car y))))
|
(lambda (x y) (< (car x) (car y))))
|
||||||
(format #f "Messages per year matching ~a" expr) "Year" "Messages" plain-text))
|
(format #f "Messages per year matching ~a" expr) "Year" "Messages" output))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,6 +107,9 @@ display, otherwise, use a graphical window."
|
||||||
(help (option-ref options 'help #f))
|
(help (option-ref options 'help #f))
|
||||||
(what (option-ref options 'what #f))
|
(what (option-ref options 'what #f))
|
||||||
(text (option-ref options 'text #f))
|
(text (option-ref options 'text #f))
|
||||||
|
;; if `text' is `#f', use a graphical window by setting output to "wxt",
|
||||||
|
;; else use text-mode plotting ("dumb")
|
||||||
|
(output (if text "dumb" "wxt"))
|
||||||
(muhome (option-ref options 'muhome #f))
|
(muhome (option-ref options 'muhome #f))
|
||||||
(restargs (option-ref options '() #f))
|
(restargs (option-ref options '() #f))
|
||||||
(expr (if restargs (string-join restargs) "")))
|
(expr (if restargs (string-join restargs) "")))
|
||||||
|
@ -116,11 +119,11 @@ display, otherwise, use a graphical window."
|
||||||
(exit (if help 0 1))))
|
(exit (if help 0 1))))
|
||||||
(mu:initialize muhome)
|
(mu:initialize muhome)
|
||||||
(cond
|
(cond
|
||||||
((string= what "per-hour") (per-hour expr text))
|
((string= what "per-hour") (per-hour expr output))
|
||||||
((string= what "per-day") (per-day expr text))
|
((string= what "per-day") (per-day expr output))
|
||||||
((string= what "per-month") (per-month expr text))
|
((string= what "per-month") (per-month expr output))
|
||||||
((string= what "per-year-month") (per-year-month expr text))
|
((string= what "per-year-month") (per-year-month expr output))
|
||||||
((string= what "per-year") (per-year expr text))
|
((string= what "per-year") (per-year expr output))
|
||||||
(else (begin
|
(else (begin
|
||||||
(display msg)
|
(display msg)
|
||||||
(exit 1))))))
|
(exit 1))))))
|
||||||
|
|
Loading…
Reference in New Issue