RE: RE: Multi-level bucketing problem

2011-05-03 Thread Bhinderwala, Shoeb
Whoa! Thanks Juan. I will start to understand/analyze this... From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of JuanManuel Gimeno Illa Sent: Tuesday, May 03, 2011 11:40 AM To: clojure@googlegroups.com Subject: Re: RE: Multi-level

Re: RE: Multi-level bucketing problem

2011-05-03 Thread JuanManuel Gimeno Illa
I'm sure this can be simplyfied: (defn mlg [attrs data] (if (empty? attrs) [ (reduce + (map :mv data)) {:children data}] (let [parts (group-by (first attrs) data) subtrees (map (fn [[value data]] [value (mlg (rest attrs) (map #(dissoc % (first

Re: Multi-level bucketing problem

2011-05-03 Thread JuanManuel Gimeno Illa
I'm sure this can be simplyfied: (defn mlg [attrs data] (if (empty? attrs) [ (reduce + (map :mv data)) {:children data}] (let [parts (group-by (first attrs) data) subtrees (map (fn [[value data]] [value (mlg (rest attrs) (map #(dissoc % (first at

RE: Multi-level bucketing problem

2011-05-02 Thread Bhinderwala, Shoeb
@googlegroups.com Subject: Re: Multi-level bucketing problem One way is not to use a tree structure but to aggregate by "composed" keys, starting with [:attr1] then [:attr1 :attr2] ... (defn sum-by [data attrs] (let [aggregated (group-by (apply juxt attrs) data)] (zipmap (keys aggregated) (ma

Re: Multi-level bucketing problem

2011-05-02 Thread Base
Google Collections has a multimap that could help you with this. It is pretty cool. As a note they actually push immutability pretty hard - maybe Rich got to them? http://guava-libraries.googlecode.com/svn/tags/release09/javadoc/com/google/common/collect/Multimaps.html On May 1, 10:57 pm, "Bh

Re: Multi-level bucketing problem

2011-05-02 Thread Miki
One way is not to use a tree structure but to aggregate by "composed" keys, starting with [:attr1] then [:attr1 :attr2] ... (defn sum-by [data attrs] (let [aggregated (group-by (apply juxt attrs) data)] (zipmap (keys aggregated) (map #(reduce + (map :mv %)) (vals aggregated) (println