计算 Ruby 模型中的比率
你好,我正在为当地的一个非政府组织开发一个数据输入系统,该系统对森林中的鸟类进行调查。我有四个模型,即 Bird、Location、Report 和 Ratio。而伯德和位置只是普通模型,只有名称字段,我的报告字段如下。
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,则该比率 应等于鸟 X 在 L 处向 L 报告的鸟类报告总数。如何获取数据 从数据库导入比率模型?
Hi, I am doing a data entry system for a local NGO here which conducts surveys about bird in forests. I have four models namely, Bird, Location, Report and Ratio. While Bird & Location are just plain models with only a name field, my report field is as follows.
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
And in the ratio model I need to calculate a ratio for the following logic.
Given a scenario that a bird X is found at a location L, the ratio
should be equal to number of times bird X is reported at L to the
number of total bird reports reported at L. How do I fetch the data
from the database into the ratio model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在您最初发布问题的 Hobo 邮件列表上回答了这个问题:http:// /groups.google.com/group/hobouusers/browse_thread/thread/99c267cb96cf3bff
I answered this question on the Hobo mailing list where you originally posted your question: http://groups.google.com/group/hobousers/browse_thread/thread/99c267cb96cf3bff