From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: [PATCH] Support time units in est+ Date: Wed, 18 Jan 2017 16:13:48 -0500 Message-ID: <87eg00ystv.fsf@gmail.com> References: <861sw0az19.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTxYe-0000eS-Tz for emacs-orgmode@gnu.org; Wed, 18 Jan 2017 16:14:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cTxYb-0004Kb-KM for emacs-orgmode@gnu.org; Wed, 18 Jan 2017 16:14:16 -0500 Received: from [195.159.176.226] (port=44681 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cTxYb-0004K3-Di for emacs-orgmode@gnu.org; Wed, 18 Jan 2017 16:14:13 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cTxYT-0003Nh-Hv for emacs-orgmode@gnu.org; Wed, 18 Jan 2017 22:14:05 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Malcolm Matalka writes: > Hey, this is my first elisp programming so I'm quite certain this is a > big hack. I just stole elements from elsewhere in the file. I'm hoping > this is good enough to get accepted then perhaps someone with more taste > would be able to refactor it to be a bit better. > > Let me know if I need to change anything. > Yes, indeed: the first thing you should do is explain what you are trying to do. E.g. what does "est+" mean? Once you have explained *what* you are trying to do, then somebody might be able to suggest *how* to do it better (if it is a worthwhile thing to do in the first place). > From 1167bd20e042ad2ae3f2712f596d76ad8b230336 Mon Sep 17 00:00:00 2001 > From: orbitz > Date: Wed, 18 Jan 2017 21:18:23 +0100 > Subject: [PATCH] org-colview.el: Add support for time units to est+ > > * lisp/org-colview.el: Add support for time units in est+. Ranges are interpreted just like non-range estimates. > > TINYCHANGE > --- > lisp/org-colview.el | 44 ++++++++++++++++++++++++++++++++------------ > 1 file changed, 32 insertions(+), 12 deletions(-) > > diff --git a/lisp/org-colview.el b/lisp/org-colview.el > index 45c71a028..2a5c067ac 100644 > --- a/lisp/org-colview.el > +++ b/lisp/org-colview.el > @@ -1288,23 +1288,43 @@ When PRINTF is non-nil, use it to format the result." > (/ (apply #'+ (mapcar #'org-columns--age-to-seconds ages)) > (float (length ages))))) > > -(defun org-columns--summary-estimate (estimates printf) > +(defun org-columns--summary-estimate (estimates _) > "Combine a list of estimates, using mean and variance. > The mean and variance of the result will be the sum of the means > and variances (respectively) of the individual estimates." > (let ((mean 0) > - (var 0)) > + (var 0) > + (hms-flag nil) > + (duration-flag nil)) > (dolist (e estimates) > - (pcase (mapcar #'string-to-number (split-string e "-")) > -(`(,low ,high) > - (let ((m (/ (+ low high) 2.0))) > - (cl-incf mean m) > - (cl-incf var (- (/ (+ (* low low) (* high high)) 2.0) (* m m))))) > -(`(,value) (cl-incf mean value)))) > - (let ((sd (sqrt var))) > - (format "%s-%s" > - (format (or printf "%.0f") (- mean sd)) > - (format (or printf "%.0f") (+ mean sd)))))) > + (pcase (split-string e "-") > + (`(,low ,high) > + (dolist (time (list high low)) > + (cond > + (duration-flag) > + ((string-match-p org-columns--duration-re time) > + (setq duration-flag t)) > + (hms-flag) > + ((string-match-p "\\`[0-9]+:[0-9]+:[0-9]+\\'" time) > + (setq hms-flag t)))) > + (let* ((low-sec (org-columns--time-to-seconds low)) > + (high-sec (org-columns--time-to-seconds high)) > + (m (/ (+ low-sec high-sec) 2.0))) > + (cl-incf mean m) > + (cl-incf var (- (/ (+ (* low-sec low-sec) (* high-sec high-sec)) 2.0) (* m m))))) > + (`(,value) (cl-incf mean (org-columns--time-to-seconds value))))) > + (let* ((sd (sqrt var)) > + (low-second (truncate (- mean sd))) > + (high-second (truncate (+ mean sd))) > + (low > + (cond (duration-flag (org-minutes-to-clocksum-string (/ low-second 60.0))) > + (hms-flag (format-seconds "%h:%.2m:%.2s" low-second)) > + (t (format-seconds "%h:%.2m" low-second)))) > + (high > + (cond (duration-flag (org-minutes-to-clocksum-string (/ high-second 60.0))) > + (hms-flag (format-seconds "%h:%.2m:%.2s" high-second)) > + (t (format-seconds "%h:%.2m" high-second))))) > + (format "%s-%s" low high)))) -- Nick