On Jul 17, 2009, at 6:33 PM, Rob Biedenharn wrote:
> On Jul 17, 2009, at 5:55 PM, Älphä Blüë wrote:
>> Steve Ross wrote:
>>> On Jul 17, 2009, at 2:17 PM, Älphä Blüë wrote:
>>>> Finally, saving the data to the Table object that is currently  
>>>> open in
>>>> Rake in the exact format specified above...
>>>
>>> So if I were to abstract this one level, I would say: "you want a
>>> container-like data structure that can describe a unique odd- 
>>> numbered
>>> team id and 14 ratings for even-numbered teams. By iterating this
>>> container, you will then update each database row that corresponds  
>>> to
>>> the team id." Is this a correct description of your goal?
>>>
>>> Sorry if I'm not getting this.
>>
>> hehe, hey steve, no really it's okay mate.  I wish I could describe
>> things better.  I believe it's because I've been working now about 11
>> hours a day 7-days a week on this project and I'm just a bit brain
>> fried.
>>
>> Look back at the pastie code again and look all the way to the  
>> bottom.
>>
>> I wrote a tiny loop in rake that showcases all of the arrays and  
>> their
>> data.
>>
>> From that view point, I have all of the data.  However, let's take a
>> small step into the problem using just two examples..
>>
>> array 1 holds team_id for table one.
>> array 2 holds rating value for table_id for table one.
>> array 3 holds team_id for table two.
>> array 4 holds rating value for table _id for table two.
>>
>> All of these arrays contain exactly 120 rows of data.  But, i can't
>> simply iterate them or match them up.. If I did so I would see:
>>
>> Rownum  |  Array 1  |  Array 2  |  Array 3  |  Array 4
>> 0          65         43.43        47         97.34
>>
>> Notice that array 1 and array 3 which hold the team IDs do not  
>> match up.
>> Therefore I can't just save the data by rows..
>>
>> I need the existing data organized into a complete array so it looks
>> like:
>>
>> Rownum  |  Array 1  |  Array 2  |  Array 3  |  Array 4
>> 0          1          42.14        1          18.97
>> 1          2          97.32        2          49.97
>> 2          3          54.22        3          87.12
>>
>> as you can see by this view, I want all of the arrays gathered into  
>> one
>> large array, sorted by team_id.
>>
>> I mean perhaps my issue is that when I return the data to rake, I  
>> need
>> to first sort the information somehow and then return it to rake.   
>> That
>> way all 28 arrays are already sorted by team_id and can just be  
>> iterated
>> over 120 rows...
>>
>> I hope this makes sense.
>>
>> -- 
>
>
> I think the underlying difficulty is that you need to learn about a  
> collection other than Array ;-)
>
> Take a look at the docs for Hash.
>
> It is sounding like you want a representation like:
>
> [{ :team_id => 1, :desc_of_array_2 => 42.14, :desc_of_array_4 =>  
> 18.97 },
> { :team_id => 2, :desc_of_array_2 => 97.32, :desc_of_array_4 =>  
> 49.97 },
> ...
> ]
>
> or even a hash that maps team_id to its set of stats like:
>
> { 1 => { :desc_of_array_2 => 42.14, :desc_of_array_4 => 18.97 },
>  2 => { :desc_of_array_2 => 97.32, :desc_of_array_4 => 49.97 },
>  ...
>  }
>
> This collection kinda looks like an array when accessed because the  
> method is [] for both Array and Hash. If you want the array 12 value  
> for team 87, you'd have (assuming that the hash is in a variable  
> called stats):
>
> stats[87][:desc_of_array_12]
>
> I'm assuming that you'd have more "natural" names for  
> the :desc_of_array_N
>
> Note that I'm using :symbols, but you could use 'strings' instead.
>
> -Rob


Just saw your other thread on the ruby list, but I'll answer here, too.

Put this at the end of your pastie and see if it helps you see.

# referencing a new key causes an empty has to be stored as the value
stats = Hash.new {|h,k| h[k] = {} }
# i will take on the same values as 0.upto(119)
120.times do |i|
   stats[to_team_id[i]][:to] = to_ppcs[i]
   stats[ro_team_id[i]][:ro] = ro_ppcs[i]
   stats[po_team_id[i]][:po] = po_ppcs[i]
   stats[so_team_id[i]][:so] = so_ppcs[i]
   stats[rzo_team_id[i]][:rzo] = rzo_ppcs[i]
   stats[flo_team_id[i]][:flo] = flo_ppcs[i]
   stats[pio_team_id[i]][:pio] = pio_ppcs[i]
   stats[too_team_id[i]][:too] = too_ppcs[i]
   stats[sao_team_id[i]][:sao] = sao_ppcs[i]
   stats[tflo_team_id[i]][:tflo] = tflo_ppcs[i]
   stats[peo_team_id[i]][:peo] = peo_ppcs[i]
   stats[fdo_team_id[i]][:fdo] = fdo_ppcs[i]
   stats[tdco_team_id[i]][:tdco] = tdco_ppcs[i]
   stats[fdco_team_id[i]][:fdco] = fdco_ppcs[i]
end

puts stats.inspect
# or this might be easier to read
require 'pp'
pp stats


-Rob

Rob Biedenharn          http://agileconsultingllc.com
[email protected]



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to