Re: [Orgmode] Re: Org-Babel and Ledger

2010-08-13 Thread Eric Schulte
Hi Seb,

Sébastien Vauban wxhgmqzgw...@spammotel.com writes:

 Hi Eric,

 Sébastien Vauban wrote:
 Eric Schulte wrote:
 Sébastien Vauban writes:

 As you can see, the tables are completely wrongly made, because they're
 based on spaces (à la Awk) and not on fixed position of fields (à la
 Cut).

 What can I do about this?

 - Post-process every ledger command with some awk or cut command that
   will do whatever is needed

This might actually be a good solution for the shell block you mention
below.


   (org-table-convert-region (point-min) (point-max))

 As you adviced, I can play with the optional parameter in ob-ledger's code.

 But what about the results of sh code?

 Imagine now that I'm forced to use =sh= instead of =ledger=, in the following
 pratical case:

 #+srcname: reg
 #+begin_src sh
 m4 scorpios-ledger.dat | ledger -f - reg unknown
 #+end_src

 I'm using =m4= (and thus make some pre-processing) because I need (or want) to
 be able to switch between =ledger= and =hledger= and comment in or out the
 directives that are accepted by one but not by the other.

 Then, such a result is still problematic:

 09-Aug-21 CHEQUE : 9953055Expenses:Unknown
 166.70 EUR166.70 EUR
 09-Sep-17 CHEQUE : 7691785Expenses:Unknown
 100.00 EUR266.70 EUR
 09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown
-525.00 EUR   -258.30 EUR

 I've looked in =org-babel-execute:sh= and =org-babel-reassemble-table=, among
 others, to look for similar constructs (calls to =org-table-convert-region=)
 but did not find any.

 Is there still a solution to get such results?


As an interim solution you could add a :results scalar header argument
to your sh code block, then pass the output of that code block to a
parsing code block (namely the one from my previous email).  That's
certainly not idea, but it should work for the moment.

Alternately if ledger supports a more clearly delimited output format
(e.g. csv) then that would probably work as well.


 #+results:
 | 09-Aug-21 CHEQUE : 9953055| Expenses:Unknown | 166.70 EUR  
 | 166.70 EUR  |
 | 09-Sep-17 CHEQUE : 7691785| Expenses:Unknown | 100.00 EUR  
 | 266.70 EUR  |
 | 09-Oct-16 REMISE CHEQUE N 8686318 001 105 | Expenses:Unknown | -525.00 EUR 
 | -258.30 EUR |

 Couldn't we specify somehow the field separator as an extra header
 argument?  I've looked for such an already existing in
 http://orgmode.org/manual/Specific-header-arguments.html#Specific-header-arguments,
 but that does not seem to be available yet.

This would probably be a good addition to ob-sh (and any other language
which doesn't have a defined list syntax).  I'll add this idea to the
babel dev stack, but I'm swamped for the next week or so.

Best -- Eric

 Though, I do not know if this is the right solution. I'm sure you'll
 tell me... ;-)

 Best regards,
   Seb

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: Org-Babel and Ledger

2010-08-12 Thread Eric Schulte
Hi Seb,

