all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [BUG] org-time-clock%
@ 2013-09-11 12:42 Pierre-Henry Frohring
  0 siblings, 0 replies; only message in thread
From: Pierre-Henry Frohring @ 2013-09-11 12:42 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 4753 bytes --]

Hi !

org-time-clock% gives me unexpected result.  
One could reproduce the bug using the code below or attached file.

configuration :
    emacs-version : GNU Emacs 24.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2013-03-13 on bob.porkrind.org
    org-version : Org-mode version 8.1.1

* results
** expected result
   #+BEGIN: clocktable :maxlevel 1 :scope file :formula %
   #+CAPTION: Clock summary at [2013-09-11 Mer 14:31]
   | Headline     | Time      |     % |
   |--------------+-----------+-------|
   | *Total time* | *4d 0:00* | 100.0 |
   |--------------+-----------+-------|
   | task_1       | 2d 0:00   |  50.0 |
   | task_2       | 1d 0:00   |  25.0 |
   | task_3       | 1d 0:00   |  25.0 |
   #+TBLFM: $3='(org-clock-time% @2$2 $2..$2);%.1f
   #+END:

** result obtained
   #+BEGIN: clocktable :maxlevel 1 :scope file :formula %
   #+CAPTION: Clock summary at [2013-09-11 Mer 14:39]
   | Headline     | Time      |   % |
   |--------------+-----------+-----|
   | *Total time* | *4d 0:00* | 0.0 |
   |--------------+-----------+-----|
   | task_1       | 2d 0:00   | 0.0 |
   | task_2       | 1d 0:00   | 0.0 |
   | task_3       | 1d 0:00   | 0.0 |
   #+TBLFM: $3='(org-clock-time% @2$2 $2..$2);%.1f
   #+END:




=====================




#+BEGIN: clocktable :maxlevel 1 :scope file :formula %
#+CAPTION: Clock summary at [2013-09-11 Mer 14:31]
| Headline     | Time      |     % |
|--------------+-----------+-------|
| *Total time* | *4d 0:00* | 100.0 |
|--------------+-----------+-------|
| task_1       | 2d 0:00   |  50.0 |
| task_2       | 1d 0:00   |  25.0 |
| task_3       | 1d 0:00   |  25.0 |
#+TBLFM: $3='(org-clock-time% @2$2 $2..$2);%.1f
#+END:


* task_1
  CLOCK: [2013-09-09 Lun 14:16]--[2013-09-11 Mer 14:16] => 48:00

* task_2
  CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] => 24:00

* task_3
  CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] => 24:00

* org-clock-time%
** org-mode-8.1.1/lisp/org-clock.el

 #+BEGIN_SRC elisp

   (defun org-clock-time% (total &rest strings)
     "Compute a time fraction in percent.
   TOTAL s a time string like 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 ((re "\\([0-9]+\\):\\([0-9]+\\)")
           tot s)
       (save-match-data
         (catch 'exit
           (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)))))
             (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))))

 #+END_SRC

 #+RESULTS:
 : org-clock-time%

** fixed/org-clock-time%
#+BEGIN_SRC elisp

  (defun org-clock-time% (total &rest strings)
    "Compute a time fraction in percent.
  TOTAL is 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 (str-to-min
          (tot 0)
          s)

      ;; "([0-9]+d)? [0-9]+:[0-9]+" -> minutes
      (setq str-to-min
            (lambda (clock)
              (let ((re "\\(\\([0-9]+\\)d[[:space:]]\\)?\\([0-9]+\\):\\([0-9]+\\)"))
                (save-match-data
                  (catch 'exit
                    (if (not (string-match re clock))
                        ;; ill formatted => 0
                        (throw 'exit 0.)

                      (+ (string-to-number (match-string 4 clock))
                         (* 60 (string-to-number (match-string 3 clock)))
                         (* 60 24 (if (match-string 2 clock)
                                      (string-to-number (match-string 2 clock))
                                    0)))))))))

      ;; compute time fraction in percent
      (catch 'exit
        (setq tot (funcall str-to-min total))
        (if (= tot 0.) (throw 'exit 0.))
        (while (setq s (pop strings))
          (throw 'exit
                 (/ (* 100.0 (funcall str-to-min s))
                    tot)))
        0)))

#+END_SRC

#+RESULTS:
: org-clock-time%


[-- Attachment #2: test-org-clocktable.org --]
[-- Type: application/octet-stream, Size: 3264 bytes --]

#+BEGIN: clocktable :maxlevel 1 :scope file :formula %
#+CAPTION: Clock summary at [2013-09-11 Mer 14:19]
| Headline     | Time      |   % |
|--------------+-----------+-----|
| *Total time* | *4d 0:00* | 0.0 |
|--------------+-----------+-----|
| task_1       | 2d 0:00   | 0.0 |
| task_2       | 1d 0:00   | 0.0 |
| task_3       | 1d 0:00   | 0.0 |
#+TBLFM: $3='(org-clock-time% @2$2 $2..$2);%.1f
#+END:


* task_1
  CLOCK: [2013-09-09 Lun 14:16]--[2013-09-11 Mer 14:16] => 48:00

* task_2
  CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] => 24:00

* task_3
  CLOCK: [2013-09-10 Mar 14:16]--[2013-09-11 Mer 14:16] => 24:00

* org-clock-time%
** org-mode-8.1.1/lisp/org-clock.el

 #+BEGIN_SRC elisp

   (defun org-clock-time% (total &rest strings)
     "Compute a time fraction in percent.
   TOTAL s a time string like 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 ((re "\\([0-9]+\\):\\([0-9]+\\)")
           tot s)
       (save-match-data
         (catch 'exit
           (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)))))
             (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))))

 #+END_SRC

** fixed/org-clock-time%
#+BEGIN_SRC elisp

  (defun org-clock-time% (total &rest strings)
    "Compute a time fraction in percent.
  TOTAL is 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 (str-to-min
          (tot 0)
          s)

      ;; "([0-9]+d)? [0-9]+:[0-9]+" -> minutes
      (setq str-to-min
            (lambda (clock)
              (let ((re "\\(\\([0-9]+\\)d[[:space:]]\\)?\\([0-9]+\\):\\([0-9]+\\)"))
                (save-match-data
                  (catch 'exit
                    (if (not (string-match re clock))
                        ;; ill formatted => 0
                        (throw 'exit 0.)

                      (+ (string-to-number (match-string 4 clock))
                         (* 60 (string-to-number (match-string 3 clock)))
                         (* 60 24 (if (match-string 2 clock)
                                      (string-to-number (match-string 2 clock))
                                    0)))))))))

      ;; compute time fraction in percent
      (catch 'exit
        (setq tot (funcall str-to-min total))
        (if (= tot 0.) (throw 'exit 0.))
        (while (setq s (pop strings))
          (throw 'exit
                 (/ (* 100.0 (funcall str-to-min s))
                    tot)))
        0)))

#+END_SRC

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-09-11 12:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-11 12:42 [BUG] org-time-clock% Pierre-Henry Frohring

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.