113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/concerns/concerns.rb', line 113
def quartile
values = yield.collect{|item| item.price}
if values != []
@stat[:volume] = values.length if @stats[:volume] % 2 == 0
@stats[:median] = (values[@stats[:volume]/2] + values[@stats[:volume]/2 - 1]) / 2
q1 = values[@stats[:volume]/4]
q3 = values[@stats[:volume]/2 + @stats[:volume]/4]
else
mid = @stats[:volume]/2
@stats[:median] = values[mid]
q1 = values[mid/2]
q3 = values[mid + mid/2]
end
end
iqr = q3 - q1
iqr1 = q1 - 1.5 * iqr
iqr3 = q3 + 1.5 * iqr
values.collect{|value| value if value.between?(iqr1,iqr3)}
end
|