Sébastien Vauban wxhgmqzgw...@spammotel.com writes:

 Hi Eric(s),

 As you can see, the tables are completely wrongly made, because they're
 based on spaces (à la Awk) and not on fixed position of fields (à la
 Cut).

 What can I do about this?

 - Post-process every ledger command with some awk or cut command that will
   do whatever is needed

 - Exploit the CSV export format (never tried, don't have Ledger 3
   installed yet -- and I'm also using hledger...)

 Couldn't you use ledger's format strings for fine-tuned control of the
 command output? I don't know how you're snarfing the output, but it seems
 like you could using formatting to produce something that already looks
 very much like an org table, or perhaps CSV.

 That anser is not really applicable in my case, as I would like to use at
 least `ledger' and `hledger' for different reports, and they don't share the
 same exporting capabilities.

 Plus the problem would come back for any other command-line tool...


 Many languages import tabular contents into elisp tables which are then
 inserted into Org-mode buffers as Org-formatted tables. This should be
 possible by replacing the call to `buffer-string' at the end of the
 `org-babel-execute:ledger' function with something analogous to the
 following (copied from ob-sqlite.el).

 (if (or (member scalar result-params)
(member html result-params)
(member code result-params)
(equal (point-min) (point-max)))
(buffer-string)
  (org-table-convert-region (point-min) (point-max))

 That's, then, the interesting line for me...


  (org-babel-sqlite-table-or-scalar
   (org-babel-sqlite-offset-colnames
(org-table-to-lisp) headers-p)))

 I would recommend this approach over shell-script post-processing.

 That seems not to work for me, as input data is, for example:

 09-Aug-21 CHEQUE : 9953055Expenses:Unknown
 166.70 EUR166.70 EUR
 09-Sep-17 CHEQUE : 7691785Expenses:Unknown
 100.00 EUR266.70 EUR
 09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown
-525.00 EUR   -258.30 EUR

 and as =org-table-convert-region= can't convert fixed positioned fields
 (when SPC are used instead of TAB):

 (org-table-convert-region beg0 end0 optional separator)

 Convert region to a table.
 The region goes from beg0 to end0, but these borders will be moved
 slightly, to make sure a beginning of line in the first line is included.

 separator specifies the field separator in the lines.  It can have the
 following values:

 '(4) Use the comma as a field separator
 '(16)Use a TAB as field separator
 integer  When a number, use that many spaces as field separator
 nil  When nil, the command tries to be smart and figure out the
  separator in the following way:
  - when each line contains a TAB, assume TAB-separated material
  - when each line contains a comma, assume CSV material
  - else, assume one or more SPACE characters as separator.

 Should that function be smarter, or do I still need pre-processing, then?


Neither, notice that if you pass an integer as the third argument to
org-table-convert-region it will parse on that many consecutive spaces.
The following works for me, on the case your provided although I suppose
it may not work on all cases.

--8---cut here---start-8---
#+results: ledger-output
#+begin_example 
  09-Aug-21 CHEQUE : 9953055Expenses:Unknown
166.70 EUR166.70 EUR
  09-Sep-17 CHEQUE : 7691785Expenses:Unknown
100.00 EUR266.70 EUR
  09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown
   -525.00 EUR   -258.30 EUR
#+end_example

#+begin_src emacs-lisp :var ledger=ledger-output
  (with-temp-buffer
(insert ledger)
(message ledger)
(org-table-convert-region (point-min) (point-max) 2)
(org-table-to-lisp))
#+end_src

#+results:
| 09-Aug-21 CHEQUE : 9953055| Expenses:Unknown | 166.70 EUR  | 
166.70 EUR  |
| 09-Sep-17 CHEQUE : 7691785| Expenses:Unknown | 100.00 EUR  | 
266.70 EUR  |
| 09-Oct-16 REMISE CHEQUE N 8686318 001 105 | Expenses:Unknown | -525.00 EUR | 
-258.30 EUR |
--8---cut here---end---8---

Hope this helps -- Eric


 Thanks for your comments...

 Best regards,
   Seb

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode


Re: [Orgmode] Re: Org-Babel and Ledger

2010-07-30 Thread Eric Schulte
Many languages import tabular contents into elisp tables which are then
inserted into Org-mode buffers as Org-formatted tables.  This should be
possible by replacing the call to `buffer-string' at the end of the
`org-babel-execute:ledger' function with something analogous to the
following (copied from ob-sqlite.el).

--8---cut here---start-8---
(if (or (member scalar result-params)
  (member html result-params)
  (member code result-params)
  (equal (point-min) (point-max)))
  (buffer-string)
(org-table-convert-region (point-min) (point-max))
(org-babel-sqlite-table-or-scalar
 (org-babel-sqlite-offset-colnames
  (org-table-to-lisp) headers-p)))
--8---cut here---end---8---

I would recommend this approach over shell-script post-processing.

Best -- Eric

Eric Abrahamsen e...@ericabrahamsen.net writes:

 On Thu, Jul 29 2010, Sébastien Vauban wrote:


 [...]


 As you can see, the tables are completely wrongly made, because they're based
 on spaces (à la Awk) and not on fixed position of fields (à la Cut).

 What can I do about this?

 - Post-process every ledger command with some awk or cut command that will do
   whatever is needed

 - Exploit the CSV export format (never tried, don't have Ledger 3 installed
   yet -- and I'm also using hledger...)

 - Other ideas?

  Couldn't you use ledger's format strings for fine-tuned control of
  the command output? I don't know how you're snarfing the output, but it
  seems like you could using formatting to produce something that already
  looks very much like an org table, or perhaps CSV.

 Eric


 Do you have suggestions about the best way to go?

 Best regards,
   Seb


 ___
 Emacs-orgmode mailing list
 Please use `Reply All' to send replies to the list.
 Emacs-orgmode@gnu.org
 http://lists.gnu.org/mailman/listinfo/emacs-orgmode

___
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode