Älphä Blüë wrote:
[...]
> Providing the methods as is, with a brief idea of what data is
> returned..

I don't have time to review all these in depth, but:

>
> open_schedule = Schedule.new
> opp_scheduled_ids = []
> 120.times do |i|

Why are you hard-coding the value 120?

>   opp_scheduled_ids[i+1] = open_schedule.find_opponents(i+1)
>   puts "Team ID = #{i+1} and Scheduled IDs are
> #{opp_scheduled_ids[i+1].join(',')} and Array Size =
> #{opp_scheduled_ids[i+1].size}"
> end
> 

Wow.  Notice first of all that you're using i+1 a lot in each iteration. 
If that's even necessary -- and I'm not sure why it would be -- then you 
should put into a variable.

In any case, your times loop is probably unnecessary; each_with_index 
would be better.  Or if find_opponents could take a Team object as 
argument rather than an I'd value, you could use collect to slim this 
down even more.

> This looks into my schedule model/table, finds 120 teams and any
> opponent they've scheduled within date > datetime value and date <
> datetime value. It then returns the ids for those opponents. 

You're reinventing DB queries in the application layer.  This should 
probably be done in the DB.
[...]
> Now I want to pull out each of the opponent_ids that are stored in each
> team's array..
> 
> 120.times do |i|
>   opp_scheduled_ids[i+1].size.times do |x|

size.times?  Why not each_with_index?
>     puts "Team ID = #{i+1} and opp_id = #{opp_scheduled_ids[i+1][x]}"
>   end
> end

Why the i+1 all over the place?  If you really need to start from 1, use 
(1..120).each.  But it would probably be cleaner to use AR and/or a DB 
query for this.
[...]
> What can I do to clean it up so that it still does the same thing but
> with cleaner code or efficiency?  

Stop trying to write Rails like spaghetti PHP!  Learn to get the most 
out of Ruby's Array methods (there are *lots*) and ActiveRecord.  Get 
used to doing big queries in the DB.

[...]
> In addition, my concerns are that I could probably just do "one" find
> command for all of the rating values in a specific table and then search
> within those results, matching up the opponent_id to the team_id and the
> value..
> 
> Example:
> 
> I want to search for the totals for team_id in offense ratings table.
> Do a find(:all) to pull all totals in offense ratings table.
> Find the totals for opp_id = # where team_id = #...
> 
> This would be better, IMO, because I'm not pulling 120 separate queries
> but one large query and searching in the cached results... correct?

Probably.  Aggregate functions will make your life much easier here.
> 
> Any advice will be greatly "appreciated" regarding my concerns..
> 
> Hey Marnen.. I remembered :)

I see! LOL.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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