简体   繁体   English

性能/红宝石/铁路/数据库问题

[英]performance/ruby/rails/db question

I'm creating an online bookmaker odds comparison site for soccer and I'm wondering how to calculate the best odds in Ruby/Rails. 我正在创建一个在线博彩赔率比较网站,并且想知道如何计算Ruby / Rails中的最佳赔率。

I have two models: fixture and odds 我有两个模型:比赛和赔率

Fixture has home and away teams, and odds model has bookmaker ID, home odds, draw odds and away odds. Fixture有主场和客场球队,赔率模型有庄家ID,主场赔率,平局赔率和客场赔率。

I have selections which just stores the selected fixtures/teams in the DB. 我有一些选择只将选定的灯具/团队存储在数据库中。

I'm thinking of doing it this way where I create an multi-dimensional array of the different bookmakers and then add the fixture_id and 1,2 or 3 for home/draw/away and then use that as the key to add the odds 我正在考虑以这种方式创建一个由不同庄家组成的多维数组,然后添加fixture_id和1,2或3进行主页/抽签/ fixture_id牌,然后将其用作添加赔率的关键

Something like odds[bookmaker][fixture][1/2/3] = price then add up the odds = count(odds[bookmaker][fixture][1/2/3]) ? odds[bookmaker][fixture][1/2/3] = price然后加总odds = count(odds[bookmaker][fixture][1/2/3])

Is there an easier way? 有更容易的方法吗? Maybe do it in the DB? 也许在数据库中做?

Without taking performance into account - it's probably not an issue and anyway, we shouldn't optimise for performance until we know we have a problem - I'd say you might introduce a Bookmaker model (if only to store the name) and start making use of ActiveRecord associations. 在不考虑性能的情况下-可能不是问题,无论如何,我们不应该针对性能进行优化,直到我们知道存在问题-我要说您可能会引入Bookmaker模型(如果只是为了存储名称)并开始制作使用ActiveRecord关联。 I'd also consider splitting Odds into the three individual result types, which could be more flexible, especially if you want to add more bets later. 我还将考虑将赔率分为三个单独的结果类型,这可能会更加灵活,特别是如果您以后要添加更多的赌注。 You might get something like: 您可能会得到类似:

class Bookmaker < ActiveRecord::Base
  has_many :odds
end

class Odd < ActiveRecord::Base # good name? Price is almost as common and less likely to be misinterpreted
  belongs_to :fixture
  belongs_to :bookmaker
  # let's assume we use result type = 1/2/3 or maybe :home/:draw/:away
end

class Fixture < ActiveRecord::Base
  has_many :odds
end

What you look to be trying to do is calculate the best price for each result across all bookies making a price on that fixture, or the "overround". 您想要做的是为所有在该固定装置上定价的商品(或“综合”)中的每个结果计算最佳价格。 If it's less than 100% then a potential arbitrage exists. 如果小于100%,则存在潜在套利。

class Odd
  named_scope :for_result, lambda { |res_tp| {:conditions => ['type = ?', res_tp]}}
end

class Fixture
  def best_price(res_type)
    # assumes you have odds stored as a percentage
    odds.for_result(res_type).minimum(:pctage)
  end
  def overround
    [:home, :away, :draw].inject(0.0){|sum, res_tp| sum + best_price(res_tp)}
  end
end

I'm sure the above doesn't exactly fit your data, but it might give an idea of how you might go about it. 我敢保证上面的数据不完全适合您的数据,但是它可能会给您一个思路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM