嗨,我正在为当地的一个非政府组织做一个数据输入系统,该非政府组织对森林中的鸟类进行调查。我有四个模型,分别是 Bird、Location、Report 和 Ratio。虽然 Bird & Location 只是只有名称字段的普通模型,但我的报告字段如下所示。
class Report < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
Date :date
Plumage enum_string(:Breeding, :NonBreeding )
Weather enum_string(:Cloudy, :Sunny, :Humid)
Time enum_string(:Dawn, :Morning, :Noon, :Evening, :Dusk, :Night)
timestamps
end
belongs_to :bird
belongs_to :location
end
在比率模型中,我需要为以下逻辑计算比率。
给定在位置 L 发现鸟 X 的场景,该比率应等于在 L 报告鸟 X 的次数与在 L 报告的鸟总报告数。如何从数据库中获取数据到比率模型?