emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [bug] Remote durations are considered as fractions
@ 2012-04-03 12:35 Sebastien Vauban
  2012-04-10 22:46 ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2012-04-03 12:35 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello,

It took me a while to understand what was going on with some figures in tables
derived from a clock report, but I found it: computed total times, referred in
a table, are converted as fractions, that is...

- 3:36 becomes 1:12 (because 3/36 = 1/12)
- 0:51 becomes 0
- 9:03 becomes 3
- 3:34 stays 3:34...

Example:

* Hours spent

#+tblname: hours-spent
#+BEGIN: clocktable :maxlevel 4 :scope ("file-tom.org") :block 2012-04 :indent t
Clock summary at [2012-04-03 Tue 14:30], for April 2012.

| File         | Headline                          | Time  |      |      |
|--------------+-----------------------------------+-------+------+------|
|              | ALL Total time                    | 18:45 |      |      |
|--------------+-----------------------------------+-------+------+------|
| file-tom.org | File time                         | 12:39 |      |      |
|              | Planning                          |       | 3:36 |      |
|              | \__ TODO Arrange meetings         |       |      | 0:51 |
|              | \__ TODO List skills required     |       |      | 1:27 |
|              | \__ TODO Organize interviews      |       |      | 1:18 |
|              | Reporting                         |       | 9:03 |      |
|              | \__ TODO Make report              |       |      | 6:47 |
|              | \__ TODO Present report           |       |      | 2:16 |
#+END:

* Summary

Time worked on some projects is wrong:

| Planning  | 1:12 |
| Reporting |    3 |
#+TBLFM: @1$2=remote(hours-spent,@4$4)::@2$2=remote(hours-spent,@8$4)

Using the flag T does not help:

| Planning  | 00:00:03 |
| Reporting | 00:00:09 |
#+TBLFM: @1$2=remote(hours-spent,@4$4);T::@2$2=remote(hours-spent,@8$4);T

Using the flag t does not help either:

| Planning  | 0.00 |
| Reporting | 0.00 |
#+TBLFM: @1$2=remote(hours-spent,@4$4);t::@2$2=remote(hours-spent,@8$4);t

Best regards,
  Seb

PS- BTW, this is a nice "clock table" where totals are not mixed. I sent two
posts yesterday, but did not see them yet on Gmane -- my NNTP source.

-- 
Sebastien Vauban

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

* Re: [bug] Remote durations are considered as fractions
  2012-04-03 12:35 [bug] Remote durations are considered as fractions Sebastien Vauban
@ 2012-04-10 22:46 ` Bastien
  2012-04-19 13:19   ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2012-04-10 22:46 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode

Hi Sébastien,

"Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> writes:

> Using the flag T does not help:
>
> | Planning  | 00:00:03 |
> | Reporting | 00:00:09 |
> #+TBLFM: @1$2=remote(hours-spent,@4$4);T

This should work as expected now (with the "T" flag.)

Note that the conversion of 3:12 into 1:4 is independant 
of getting the remote references right when they are durations.

| Test | 3:12 |
|      |  1:4 |
#+TBLFM: @2$2=@1$2

Thanks for reporting this!

-- 
 Bastien

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

* Re: [bug] Remote durations are considered as fractions
  2012-04-10 22:46 ` Bastien
@ 2012-04-19 13:19   ` Sebastien Vauban
  2012-04-20 11:21     ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2012-04-19 13:19 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Bastien,

Bastien wrote:
> "Sebastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>
>> Using the flag T does not help:
>>
>> | Planning  | 00:00:03 |
>> | Reporting | 00:00:09 |
>> #+TBLFM: @1$2=remote(hours-spent,@4$4);T
>
> This should work as expected now (with the "T" flag.)

I confirm this is now working as expected for both the "T" and the "t" flags:

- Using the flag T:

  | Planning  | 03:36:00 |
  | Reporting | 09:03:00 |
  #+TBLFM: @1$2=remote(hours-spent,@4$3);T::@2$2=remote(hours-spent,@8$3);T

- Using the flag t:

  | Planning  | 3.60 |
  | Reporting | 9.05 |
  #+TBLFM: @1$2=remote(hours-spent,@4$3);t::@2$2=remote(hours-spent,@8$3);t

Thanks!

BTW, *could we limit the format of "T" to H:MM*, instead of H:MM:SS? The first
case seems much more common, and the one used in all time clocking functions
of Org.

> Note that the conversion of 3:12 into 1:4 is independant of getting the
> remote references right when they are durations.
>
> | Test | 3:12 |
> |      |  1:4 |
> #+TBLFM: @2$2=@1$2
>
> Thanks for reporting this!

Wasn't aware of that. Thanks for mentioning.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [bug] Remote durations are considered as fractions
  2012-04-19 13:19   ` Sebastien Vauban
