From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shankar Rao Subject: (no subject) Date: Sun, 11 Oct 2015 12:51:34 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e011833043ae7940521d98a9e Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlMee-000567-Hv for emacs-orgmode@gnu.org; Sun, 11 Oct 2015 15:51:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlMed-0001tB-5e for emacs-orgmode@gnu.org; Sun, 11 Oct 2015 15:51:36 -0400 Received: from mail-ob0-x229.google.com ([2607:f8b0:4003:c01::229]:35892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlMec-0001t5-V3 for emacs-orgmode@gnu.org; Sun, 11 Oct 2015 15:51:35 -0400 Received: by obcor6 with SMTP id or6so11472820obc.3 for ; Sun, 11 Oct 2015 12:51:34 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --089e011833043ae7940521d98a9e Content-Type: text/plain; charset=UTF-8 I have multiple savings accounts, some of which I want to partition into mutiple virtual "subaccounts" that don't merit their own savings account. I want to use org-mode tables to keep track how much money is each subaccount. Given the following table: #+TBLNAME: trans-150925 | ! | Amount | From | To | Subacct | |---+--------+------------+------------+-------------| | | 50 | Short Term | Inbox | Bond | | | 200 | Inbox | Short Term | Bond | | | 120 | Gifts | Inbox | Baby Gifts | | | 75 | Short Term | Inbox | Furnishings | In this example, I have accounts "Inbox", "Short Term", and "Gifts". Of these accounts, "Short Term" has two subaccounts "Bond" and "Furnishings", and "Gifts" has a subaccount "Baby Gifts". I want to create a function that given a subaccount name, calculates the net amount to be withdrawn/deposited to the subaccount. Note that "Inbox" doesn't have any subaccounts, which I want to use to determine if a given transaction is a withdrawal or deposit to the subaccount. I have created the following two functions to implement this: (defun sbr/org-lookup-trans (category date s-name r-name) (let* ((table (concat "trans-" date)) (s-range (format "@I%s..@>%s" s-name s-name)) (s-col (org-table-get-remote table s-range)) (r-range (format "@I%s..@>%s" r-name r-name)) (r-col (org-table-get-remote table r-range))) (org-lookup-all category s-col r-col))) (defun sbr/get-net-subacct (category date) (let* ((from-vec (sbr/org-lookup-trans category date "$Subacct" "$From")) (to-vec (sbr/org-lookup-trans category date "$Subacct" "$To")) (amount-vec (sbr/org-lookup-trans category date "$Subacct" "$Amount")) (from-inbox-ind ) ; A (to-inbox-ind ) ; B (adds amount-vec[from-inbox-ind]) ; C (subs amount-vec[to-inbox-ind])) ; D (calc-eval (if (zerop (length subs)) adds (concat adds "-" subs))))) I need help filling in the pseudo code in lines A through D, namely: 1. how to get a list of all indices of elements in a vector that satisfy a predicate? 2. how to reference a vector by a list of indices? In this example the function should return the following values: (sbr/get-net-subacct "Bond" "150925") ==> 150 (sbr/get-net-subacct "Furnishings" "150925") ==> -75 (sbr/get-net-subacct "Baby Gifts" "150925") ==> -120 How do I implement the above pseudocode functions? Is there a simpler way to accomplish this task? --089e011833043ae7940521d98a9e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I have multiple s= avings accounts, some of which I want to partition into mutiple virtual &qu= ot;subaccounts" that don't merit their own savings account. I want= to use org-mode tables to keep track how much money is each subaccount. Gi= ven the following table:

#+TBLNAME: tra= ns-150925
| ! | Amount= | From =C2=A0 =C2=A0 =C2=A0 | To =C2=A0 =C2=A0 =C2=A0 =C2=A0 | Subacct =C2= =A0 =C2=A0 |
|---+----= ----+------------+------------+-------------|
| =C2=A0 | =C2=A0 =C2=A0 50 | Short Term | Inbox = =C2=A0 =C2=A0 =C2=A0| Bond =C2=A0 =C2=A0 =C2=A0 =C2=A0|
| =C2=A0 | =C2=A0 =C2=A0200 | Inbox =C2= =A0 =C2=A0 =C2=A0| Short Term | Bond =C2=A0 =C2=A0 =C2=A0 =C2=A0|
| =C2=A0 | =C2=A0 =C2=A0120 | G= ifts =C2=A0 =C2=A0 =C2=A0| Inbox =C2=A0 =C2=A0 =C2=A0| Baby Gifts =C2=A0|
| =C2=A0 | =C2=A0 =C2= =A0 75 | Short Term | Inbox =C2=A0 =C2=A0 =C2=A0| Furnishings |

In this example, I have accounts "Inbox"= ;, "Short Term", and "Gifts". Of these accounts, "= Short Term" has two subaccounts "Bond" and "Furnishings= ", and "Gifts" has a subaccount "Baby Gifts". I wa= nt to create a function that given a subaccount name, calculates the net am= ount to be withdrawn/deposited to the subaccount. Note that "Inbox&quo= t; doesn't have any subaccounts, which I want to use to determine if a = given transaction is a withdrawal or deposit to the subaccount.

I have created the following two functions to imp= lement this:

(defun sbr/org-lookup-tran= s (category date s-name r-name)
=C2=A0 (let* ((table (concat "trans-" date))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(s-range (format "@I%s..@>%s" s-name s-name))
<= div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(= s-col (org-table-get-remote table s-range))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(r-range (format &q= uot;@I%s..@>%s" r-name r-name))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(r-col (org-table-get-r= emote table r-range)))
=C2=A0 =C2=A0 (org-lookup-all category s-col r-col)))

(defun sbr/get-net-subacct (category date)
=C2=A0 (let* ((from-vec (sbr/org-looku= p-trans category date "$Subacct" "$From"))
=
= =C2=A0 (to-vec (sbr/org-lookup-trans category date "$Sub= acct" "$To"))
=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0(amount-vec (sbr/org-lookup-t= rans category date "$Subacct" "$Amount")) =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 = =C2=A0=C2=A0=C2=A0(from-inbox-ind <indices of all from-vec elements that= equal "Inbox">) ; A
=C2=A0 =C2=A0 =C2=A0 = =C2=A0(to-inbox-ind =C2=A0<indices of all to-vec elements that equal &qu= ot;Inbox">) ; B
=C2=A0 =C2=A0(adds= amount-vec[from-inbox-ind]) ; C
=C2=A0 =C2=A0 =C2=A0 = =C2=A0(subs amount-vec[to-inbox-ind])) =C2=A0; D
=C2=A0 =C2=A0 (calc-eval (if (zerop (length subs= ))
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0adds
=C2=A0(concat adds "-" subs)))))

I need help filling in the pseudo code in lines = A through D, namely:
<= br>
1. how to get a li= st of all indices of elements in a vector that satisfy a predicate?<= /div>
2. how to reference a vector = by a list of indices?
=
In this example t= he function should return the following values:

(sbr/get-net-subacct "Bond" "150925") =3D=3D&g= t; 150
(sbr/get-net-su= bacct "Furnishings" "150925") =3D=3D> -75
(sbr/get-net-subacct "Baby = Gifts" "150925") =3D=3D> -120

How do I implement the above pseudocode functions? Is there a simp= ler way to accomplish this task?
--089e011833043ae7940521d98a9e--