2016-03-04 70 views
1

我已成功安装descriptive statistics,并尝试使用所提供的方法(如差异等),它会一直拍摄未定义的方法“差异”。我认为这些方法是内置的,可以马上使用。在活动记录中使用描述性统计宝石

Scores_controller.rb

def index           
     statsD = User.all.extend(DescriptiveStatistics) 
     @var = Score.variance(&:strokes) 
    end 

index.html.erb

Variance: <%= @var %> 

我试图在统计应用到我满桌的分数。请帮忙。

+0

什么是中风的数据类型? – MZaragoza

+0

我刚刚创建了一个示例应用程序,使用描述性统计信息,你可以看看它https://github.com/mzaragoza/sample_descriptive_statistics我希望这有助于 – MZaragoza

+0

@MZaragoza谢谢!那是铁轨吗?它看起来有点滑稽 – user2026178

回答

1

您必须为您尝试使用的模型扩展DescriptiveStatistics。它看起来像要扩展User,但要使用Score

def index           
    scores = Score.all.extend(DescriptiveStatistics) 
    @variance = scores.variance(&:strokes) 
end 

现在在你看来都

Variance: <%= @variance %> 

看看这个例子应用 https://github.com/mzaragoza/sample_descriptive_statistics