@ 2012-04-20 11:21     ` Bastien
  2012-04-20 20:45       ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2012-04-20 11:21 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: emacs-orgmode

Hi Sébastien,

"Sebastien Vauban" <wxhgmqzgwmuf@spammotel.com> writes:

> BTW, *could we limit the format of "T" to H:MM*, instead of H:MM:SS? The first
> case seems much more common, and the one used in all time clocking functions
> of Org.

Patch welcome!

-- 
 Bastien

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

* Re: [bug] Remote durations are considered as fractions
  2012-04-20 11:21     ` Bastien
@ 2012-04-20 20:45       ` Sebastien Vauban
  2012-04-20 23:22         ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2012-04-20 20:45 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Bastien,

Bastien wrote:
> "Sebastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>
>> BTW, *could we limit the format of "T" to H:MM*, instead of H:MM:SS? The first
>> case seems much more common, and the one used in all time clocking functions
>> of Org.
>
> Patch welcome!

I think this is it...

From a77fe281afe5b568ebfd1d3969a7d4e6e8e54e63 Mon Sep 17 00:00:00 2001
From: Sebastien Vauban <sva-D0wtAvR13HarG/iDocfnWg@public.gmane.org>
Date: Fri, 20 Apr 2012 22:43:11 +0200
Subject: [PATCH] Change output format of T specifier to H:MM

	* org-table.el (org-table-time-seconds-to-string): Change the
	format string for default output format to H:MM (instead of
	HH:MM:SS).

---
 lisp/org-table.el |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 2d527d7..76fa7c7 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -3319,7 +3319,7 @@ minutes or seconds."
 	 (format "%.1f" (/ (float secs) 60)))
 	((eq output-format 'seconds)
 	 (format "%d" secs))
-	(t (org-format-seconds "%.2h:%.2m:%.2s" secs))))
+	(t (org-format-seconds "%h:%.2m" secs))))
 
 (defun org-table-fedit-convert-buffer (function)
   "Convert all references in this buffer, using FUNCTION."
-- 
1.7.9

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [bug] Remote durations are considered as fractions
  2012-04-20 20:45       ` Sebastien Vauban
@ 2012-04-20 23:22         ` Bastien
  2012-05-02 10:32           ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2012-04-20 23:22 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



Hi Sébastien,

"Sebastien Vauban"
<wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:

> I think this is it...

Yes..  but in fact, this is precisely the difference between the `t' and
the `T' flags - the latter displays seconds while the former display the
output according to `org-table-duration-custom-format', which you can
customize.  Sorry I didn't mention this before.

-- 
 Bastien

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

* Re: [bug] Remote durations are considered as fractions
  2012-04-20 23:22         ` Bastien
@ 2012-05-02 10:32           ` Sebastien Vauban
  2012-05-09 19:16             ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2012-05-02 10:32 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Bastien,

