[GNC-dev] [GNC] Reports: Help normalizing a list of gnc:monetary values

Evelyn Yamanaka evelyn.yamanaka at gmail.com
Wed Mar 31 11:32:41 EDT 2021


Thank you so much, Christopher!

In retrospect it seems so simple, especially since
gnc:gnc-monetary-amount appears elsewhere in the standard report. I
was seriously stuck though, with my non-scheme brain wondering if
there was some object.property syntax and looking for a class
definition of gnc:monetary. Your answer was a life saver!

So, the normalization / percentage representation is actually part of
a report I'm working on whose primary goal is to support some concept
of tagging / grouping for accounts that's independent of the account
tree structure. I have a working version up if you or anyone is
curious:

https://github.com/ritsu/gnucash-reports

Any comments or suggestions would be appreciated, especially since I'm
definitely not a scheme coder. ;) I've tried to leave as much of the
original category-barchart.scm untouched as possible, and marked the
places I've changed with a "Tags:" prefixed comment.

E


On Mon, Mar 29, 2021 at 10:05 PM Christopher Lam
<christopher.lck at gmail.com> wrote:
>
> Hi, the simple answer is gnc:monetary/ would divide two monetary amounts and the result is not a monetary but a simple ratio.
>
> (define (gnc:monetary/ a b)
>  (/ (gnc:gnc-monetary-amount a)
>     (gnc:gnc-monetary-amount b)))
>
> This would do the trick. Afterwards, for the chart amounts you can use the unit-less ratio directly. Do feel free to attach your work and we'll help you complete it.
>
> On Mon, 29 Mar 2021, 8:00 pm Evelyn Yamanaka, <evelyn.yamanaka at gmail.com> wrote:
>>
>> I'm trying to create a stacked bar chart graph where the total for
>> each period on the x-axis is 100%, so you can easily see trends in
>> changes in the proportion of individual accounts relative to the
>> total.
>>
>> I'm using category-barchart.scm as a starting point, where account
>> balances are stored as a list of pairs (<account> <balance-list>) in
>> the variable all-data, and <balance-list> is a list of gnc:monetary
>> values (or something like that?) for each period on the x-axis.
>>
>> I can get totals for each period with:
>>
>> (let ((totals
>>         (map
>>           (lambda (l) (apply gnc:monetary+ l))
>>           (apply zip (map cadr all-data)))))
>>   (set! all-data-totals (list "Total" totals)))
>>
>> However, I'm not sure how to divide gnc:monetary values by other
>> gnc:monetary values. I know I can add with:
>>
>> (for-each
>>   (lambda (d)
>>     (let ((new-data (map gnc:monetary+ (cadr d) (cadr d))))
>>       (set! all-data-new
>>         (append all-data-new
>>                 (list (car d) new-data)))))
>>   all-data)
>>
>> But I'm not sure how to divide. Something like:
>>   (map gnc:monetary/ (cadr all-data-totals) (cadr d))
>>
>> Of course, "gnc:monetary/" is undefined, and simply using "/" does not
>> work either. Is there any way to do this? Any help would be appreciated.
>>
>> Thanks,
>> E
>> _______________________________________________
>> gnucash-user mailing list
>> gnucash-user at gnucash.org
>> To update your subscription preferences or to unsubscribe:
>> https://lists.gnucash.org/mailman/listinfo/gnucash-user
>> If you are using Nabble or Gmane, please see https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
>> -----
>> Please remember to CC this list on all your replies.
>> You can do this by using Reply-To-List or Reply-All.


More information about the gnucash-devel mailing list