* Time calculation: vsum?
@ 2011-07-17 5:53 Christian Moe
2011-07-17 12:27 ` Michael Markert
2011-07-24 18:32 ` Bastien
0 siblings, 2 replies; 5+ messages in thread
From: Christian Moe @ 2011-07-17 5:53 UTC (permalink / raw)
To: Org Mode, Eric Schulte
Hi,
Time calculations don't seem to work with vsum (or vmean).
| Time |
|---------|
| 1:06:00 |
| 0:52:30 |
| 2:00:00 |
|---------|
| 3 |
#+TBLFM: @5$1=vsum(@I..@II);T
Am I doing something wrong?
Could this be made to work?
Yours,
Christian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Time calculation: vsum?
2011-07-17 5:53 Time calculation: vsum? Christian Moe
@ 2011-07-17 12:27 ` Michael Markert
2011-07-17 13:27 ` Christian Moe
2011-07-24 18:32 ` Bastien
1 sibling, 1 reply; 5+ messages in thread
From: Michael Markert @ 2011-07-17 12:27 UTC (permalink / raw)
To: mail; +Cc: Org Mode
[-- Attachment #1: Type: text/plain, Size: 1589 bytes --]
Hi Christian,
On 17 Jul 2011, Christian Moe wrote:
> Hi,
>
> Time calculations don't seem to work with vsum (or vmean).
>
>
> | Time |
> |---------|
> | 1:06:00 |
> | 0:52:30 |
> | 2:00:00 |
> |---------|
> | 3 |
> #+TBLFM: @5$1=vsum(@I..@II);T
>
>
> Am I doing something wrong?
Yes, `vsum' works just on numbers, not times.
> Could this be made to work?
Here's a elisp function that does what you want (assuming it's
hours:minutes:seconds -- if not tweak the numbers):
#+begin_src elisp
(defun h-m-s-vsum (times)
(loop for (h m s) in (mapcar (lambda (time)
(mapcar #'string-to-int
(split-string time ":" 'omit-nulls)))
times)
collect (+ (* 3600 h) (* 60 m) s) into seconds
finally (return (let* ((second-sum (apply #'+ seconds))
(seconds (let ((s (% second-sum 60)))
(decf second-sum s)
s))
(minutes (let ((m (% second-sum 3600)))
(decf second-sum m)
(truncate (/ m 60))))
(hours (/ second-sum 3600)))
(format "%s:%s:%s" hours minutes seconds)))))
#+end_src elisp
The table has to be
| Time |
|---------|
| 1:06:00 |
| 0:52:30 |
| 2:00:00 |
|---------|
| 3:58:30 |
#+TBLFM: @5$1='(h-m-s-vsum '(@I..@II))
Hope that helps.
Maybe there is an easier way. I hope there is ;)
Michael
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Time calculation: vsum?
2011-07-17 12:27 ` Michael Markert
@ 2011-07-17 13:27 ` Christian Moe
0 siblings, 0 replies; 5+ messages in thread
From: Christian Moe @ 2011-07-17 13:27 UTC (permalink / raw)
To: Michael Markert; +Cc: Org Mode
Hi, Michael,
First, I just realized I was part wrong: vsum of time values DOES work
(sorry, Eric!).
| Task 1 | Task 2 | Task 3 | Total |
|--------+--------+--------+---------|
| 35:00 | 35:00 | 4:00 | 1:14:00 |
#+TBLFM: @2$4=vsum($1..$3);T
| Task | Time |
|--------+-------|
| Task 1 | 35:00 |
| Task 2 | 35:00 |
| Task 3 | 4:00 |
|--------+-------|
| Total | 1:14 |
#+TBLFM: @5$2=vsum(@I..@II);T
But in the vertical vsum in the second example above, the right answer
is misleadingly formatted, so you'd read it as 1 min 14 seconds, not 1
hr 14 mins.
And I'm still failing to get the right vsum /vertically/ with times
one hour or above, e.g.:
| Task | Time |
|--------+---------|
| Task 1 | 1:35:00 |
| Task 2 | 1:35:00 |
| Task 3 | 1:04:00 |
|--------+---------|
| Total | 3 |
#+TBLFM: @5$2=vsum(@I..@II);T
Meanwhile, Michael, thanks for your elisp solution -- it's more
compact than mine, and I'll be happy to steal it!
But support for time calculations -- in calc formulas too -- has been
added in 7.6.
Yours,
Christian
On 7/17/11 2:27 PM, Michael Markert wrote:
> Hi Christian,
>
> On 17 Jul 2011, Christian Moe wrote:
>> Hi,
>>
>> Time calculations don't seem to work with vsum (or vmean).
>>
>>
>> | Time |
>> |---------|
>> | 1:06:00 |
>> | 0:52:30 |
>> | 2:00:00 |
>> |---------|
>> | 3 |
>> #+TBLFM: @5$1=vsum(@I..@II);T
>>
>>
>> Am I doing something wrong?
>
> Yes, `vsum' works just on numbers, not times.
>
>> Could this be made to work?
> Here's a elisp function that does what you want (assuming it's
> hours:minutes:seconds -- if not tweak the numbers):
>
> #+begin_src elisp
> (defun h-m-s-vsum (times)
> (loop for (h m s) in (mapcar (lambda (time)
> (mapcar #'string-to-int
> (split-string time ":" 'omit-nulls)))
> times)
> collect (+ (* 3600 h) (* 60 m) s) into seconds
> finally (return (let* ((second-sum (apply #'+ seconds))
> (seconds (let ((s (% second-sum 60)))
> (decf second-sum s)
> s))
> (minutes (let ((m (% second-sum 3600)))
> (decf second-sum m)
> (truncate (/ m 60))))
> (hours (/ second-sum 3600)))
> (format "%s:%s:%s" hours minutes seconds)))))
> #+end_src elisp
>
> The table has to be
>
> | Time |
> |---------|
> | 1:06:00 |
> | 0:52:30 |
> | 2:00:00 |
> |---------|
> | 3:58:30 |
> #+TBLFM: @5$1='(h-m-s-vsum '(@I..@II))
>
> Hope that helps.
> Maybe there is an easier way. I hope there is ;)
>
> Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Time calculation: vsum?
2011-07-17 5:53 Time calculation: vsum? Christian Moe
2011-07-17 12:27 ` Michael Markert
@ 2011-07-24 18:32 ` Bastien
2011-07-24 22:03 ` Christian Moe
1 sibling, 1 reply; 5+ messages in thread
From: Bastien @ 2011-07-24 18:32 UTC (permalink / raw)
To: mail; +Cc: Org Mode
Hi Christian,
Christian Moe <mail@christianmoe.com> writes:
> Time calculations don't seem to work with vsum (or vmean).
>
>
> | Time |
> |---------|
> | 1:06:00 |
> | 0:52:30 |
> | 2:00:00 |
> |---------|
> | 3 |
> #+TBLFM: @5$1=vsum(@I..@II);T
>
>
> Am I doing something wrong?
>
> Could this be made to work?
It should work now, thanks for pointing this out.
--
Bastien
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Time calculation: vsum?
2011-07-24 18:32 ` Bastien
@ 2011-07-24 22:03 ` Christian Moe
0 siblings, 0 replies; 5+ messages in thread
From: Christian Moe @ 2011-07-24 22:03 UTC (permalink / raw)
To: Bastien; +Cc: Org Mode
Hi,
Confirmed, thanks!
Yours,
Christian
On 7/24/11 8:32 PM, Bastien wrote:
> Hi Christian,
>
> Christian Moe<mail@christianmoe.com> writes:
>
>> Time calculations don't seem to work with vsum (or vmean).
>>
>>
>> | Time |
>> |---------|
>> | 1:06:00 |
>> | 0:52:30 |
>> | 2:00:00 |
>> |---------|
>> | 3 |
>> #+TBLFM: @5$1=vsum(@I..@II);T
>>
>>
>> Am I doing something wrong?
>>
>> Could this be made to work?
>
> It should work now, thanks for pointing this out.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-24 22:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-17 5:53 Time calculation: vsum? Christian Moe
2011-07-17 12:27 ` Michael Markert
2011-07-17 13:27 ` Christian Moe
2011-07-24 18:32 ` Bastien
2011-07-24 22:03 ` Christian Moe
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).