Bastien wrote:
> "Sebastien Vauban" writes:
>
>> I think this is it...
>
> Yes.. but in fact, this is precisely the difference between the `t' and the
> `T' flags - the latter displays seconds while the former display the output
> according to `org-table-duration-custom-format', which you can customize.
> Sorry I didn't mention this before.

I have the impression you mixed, in the above, seconds with *fraction of*
seconds:

- the flag `T' currently means HH:MM:SS, while
- the flag `t' currently means "fractional time" of hours (by default).

As you say, `t' may be further customized:

    ┏━━━━
    ┃ org-table-duration-custom-format is a variable defined in `org-table.el'.
    ┃ Its value is hours
    ┃ 
    ┃ Documentation:
    ┃ Format for the output of calc computations like $1+$2;t.
    ┃ The default value is 'hours, and will output the results as a
    ┃ number of hours.  Other allowed values are 'seconds, 'minutes and
    ┃ 'days, and the output will be a fraction of seconds, minutes or
    ┃ days.
    ┗━━━━

Hence, you really have 5 cases:

- t, fraction of days
- t, fraction of hours
- t, fraction of minutes
- t, fraction of seconds
- T, HH:MM:SS

Those 5 cases are currently handled (in that order) in the following function:

--8<---------------cut here---------------start------------->8---
(defun org-table-time-seconds-to-string (secs &optional output-format)
  "Convert a number of seconds to a time string.
If OUTPUT-FORMAT is non-nil, return a number of days, hours,
minutes or seconds."
  (let* ((secs0 (abs secs))
	 (res
	  (cond ((eq output-format 'days)
		 (format "%.3f" (/ (float secs0) 86400)))
		((eq output-format 'hours)
		 (format "%.2f" (/ (float secs0) 3600)))
		((eq output-format 'minutes)
		 (format "%.1f" (/ (float secs0) 60)))
		((eq output-format 'seconds)
		 (format "%d" secs0))
		(t (org-format-seconds "%.2h:%.2m:%.2s" secs0)))))
    (if (< secs 0) (concat "-" res) res)))
--8<---------------cut here---------------end--------------->8---

My patch just addressed the HH:MM:SS format (that is, the `T' flag).
It does not impact the fractional representation of time (the `t' flag).

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [bug] Remote durations are considered as fractions
  2012-05-02 10:32           ` Sebastien Vauban
@ 2012-05-09 19:16             ` Sebastien Vauban
  2012-06-04 15:02               ` Sebastien Vauban
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2012-05-09 19:16 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Bastien,

"Sebastien Vauban" wrote:
> Bastien wrote:
>> "Sebastien Vauban" writes:
>>
>>> I think this is it...
>>
>> Yes.. but in fact, this is precisely the difference between the `t' and the
>> `T' flags - the latter displays seconds while the former display the output
>> according to `org-table-duration-custom-format', which you can customize.
>> Sorry I didn't mention this before.
>
> I have the impression you mixed, in the above, seconds with *fraction of*
> seconds:
>
> - the flag `T' currently means HH:MM:SS, while
> - the flag `t' currently means "fractional time" of hours (by default).
>
> As you say, `t' may be further customized:
>
>     ┏━━━━
>     ┃ org-table-duration-custom-format is a variable defined in `org-table.el'.
>     ┃ Its value is hours
>     ┃ 
>     ┃ Documentation:
>     ┃ Format for the output of calc computations like $1+$2;t.
>     ┃ The default value is 'hours, and will output the results as a
>     ┃ number of hours.  Other allowed values are 'seconds, 'minutes and
>     ┃ 'days, and the output will be a fraction of seconds, minutes or
>     ┃ days.
>     ┗━━━━
>
> Hence, you really have 5 cases:
>
> - t, fraction of days
> - t, fraction of hours
> - t, fraction of minutes
> - t, fraction of seconds
> - T, HH:MM:SS
>
> Those 5 cases are currently handled (in that order) in the following function:
>
> (defun org-table-time-seconds-to-string (secs &optional output-format)
>   "Convert a number of seconds to a time string.
> If OUTPUT-FORMAT is non-nil, return a number of days, hours,
> minutes or seconds."
>   (let* ((secs0 (abs secs))
> 	 (res
> 	  (cond ((eq output-format 'days)
> 		 (format "%.3f" (/ (float secs0) 86400)))
> 		((eq output-format 'hours)
> 		 (format "%.2f" (/ (float secs0) 3600)))
> 		((eq output-format 'minutes)
> 		 (format "%.1f" (/ (float secs0) 60)))
> 		((eq output-format 'seconds)
> 		 (format "%d" secs0))
> 		(t (org-format-seconds "%.2h:%.2m:%.2s" secs0)))))
>     (if (< secs 0) (concat "-" res) res)))
>
> My patch just addressed the HH:MM:SS format (that is, the `T' flag).
> It does not impact the fractional representation of time (the `t' flag).

I just had to look at some table using time references :

    | 08:30 | 09:00 |
    | 09:30 |       |

As the end time on the first line is equal to the beginning time on the second
one, I try using a formula to copy the time:

    |  08:30 | 09:00 |
    | #ERROR |       |
    #+TBLFM: @2$1=@1$2

The above does not work because Calc makes a division of 9 by 0, as -- by
default, without an explicit format -- data is considered as numeric, right?

Hence, I need to use the T flag, but this doesn't look right yet:

    |    08:30 | 09:00 |
    | 09:00:00 |       |
    #+TBLFM: @2$1=@1$2;T

This is what the above patch is supposed to solve.

BTW, I tried other variants:

1. replacing `:' by `h'

    | 08h30 | 09h00 |
    | 9 h00 |       |
    #+TBLFM: @2$1=@1$2

   Weird that the 9 is moved away from the `h'. I can accept that the leading
   0 is removed, though.

2. ... and using a string format:

    | 8h30 | 9h00 |
    |    9 |      |
    #+TBLFM: @2$1=@1$2;%s

   Another weird results for me...

Isn't there any way to say "copy verbatim the contents" of that field?

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [bug] Remote durations are considered as fractions
  2012-05-09 19:16             ` Sebastien Vauban
@ 2012-06-04 15:02               ` Sebastien Vauban
  0 siblings, 0 replies; 9+ messages in thread
From: Sebastien Vauban @ 2012-06-04 15:02 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi,

May I bump up this thread (and its inlined, older, corollary)?

Best regards,
  Seb


"Sebastien Vauban" wrote:
> "Sebastien Vauban" wrote:
>> Bastien wrote:
>>> "Sebastien Vauban" writes:
>>>
>>>> I think this is it...
>>>
>>> Yes.. but in fact, this is precisely the difference between the `t' and the
>>> `T' flags - the latter displays seconds while the former display the output
>>> according to `org-table-duration-custom-format', which you can customize.
>>> Sorry I didn't mention this before.
>>
>> I have the impression you mixed, in the above, seconds with *fraction of*
>> seconds:
>>
>> - the flag `T' currently means HH:MM:SS, while
>> - the flag `t' currently means "fractional time" of hours (by default).
>>
>> As you say, `t' may be further customized:
>>
>>     ┏━━━━
>>     ┃ org-table-duration-custom-format is a variable defined in `org-table.el'.
>>     ┃ Its value is hours
>>     ┃ 
>>     ┃ Documentation:
>>     ┃ Format for the output of calc computations like $1+$2;t.
>>     ┃ The default value is 'hours, and will output the results as a
>>     ┃ number of hours.  Other allowed values are 'seconds, 'minutes and
>>     ┃ 'days, and the output will be a fraction of seconds, minutes or
>>     ┃ days.
>>     ┗━━━━
>>
>> Hence, you really have 5 cases:
>>
>> - t, fraction of days
>> - t, fraction of hours
>> - t, fraction of minutes
>> - t, fraction of seconds
>> - T, HH:MM:SS
>>
>> Those 5 cases are currently handled (in that order) in the following function:
>>
>> (defun org-table-time-seconds-to-string (secs &optional output-format)
>>   "Convert a number of seconds to a time string.
>> If OUTPUT-FORMAT is non-nil, return a number of days, hours,
>> minutes or seconds."
>>   (let* ((secs0 (abs secs))
>> 	 (res
>> 	  (cond ((eq output-format 'days)
>> 		 (format "%.3f" (/ (float secs0) 86400)))
>> 		((eq output-format 'hours)
>> 		 (format "%.2f" (/ (float secs0) 3600)))
>> 		((eq output-format 'minutes)
>> 		 (format "%.1f" (/ (float secs0) 60)))
>> 		((eq output-format 'seconds)
>> 		 (format "%d" secs0))
>> 		(t (org-format-seconds "%.2h:%.2m:%.2s" secs0)))))
>>     (if (< secs 0) (concat "-" res) res)))
>>
>> My patch just addressed the HH:MM:SS format (that is, the `T' flag).
>> It does not impact the fractional representation of time (the `t' flag).
>
> I just had to look at some table using time references :
>
>     | 08:30 | 09:00 |
>     | 09:30 |       |
>
> As the end time on the first line is equal to the beginning time on the second
> one, I try using a formula to copy the time:
>
>     |  08:30 | 09:00 |
>     | #ERROR |       |
>     #+TBLFM: @2$1=@1$2
>
> The above does not work because Calc makes a division of 9 by 0, as -- by
> default, without an explicit format -- data is considered as numeric, right?
>
> Hence, I need to use the T flag, but this doesn't look right yet:
>
>     |    08:30 | 09:00 |
>     | 09:00:00 |       |
>     #+TBLFM: @2$1=@1$2;T
>
> This is what the above patch is supposed to solve.
>
> BTW, I tried other variants:
>
> 1. replacing `:' by `h'
>
>     | 08h30 | 09h00 |
>     | 9 h00 |       |
>     #+TBLFM: @2$1=@1$2
>
>    Weird that the 9 is moved away from the `h'. I can accept that the leading
>    0 is removed, though.
>
> 2. ... and using a string format:
>
>     | 8h30 | 9h00 |
>     |    9 |      |
>     #+TBLFM: @2$1=@1$2;%s
>
>    Another weird results for me...
>
> Isn't there any way to say "copy verbatim the contents" of that field?

-- 
Sebastien Vauban

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

end of thread, other threads:[~2012-06-04 15:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-03 12:35 [bug] Remote durations are considered as fractions Sebastien Vauban
2012-04-10 22:46 ` Bastien
2012-04-19 13:19   ` Sebastien Vauban
2012-04-20 11:21     ` Bastien
2012-04-20 20:45       ` Sebastien Vauban
2012-04-20 23:22         ` Bastien
2012-05-02 10:32           ` Sebastien Vauban
2012-05-09 19:16             ` Sebastien Vauban
2012-06-04 15:02               ` Sebastien Vauban

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