# Database Diagram Advice needed plus Normalization

**URL:** <https://www.ruby-forum.com/t/database-diagram-advice-needed-plus-normalization/172036>\
**Category:** Rails\
**Created:** [July 13, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/database-diagram-advice-needed-plus-normalization/172036 "2009-07-13T17:57:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 13, 2009, 5:57pm UTC](https://www.ruby-forum.com/t/database-diagram-advice-needed-plus-normalization/172036/1 "2009-07-13T17:57:13Z")

</div>

Hi all,

I’m getting into the meat of my application, namely transitional  
calculations between statistical tables. As a brief overview:

37 categorical statistics tables (independent data from one another) but  
each belongs to an inheritance\_template.rb model with  
self.abstract\_class = true so that methods can be shared and code is  
DRY.

Now my main ratings table will need to pull information from all 37  
tables, and calculate variance between that data using standard  
deviation and other advanced mathematics.

So, as an example of a motion diagram:

Ratings controller --\> queries Table #1 of 37 pulling all records  
–\> standard deviation and offset for variance is calculated  
–\> new results are formed  
----\> (should these results be placed somewhere or stored in arrays?)  
–\> new results are further calculated and rating point modifiers are  
assigned  
----\> rating point modifiers should be stored in a table  
------\> table should be accessible by ratings for further use

Ratings controller --\> queries Table #2 of 37 pulling all records  
etc. etc.

Now, at first glance the data being pulled is actually going to happen  
one day each week so it’s probably better to “task” it using a rake  
task. Or, do you disagree and if so, why? I could simply store the  
method in the inheritance\_template model and let the rake task call that  
method and perform the calculations.

However, I need to have the results of those calculations saved  
somewhere so that my ratings table can be created from those values.

So, I need some advice on how to proceed with this diagram and what you  
would suggest about normalizing the data?

I’ve already created this entire platform in PHP but PHP is not rails.

Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![elricstorm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/da6949/32.png) [@elricstorm](https://www.ruby-forum.com/u/elricstorm)\
**Post date:** [July 13, 2009, 6:11pm UTC](https://www.ruby-forum.com/t/database-diagram-advice-needed-plus-normalization/172036/2 "2009-07-13T18:11:22Z")

</div>

I’m thinking along the lines of:

libs/  
… calculations.rb

= which would run calculations for standard deviation and variation on  
data provided to it…

libs/tasks/  
… calculations.rake

desc “Calculate Ratings”  
task :calculate\_all\_ratings =\> :environment do

calculate\_rushing = RushingOffense.find(:all)  
calculate\_rushing.ratings

# need to store the results somewhere…

end

= which would access each model and use a calculation method

RushingOffense model is part of inheritance\_template.rb so the method  
would be located in there…

class InheritanceTemplate \< ActiveRecord::Base  
self.abstract\_class = true

def self.ratings  
calculation\_object = Calculations.new(statistic1, statistic2, etc.)  
etc…  
end

end

= which would access the calculations.rb file which contains the method  
for Calculations.new

Now I just need to figure out if this is a good approach, whether or not  
I need to tie it into another controller as far as tasking goes, and how  
to make it more automated…
