Browse files

fixed PopulationStatus methods

  • Loading branch information...
1 parent d19d396 commit d03a5df1f72c5e87dff9bf5b90f95508a43fb9b6 @dladowitz dladowitz committed Oct 5, 2012
Showing with 9 additions and 9 deletions.
  1. +6 −6 app/models/person.rb
  2. +3 −3 app/models/population_state.rb
View
12 app/models/person.rb
@@ -10,8 +10,8 @@ class Person < ActiveRecord::Base
def population_add
pop_state = PopulationState.first
- if self.sex == "M"
- pop_state.total_males += 1
+ if self.sex == "male"
+ pop_state.total_males += 1
pop_state.total_male_height += self.height
pop_state.total_male_weight += self.weight
else
@@ -25,19 +25,19 @@ def population_add
def population_before_update
pop_state = PopulationState.first
- if self.sex == "M"
+ if self.sex == "male"
pop_state.total_male_height -= Person.find(self.id).height
pop_state.total_male_weight -= Person.find(self.id).weight
else
pop_state.total_female_height -= Person.find(self.id).height
- pop_state.total_female_weight -= Person.find(self.id).height
+ pop_state.total_female_weight -= Person.find(self.id).weight
end
pop_state.save
end
def population_after_update
pop_state = PopulationState.first
- if self.sex == "M"
+ if self.sex == "male"
pop_state.total_male_height += self.height
pop_state.total_male_weight += self.weight
else
@@ -49,7 +49,7 @@ def population_after_update
def population_destroy
pop_state = PopulationState.first
- if self.sex == "M"
+ if self.sex == "male"
pop_state.total_males -= 1
pop_state.total_male_height -= self.height
pop_state.total_male_weight -= self.weight
View
6 app/models/population_state.rb
@@ -2,7 +2,7 @@ class PopulationState < ActiveRecord::Base
attr_accessible :total_female_height, :total_female_weight, :total_females, :total_male_height, :total_male_weight, :total_males
def pop_data
- @population_data ||= {:male {total: total_males, height: total_male_height, weight: total_male_weight},
+ @population_data ||= {:male => {total: total_males, height: total_male_height, weight: total_male_weight},
female: {total: total_females, height: total_female_height, weight: total_female_weight}}
end
@@ -18,14 +18,14 @@ def variance(gender, attribute)
attribute_collection = []
Person.all.each do |person|
if person.sex == gender.to_s
- attribute_collection << person.send(:attribute)
+ attribute_collection << person.send(attribute)
end
end
(1/(pop_data[gender][:total] - 1).to_f)* attribute_collection.inject(0) {|sum, attrib| sum + (attrib - mean(gender, attribute))**2}
end
def attr_prob(gender, attribute)
- (1/Math.sqrt(2*Math::PI*variance(gender, attribute)))**((-(6-mean(gender, attribute))**2)/2*variance(gender, attribute))
+ (1/Math.sqrt(2*Math::PI*variance(gender, attribute)**2))**((-(6-mean(gender, attribute))**2)/2*variance(gender, attribute))
end

0 comments on commit d03a5df

Please sign in to comment.