* some more guile scripting stuff

This commit is contained in:
Dirk-Jan C. Binnema
2011-07-13 23:00:05 +03:00
parent 647efbac6c
commit 63a968ccae
2 changed files with 60 additions and 8 deletions

View File

@ -583,7 +583,8 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC}, {GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
}; };
g_return_if_fail (func && msg); g_return_if_fail (msg && msg->_file);
g_return_if_fail (func);
/* first, get the from address(es) */ /* first, get the from address(es) */
get_contacts_from (msg, func, user_data); get_contacts_from (msg, func, user_data);

View File

@ -11,11 +11,11 @@
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details. ;; GNU General Public License for more details.
;; ;;
;; You should have received a copy of the GNU General Public License ;; You should have received a copy of the GNU General Public License
;; 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.
;;
;;
;; some guile/scheme functions to get various statistics of my mu ;; some guile/scheme functions to get various statistics of my mu
;; message store. ;; message store.
@ -28,16 +28,67 @@ provided, only count the messages that match it.\n"
(mu:store:foreach (lambda(msg) #f) EXPR)) (mu:store:foreach (lambda(msg) #f) EXPR))
(define (mu:stats:average-size EXPR) (define (mu:stats:average FUNC EXPR)
"Count the total number of messages. If the optional EXPR is "Count the average of the result of applying FUNC on all
provided, only count the messages that match it.\n" messages. If the optional EXPR is provided, only consider the messages
that match it.\n"
(let* ((sum 0) (let* ((sum 0)
(n (mu:store:foreach (n (mu:store:foreach
(lambda(msg) (set! sum (+ sum (mu:msg:size msg)))) EXPR))) (lambda(msg) (set! sum (+ sum (FUNC msg)))) EXPR)))
(if (= n 0) 0 (exact->inexact (/ sum n))))) (if (= n 0) 0 (exact->inexact (/ sum n)))))
(define (mu:stats:average-size EXPR)
"Calculate the average message size. If the optional EXPR is
provided, only consider the messages that match it.\n"
(mu:stats:average (lambda(msg) (mu:msg:size msg)) EXPR))
(define (mu:stats:average-recipient-number EXPR)
"Calculate the average number of recipients (To: + CC: + Bcc:). If
the optional EXPR is provided, only consider the messages that match
it.\n"
(mu:stats:average (lambda(msg)
(+(length (mu:msg:to msg))
(length (mu:msg:cc msg))
(length (mu:msg:bcc msg)))) EXPR))
(define (mu:stats:frequency FUNC EXPR)
"FUNC is a function that takes a Msg and returns some number between
0 and <MAX. If the optional EXPR is provided, only consider messages
that match it.\n"
(let ((table '()))
(mu:store:foreach
(lambda(msg)
(let* ((val (FUNC msg)) (freq (assoc-ref table val)))
(set! table (assoc-set! table val
(+ 1 (if (eq? freq #f) 0 freq)))))) "")
(sort table (lambda(a b) (< (car a) (car b))))))
(define (mu:stats:per-weekday EXPR)
"Count the total number of messages for each weekday (0-6 for
Sun..Sat). If the optional EXPR is provided, only count the messages
that match it. The result is a list of pairs (weekday . frequency).\n"
(mu:stats:frequency
(lambda (msg) (tm:wday (localtime (mu:msg:date msg)))) EXPR))
(define (mu:stats:per-month EXPR)
"Count the total number of messages for each month (0-11 for
Jan..Dec). If the optional EXPR is provided, only count the messages
that match it. The result is a list of pairs (month . frequency).\n"
(mu:stats:frequency
(lambda (msg) (tm:mon (localtime (mu:msg:date msg)))) EXPR))
(define (mu:stats:per-hour EXPR)
"Count the total number of messages for each weekday (0-6 for
Sun..Sat). If the optional EXPR is provided, only count the messages
that match it. The result is a list of pairs (weekday . frequency).\n"
(mu:stats:frequency
(lambda (msg) (tm:hour (localtime (mu:msg:date msg)))) EXPR))
(define (mu:stats:per-year EXPR)
"Count the total number of messages for each year since 1970. If the
optional EXPR is provided, only count the messages that match it. The
result is a list of pairs (year . frequency).\n"
(mu:stats:frequency
(lambda (msg) (+ 1900 (tm:year (localtime (mu:msg:date msg))))) EXPR))