From mboxrd@z Thu Jan 1 00:00:00 1970 From: marco paolo valerio vezzoli Subject: patch proposal for org-clock-time% with day Date: Mon, 18 Nov 2013 12:33:29 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e013a2708cbfda004eb71ea3a Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViN5A-0002y2-4r for emacs-orgmode@gnu.org; Mon, 18 Nov 2013 06:33:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ViN58-0006NH-R4 for emacs-orgmode@gnu.org; Mon, 18 Nov 2013 06:33:32 -0500 Received: from mail-vc0-x230.google.com ([2607:f8b0:400c:c03::230]:56310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViN58-0006NB-Kf for emacs-orgmode@gnu.org; Mon, 18 Nov 2013 06:33:30 -0500 Received: by mail-vc0-f176.google.com with SMTP id ia6so2896433vcb.35 for ; Mon, 18 Nov 2013 03:33:30 -0800 (PST) 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --089e013a2708cbfda004eb71ea3a Content-Type: text/plain; charset=UTF-8 Hi, I use clocktables with the :funciton % option. Sometime the table sums up to a time interval larger than one day so the total may fool the regular expression: 1d 0:04 -> 4 minutes instead of 1444 minutes I wrote a simple modification of org-clock-time% : please find it below. I'm sure that elisp wizards can find a better solution than mine. Marco (defun org-clock-time% (total &rest strings) "Compute a time fraction in percent. TOTAL s a time string like 1d 10:21 specifying the total times. STRINGS is a list of strings that should be checked for a time. The first string that does have a time will be used. This function is made for clock tables." (let ((day-re "\\([0-9]+\\)d \\([0-9]+\\):\\([0-9]+\\)") (re "\\([0-9]+\\):\\([0-9]+\\)") tot s) (save-match-data (catch 'exit (if (not (string-match day-re total)) (if (not (string-match re total)) (throw 'exit 0.) (setq tot (+ (string-to-number (match-string 2 total)) (* 60 (string-to-number (match-string 1 total)))))) (setq tot (+ (string-to-number (match-string 2 total)) (* 60 (string-to-number (match-string 1 total))) (* 60 24 (string-to-number (match-string 1 total))))) (if (= tot 0.) (throw 'exit 0.))) (while (setq s (pop strings)) (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s) (throw 'exit (/ (* 100.0 (+ (string-to-number (match-string 2 s)) (* 60 (string-to-number (match-string 1 s))))) tot)))) 0)))) --089e013a2708cbfda004eb71ea3a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,
I use clocktables with the :funcito= n % option.
Sometime the table sums up to a time interval lar= ger than one day so the total may fool the regular expression:

1d 0:04 -> 4 minutes instead of 1444 minutes

I wr= ote a simple modification of org-clock-time% : please find it below. I'= m sure that elisp wizards can find a better solution than mine.
=C2=A0 Marco

(defun org-clock-time% (total &rest strings)=C2=A0 "Compute a time fraction in percent.
TOTAL s a time string= like 1d 10:21 specifying the total times.
STRINGS is a list of strings = that should be checked for a time.
The first string that does have a time will be used.
This function is ma= de for clock tables."
=C2=A0 (let ((day-re "\\([0-9]+\\)d \\([= 0-9]+\\):\\([0-9]+\\)")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = (re "\\([0-9]+\\):\\([0-9]+\\)")
=C2=A0=C2=A0=C2=A0 tot s)
=C2=A0=C2=A0=C2=A0 (save-match-data
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (catch 'exit
=C2=A0=C2=A0=C2=A0 (if (not (s= tring-match day-re total))
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (if (no= t (string-match re total))
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (throw = 'exit 0.)
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (setq t= ot (+ (string-to-number (match-string 2 total))
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 (* 60= (string-to-number (match-string 1 total))))))
=C2=A0=C2=A0=C2=A0 =C2=A0= (setq tot (+ (string-to-number (match-string 2 total))
=C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (* 60 (string-t= o-number (match-string 1 total)))
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 = =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (* 60 24 (string-to-number (match-stri= ng 1 total)))))
=C2=A0=C2=A0=C2=A0 =C2=A0 (if (=3D tot 0.) (throw 'exit 0.)))
=C2=A0= =C2=A0=C2=A0 (while (setq s (pop strings))
=C2=A0=C2=A0=C2=A0 =C2=A0 (if= (string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
=C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (throw 'exit
=C2=A0=C2=A0=C2=A0 = =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 (/ (* 100.0 (+ (string-to-numbe= r (match-string 2 s))
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (* 60 (string-to-number
=C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= =C2=A0 (match-string 1 s)))))
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 tot))))
=C2=A0=C2=A0=C2=A0 0))))
--089e013a2708cbfda004eb71ea3a--