Worlds Bets
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
sto
2026-09-06 10:07:47 +02:00
parent 49e49dc93d
commit dae86bd1ea
33 changed files with 1337 additions and 1 deletions

93
app/models/world_bet.rb Normal file
View File

@@ -0,0 +1,93 @@
# == Schema Information
#
# Table name: world_bets
#
# id :integer not null, primary key
# bet :string
# french_score :integer
# name :string
# score :integer
# world_score :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class WorldBet < ApplicationRecord
validates :name, presence: true, uniqueness: true
validates :score, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :french_score, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :world_score, presence: true, numericality: { greater_than_or_equal_to: 0 }
@@multiplier_array = [ 20, 15, 12, 10, 8, 6, 4, 3, 2, 1 ]
@@points_array = [ 100, 70, 50, 40, 30, 26, 23, 20, 17, 15 ]
def self.multiplier(i)
if i < 0 or i > 9
return 0
end
@@multiplier_array[i]
end
def self.points(i)
if !i || i < 1
return 0
end
if i <= 10
return @@points_array[i - 1]
end
if i <= 20
return 12
end
if i <= 30
return 10
end
if i <= 40
return 8
end
if i <= 50
return 7
end
if i <= 60
return 6
end
if i <= 70
return 5
end
if i <= 80
return 4
end
if i <= 90
return 3
end
if i <= 100
return 2
end
if i <= 150
return 1
end
0
end
def serialize_bet(w, f)
self.bet = "#{w.join(',')};#{f.join(',')}"
end
def compute_score(participant_scores)
self.score = 0
self.french_score = 0
self.world_score = 0
w = self.bet.split(";", -1).first.split(",", -1)
w.each_with_index do |participant_id, i|
if participant_scores.has_key?(Integer(participant_id))
self.score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
self.world_score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
end
end
f = self.bet.split(";", -1).last.split(",", -1)
f.each_with_index do |participant_id, i|
if participant_scores.has_key?(Integer(participant_id))
self.score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
self.french_score += participant_scores[Integer(participant_id)] * WorldBet.multiplier(i)
end
end
end
end