Re: Second call to ledger.read_journal() fails

2017-08-15 Thread Bob Hossley
On Monday, August 14, 2017 at 7:59:54 PM UTC-7, John Wiegley wrote:
>
>
> There should be a 'ledger.session', package global variable you can use. 
>
>
Thanks.

Unfortunately, ledger.session.close_journal_files() Segmentation faults 
when I use
it as I would like to use it.  If I do a ledger.read_journal()  followed 
immediately by 
ledger.session.close_journal_files(), it does *not* Segmentation fault.  
But when I 
do a journal.query() before the ledger.session.close_journal_files(), it 
faults:

(Pdb) l
>  85  if date:
>  86  qal.extend(['-e', date])
>  87  qal.append('^assets')
>  88  journalx = ledger.read_journal(parameters.fpn_journal)
>  89  sym2name = dict()
>  90  ->for postx in journalx.query(' '.join(qal)):
>  91  if  postx.amount.commodity.symbol != '$':
>  92  sym2name[postx.amount.commodity.symbol] = 
> str(postx.account)
>  93  ledger.session.close_journal_files()
>  94  return sym2name
>  95  #@+node:bob.20170807142056.12: ** main()
> (Pdb) b 93
> Breakpoint 2 at /pri/git/Ledger4/symbol2name.py:93
> (Pdb) c
> > /pri/git/Ledger4/symbol2name.py(93)symbol2name()
> -> ledger.session.close_journal_files()
> (Pdb) s
> Segmentation fault (core dumped)
>

The same thing happens when I set breakpoints at 93 and 94 and then 
continue from 93.
That is, the problem has nothing to do with single stepping into 
ledger.session.close_journal_files().

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Second call to ledger.read_journal() fails

2017-08-14 Thread Bob Hossley
Thanks for responding.

>
> It's supposed to allow multiple calls, with close_journal_files to "reset" 
> things back to a clean slate. 
>

close_journal_files() is *NOT* a  ledger.Journal method.

close_journal_files() is a ledger.Session method.  But I don't know how to 
get a ledger.Session object.

Bob Hossley

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Second call to ledger.read_journal() fails

2017-08-14 Thread Bob Hossley
I'm trying to use the Ledger Python Extension.  I have written a Python 
function to read a journal and return a dictionary mapping stock symbol to 
account name. I'm writing another Python function to calculate the Internal 
Rate of Return for one specified stock.  Hence, I have one Python script 
that attempts a second call to ledger.read_journal().  This second call 
always fails as shown below:

2017-08-14 14:46:49 /pri/git/Ledger4
> $ ./irr01.py -e 2010-01-01 VWO irr.json
> Traceback (most recent call last):
>   File "./irr01.py", line 81, in 
> main()
>   File "./irr01.py", line 60, in main
> journalx = ledger.read_journal(parameters.fpn_journal)
> RuntimeError: Assertion failed in 
> "/build/ledger-2L3TES/ledger-3.1.1+dfsg1/src/session.cc", line 
> 182:std::size_t ledger::session_t::read_data(const string&): xact_count == 
> journal->xacts.size()
> 2017-08-14 14:51:00 /pri/git/Ledger4
>

I have varied which call is second.  The second always fails.  I have 
looked in vain for a call that will "close" a ledger.Journal object or that 
will "close" or re-initialize the ledger library.  Associated with each 
call to ledger.read_journal(), there is a call to journal.query().  This 
query() iterates till it raises exception StopIteration.

Is each job/process allowed to make only one call to 
ledger.read_journal()?  This would be inconvenient and an unusual 
restriction to impose, but it could probably be accommodated.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How do I obtain the "lot price"?

2017-08-03 Thread Bob Hossley
Thanks for any help you can give me.



*Question about Report Format String*The "lot price" (the price of one 
share) is shown in curly braces by the format string parameter %(amount).  
But I have been unable to obtain just the "lot price" using a format string 
parameter.  I suspect that %(price) was intended to be the "lot price" and 
that it is a bug that it displays the %(cost) instead.

*Question about the Ledger Python Extension*

How do you obtain the "lot price" using the Ledger Python Extension?

I suspect that either post.price or post.amount.price should be the "lot 
price" and that it is a bug that neither exists.



*File lots.ledger*Attached is lots.ledger, a small test journal that shows 
the problem:

2008-02-19 (0) SPDR Lehman Int'l  Tres. Bond ETF - Buy 100 shares
> Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR 
> Barclays Int'l Bond ETF  BWX 200. @ $27.25
> Expenses:Investment Expenses:Commissions:Vanguard $2.18
> * Assets:Vanguard Trust Account:Cash - Vanguard California Tax-Free 
> MMF$-5,452.18
>
> 2008-02-19 (1) SPDR Lehman Int'l  Tres. Bond ETF - Buy 117 shares
> Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR 
> Barclays Int'l Bond ETF  BWX 234. @ $27.24995726
> Expenses:Investment Expenses:Commissions:Vanguard $2.56
> * Assets:Vanguard Trust Account:Cash - Vanguard California Tax-Free 
> MMF$-6,379.05
>
> 2008-02-19 (2) SPDR Lehman Int'l  Tres. Bond ETF - Buy 700 shares
> Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR 
> Barclays Int'l Bond ETF  BWX 1400. @ $27.25
> Expenses:Investment Expenses:Commissions:Vanguard$15.26
> * Assets:Vanguard Trust Account:Cash - Vanguard California Tax-Free 
> MMF   $-38,165.26
>
> 2017-06-23 (1to15) SPDR Lehman Int'l  Tres. Bond ETF - Sell 3229.1222 
> shares
> Assets:Vanguard Trust Account:Vanguard Federal Money Market Fund
> $50,736.76
> Expenses:Investment Expenses:Commissions:Vanguard $1.95
> Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR 
> Barclays Int'l Bond ETF  BWX -200. @ $27.6656  ; Sold all of lot 0
> Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR 
> Barclays Int'l Bond ETF  BWX -1400. @ $27.6656  ; Sold all of lot 2
> Assets:Vanguard Trust Account:Vanguard Investments: Bonds:Taxable:SPDR 
> Barclays Int'l Bond ETF  BWX -234. @ $27.66559829  ; Sold all of lot 1
>
>


*Showing the Reports Problem*Here is a report format that shows the problem 
when run on lots.ledger:

ledger -f lots.ledger reg --no-revalued --format 'code=%C 
> amount="%(amount)" quantity=%(quantity(amount)) cost=%(cost) 
> price=%(price)\n'
>

2017-08-02 15:34:43 /pri/git/Ledger4/bugs
> $ ledger -f lots.ledger reg --no-revalued --format 'code=%C 
> amount="%(amount)" quantity=%(quantity(amount)) cost=%(cost) 
> price=%(price)\n'
> code=(0)  amount="BWX 200. {$27.25} [08-Feb-19]" quantity=200 
> cost=$5,450.00 price=$5,450.00
> code=(0)  amount="$2.18" quantity=2.18 cost=$2.18 price=$2.18
> code=(0)  amount="$-5,452.18" quantity=-5452.18 cost=$-5,452.18 
> price=$-5,452.18
> code=(1)  amount="BWX 234. {$27.24995726} [08-Feb-19]" quantity=234 
> cost=$6,376.48999884 price=$6,376.48999884
> code=(1)  amount="$2.56" quantity=2.56 cost=$2.56 price=$2.56
> code=(1)  amount="$-6,379.05" quantity=-6379.05 cost=$-6,379.05 
> price=$-6,379.05
> code=(2)  amount="BWX 1400. {$27.25} [08-Feb-19]" quantity=1400 
> cost=$38,150.00 price=$38,150.00
> code=(2)  amount="$15.26" quantity=15.26 cost=$15.26 price=$15.26
> code=(2)  amount="$-38,165.26" quantity=-38165.26 cost=$-38,165.26 
> price=$-38,165.26
> code=(1to15)  amount="$50,736.76" quantity=50736.76 cost=$50,736.76 
> price=$50,736.76
> code=(1to15)  amount="$1.95" quantity=1.95 cost=$1.95 price=$1.95
> code=(1to15)  amount="BWX -200. {$27.6656} [17-Jun-23]" quantity=-200 
> cost=$-5,533.12 price=$-5,533.12
> code=(1to15)  amount="BWX -1400. {$27.6656} [17-Jun-23]" 
> quantity=-1400 cost=$-38,731.84 price=$-38,731.84
> code=(1to15)  amount="BWX -234. {$27.66559829} [17-Jun-23]" 
> quantity=-234 cost=$-6,473.7486 price=$-6,473.7486
> 2017-08-02 15:35:22 /pri/git/Ledger4/bugs
>
>


*File costPrice.py*Attached is costPrice.py, a Python script that shows the 
problem when run on lots.ledger.

Here is the print statement that generates the output:

print('code={code} amount="{amt}" quantity={qt} cost={cost} 
> price={price} amount.price={aprice}'.format(
> code=xact.code, amt=post.amount, qt=post.amount.number(),
> cost=post.cost, price=hasattr(post, 'price'),
> aprice=hasattr(post.amount.price, 'price')))
>


2017-08-02 16:00:18 /pri/git/Ledger4/bugs/price
> $ python2 costPrice.py lots.ledger
> code=0 amount="BWX 200. {$27.25} [08-Feb-19]" quantity=200 
> cost=$5,450.00 price=False amount.price=

Sorting on multiple keys and Sort Stability

2017-07-05 Thread Bob Hossley
The ledger sort is *NOT* "stable".  A sort is "stable" iff when multiple 
records have the same key, their original order is preserved. Consequently, 
I can't use the ledger sort to achieve sorting on multiple keys.  When I 
convert my GnuCash file to Ledger, the transactions are in random order. I 
want the transactions in my journal ordered first by date and second by 
payee. 

Is there any chance that ledger sort will be made "stable"?  Can anyone 
suggest a way to achieve the journal structure I want?


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.