Permalink
Browse files

group-by-account and add-balance-column implemented

  • Loading branch information...
1 parent 1c34926 commit 672b2ed939e1e4dd7b2ab89c5703c61112cb33f7 @stathissideris committed Sep 13, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/moneyz/core.clj
View
@@ -38,6 +38,18 @@
(fn [[key d]] [key (dataset (:column-names statement) d)])
(group-by :Account (:rows statement)))))
+(defn calculate-balance-column [statement]
+ (reverse (reductions + (reverse (map :Amount (:rows statement))))))
+
+(defn add-balance-column [statement]
+ (let [balance-column (calculate-balance-column statement)]
+ (-> statement
+ (assoc :column-names (conj (:column-names statement) :Balance))
+ (assoc :rows
+ (into [] (map
+ (fn [row bal] (assoc row :Balance bal))
+ (:rows statement) balance-column))))))
+
(def d (group-by-account (merge-statements d1 d2)))
;;(view (time-series-plot (process-dates ($ :Date d)) ($ :Amount d)))

0 comments on commit 672b2ed

Please sign in to comment.