emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* patch proposal for org-clock-time% with day
@ 2013-11-18 11:33 marco paolo valerio vezzoli
  2013-11-18 14:13 ` marco paolo valerio vezzoli
  2013-11-19  9:31 ` Bastien
  0 siblings, 2 replies; 3+ messages in thread
From: marco paolo valerio vezzoli @ 2013-11-18 11:33 UTC (permalink / raw)
  To: emacs-orgmode

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

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))))

[-- Attachment #2: Type: text/html, Size: 2026 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: patch proposal for org-clock-time% with day
  2013-11-18 11:33 patch proposal for org-clock-time% with day marco paolo valerio vezzoli
@ 2013-11-18 14:13 ` marco paolo valerio vezzoli
  2013-11-19  9:31 ` Bastien
  1 sibling, 0 replies; 3+ messages in thread
From: marco paolo valerio vezzoli @ 2013-11-18 14:13 UTC (permalink / raw)
  To: emacs-orgmode

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

Another small patch: this handles also partial times > 1d.
   Marco


(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 ((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 day-re s)
          (throw 'exit
             (/ (* 100.0 (+ (string-to-number (match-string 3 s))
                    (* 60 (string-to-number
                       (match-string 2 s)))
                    (* 60 24 (string-to-number
                          (match-string 1 s)))))
            tot))
        (if (string-match re s)
        (throw 'exit
               (/ (* 100.0 (+ (string-to-number (match-string 2 s))
                      (* 60 (string-to-number
                         (match-string 1 s)))))
            tot)))))
    0))))


2013/11/18 marco paolo valerio vezzoli <marco.p.v.vezzoli@gmail.com>

> 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))))
>

[-- Attachment #2: Type: text/html, Size: 4488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: patch proposal for org-clock-time% with day
  2013-11-18 11:33 patch proposal for org-clock-time% with day marco paolo valerio vezzoli
  2013-11-18 14:13 ` marco paolo valerio vezzoli
@ 2013-11-19  9:31 ` Bastien
  1 sibling, 0 replies; 3+ messages in thread
From: Bastien @ 2013-11-19  9:31 UTC (permalink / raw)
  To: marco paolo valerio vezzoli; +Cc: emacs-orgmode

Hi Marco,

can you send it as a patch?  It helps spotting the difference.

Clone the git repo, edit the file, save the buffer, then simply
do `C-x v =' to create a new buffer with the diff.  This is from
a recent Emacs, but not so recent.

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-19  9:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-18 11:33 patch proposal for org-clock-time% with day marco paolo valerio vezzoli
2013-11-18 14:13 ` marco paolo valerio vezzoli
2013-11-19  9:31 ` Bastien

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).