Skip to content
Snippets Groups Projects
Commit 2d9f2133 authored by Karl Fogel's avatar Karl Fogel
Browse files

Take recency into account when scoring

Also add new user option `mailaprop-show-scores' to control whether or
not to display each candidate's score next to the sent/received counts.
parent b8d6bbf3
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
(require 'cl-lib)
(require 'company)
(require 'org) ; just for `org-time-stamp-to-now'
;; The user must set this.
(defvar mailaprop-address-file nil
......@@ -147,6 +148,12 @@ would return for that candidate substring.")
"*How much of the address to be completed must be present before
mailaprop offers completion. This is a positive integer.")
(defvar mailaprop-show-scores nil
"*If non-nil, show each candidate's score (rounded to two decimal
places) in square braces, to the right of the candidate's
sent/received counts in parentheses. This is useful if you
want to monitor how the scoring formula is doing.")
(defvar mailaprop-drop-address-fn nil
"*If non-nil, a user-defined function to decide whether to drop an address.
The function returns non-nil iff the given address should be dropped.
......@@ -235,12 +242,14 @@ RAW-ADDRESSES is a list as read from `mailaprop-address-file'."
(funcall mailaprop-drop-address-fn
group-key-addr group-size addr)))
(let* ((date (nth 1 addr-entry))
(days (abs (condition-case nil
(org-time-stamp-to-now date)
(error 65536))))
(sent (nth 2 addr-entry))
(recv (nth 3 addr-entry))
;; Sending to counts twice as much as receiving from.
;; (We should use the date and incorporate
;; recency into the score too.)
(score (+ (* sent 2) recv)))
;; Sending to counts twice as much as receiving from,
;; and recency counts (with square-root dropoff).
(score (/ (+ (* sent 2) recv) (sqrt days))))
(setq lst (cons (list addr date score) lst))
(let ((annotation (vector date sent recv score)))
(puthash addr annotation mailaprop-annotations)))))
......@@ -428,7 +437,8 @@ If there is no score corresponding to ADDR, return zero."
(mailaprop-get-candidates arg)))
(post-completion nil)
(annotation (let ((sent-count (mailaprop-find-sent-count arg))
(recv-count (mailaprop-find-recv-count arg)))
(recv-count (mailaprop-find-recv-count arg))
(score (mailaprop-find-score arg)))
(concat
;; Should we offer customizable annotations?
" | " (mailaprop-find-date arg)
......@@ -439,11 +449,9 @@ If there is no score corresponding to ADDR, return zero."
", "
(number-to-string recv-count)))
")"
;; We used to have another entry here, showing
;; the raw score in parentheses. But now that
;; we show the sent count and received count,
;; the raw score is less useful, so we dropped it.
)))
(if mailaprop-show-scores
(concat " [" (format "%.2f" score) "]")
""))))
(sorted t)
(ignore-case t)
(no-cache t)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment