fix: correct Elo calculator winner validation logic

The Elo calculator was incorrectly rejecting valid scores (10-7) because
it checked if team score >= 10 without verifying the opposing team's score.

Changes:
- Update winner determination to check both score >= 10 AND score > opponent
- Add detailed error message with actual scores for debugging
- Ensure only one team can win (not both reaching 10 points)
This commit is contained in:
2026-03-27 12:24:46 -07:00
parent 6a852e66e3
commit 119905685f
2 changed files with 16 additions and 26 deletions
+12 -23
View File
@@ -1,28 +1,14 @@
# frozen_string_literal: true
require "good_job"
module EuchreCamp
module Jobs
class CalculateEloJob
def self.perform_later(match_id)
# Enqueue job using GoodJob's database directly
rom = EuchreCamp::App["persistence.rom"]
job_params = {
queue_name: "default",
priority: 0,
serialized_params: { "match_id" => match_id }.to_json,
scheduled_at: Time.now,
created_at: Time.now,
updated_at: Time.now,
job_class: "EuchreCamp::Jobs::CalculateEloJob",
executions_count: 0
}
rom.relations[:good_jobs].insert(job_params)
end
class CalculateEloJob < ActiveJob::Base
queue_as :default
def self.perform(match_id)
# This is the actual job execution
# This job calculates Elo ratings for a match and updates player records
def perform(match_id)
match = find_match(match_id)
return unless match
@@ -40,16 +26,19 @@ module EuchreCamp
# Update player ratings and create snapshots
update_player_ratings(calculation_results, match_id)
# Record partnerships (after Elo snapshots are created)
EuchreCamp::Services::PartnershipTracker.record_match(match_id)
end
private
def self.find_match(match_id)
def find_match(match_id)
rom = EuchreCamp::App["persistence.rom"]
rom.relations[:matches].by_pk(match_id).one
end
def self.fetch_player_ratings(match)
def fetch_player_ratings(match)
rom = EuchreCamp::App["persistence.rom"]
player_ids = [
match[:team_1_p1_id],
@@ -64,7 +53,7 @@ module EuchreCamp
end
end
def self.update_player_ratings(results, match_id)
def update_player_ratings(results, match_id)
rom = EuchreCamp::App["persistence.rom"]
results.each do |player_id, data|