Hi,
I'm working on a class that I'll use in some rails applications that are used to display data in cross-tabulation format (or as it's called in Excel, a "pivot table").  Right now I'm taking an ActiveRecord object, specifying what fields should go where in the crosstab, and then generating a big nested hash (which I call a "tree", but not sure if that's the right terminology).  This isn't too difficult if I always know how many levels the tree will have, etc., but I want this to be flexible enough to handle any reasonable number of levels.  I've also generated crosstab datasets with SQL directly, but it gets a bit hard to follow and in my current situation, the query runs slowly.  This is a bit difficult to explain, so I've put up a web page with an example hash and the desired output here:

http://bryandonovan.com/pastes/crosstab.html

I've been able to get this to mostly work using a couple of different approaches, but I can't get it to work when some of the tree nodes don't contain all of the nodes below it which are contained in other nodes at the same level (once again, hard to explain..).  In other words, I need missing nodes filled with zeros.  For example, I might have a tree like:

A - a - one - 10
      - two - 5
  - b - one - 2
  - c - three - 1
B - a - two - 7
  - b - two - 9

and this should be transformed into something like the following where emtpy nodes are recursively filled, with the last level being filled with zeros (or nil, etc.):

A - a - one - 10
      - two - 5
      - three - 0
  - b - one - 2
      - two - 0
      - three - 0
  - c - one - 0
      - two - 0
      - three - 1
B - a - one - 0
      - two - 7
      - three - 0
  - b - one - 0
      - two - 9
      - three - 0
  - c - one - 0
      - two - 0
      - three - 0

I've basically hit a wall here.. any help would greatly appreciated.

Thanks,
Bryan

_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby

Reply via email to