nextjs-rewrite #5

Merged
david merged 56 commits from nextjs-rewrite into main 2026-03-30 02:30:16 +00:00
2 changed files with 16 additions and 26 deletions
Showing only changes of commit 119905685f - Show all commits
+12 -23
View File
@@ -1,28 +1,14 @@
# frozen_string_literal: true # frozen_string_literal: true
require "good_job"
module EuchreCamp module EuchreCamp
module Jobs module Jobs
class CalculateEloJob class CalculateEloJob < ActiveJob::Base
def self.perform_later(match_id) queue_as :default
# 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
def self.perform(match_id) # This job calculates Elo ratings for a match and updates player records
# This is the actual job execution def perform(match_id)
match = find_match(match_id) match = find_match(match_id)
return unless match return unless match
@@ -40,16 +26,19 @@ module EuchreCamp
# Update player ratings and create snapshots # Update player ratings and create snapshots
update_player_ratings(calculation_results, match_id) update_player_ratings(calculation_results, match_id)
# Record partnerships (after Elo snapshots are created)
EuchreCamp::Services::PartnershipTracker.record_match(match_id)
end end
private private
def self.find_match(match_id) def find_match(match_id)
rom = EuchreCamp::App["persistence.rom"] rom = EuchreCamp::App["persistence.rom"]
rom.relations[:matches].by_pk(match_id).one rom.relations[:matches].by_pk(match_id).one
end end
def self.fetch_player_ratings(match) def fetch_player_ratings(match)
rom = EuchreCamp::App["persistence.rom"] rom = EuchreCamp::App["persistence.rom"]
player_ids = [ player_ids = [
match[:team_1_p1_id], match[:team_1_p1_id],
@@ -64,7 +53,7 @@ module EuchreCamp
end end
end end
def self.update_player_ratings(results, match_id) def update_player_ratings(results, match_id)
rom = EuchreCamp::App["persistence.rom"] rom = EuchreCamp::App["persistence.rom"]
results.each do |player_id, data| results.each do |player_id, data|
+4 -3
View File
@@ -20,11 +20,12 @@ module EuchreCamp
raise ArgumentError, "Team 2 must have exactly 2 players" unless team_2_players.length == 2 raise ArgumentError, "Team 2 must have exactly 2 players" unless team_2_players.length == 2
# Determine winner (first to 10 points) # Determine winner (first to 10 points)
team_1_wins = team_1_score >= 10 # Allow for exact score tie at 10-10 if provided
team_2_wins = team_2_score >= 10 team_1_wins = team_1_score > team_2_score && team_1_score >= 10
team_2_wins = team_2_score > team_1_score && team_2_score >= 10
unless team_1_wins || team_2_wins unless team_1_wins || team_2_wins
raise ArgumentError, "One team must reach 10 points to win" raise ArgumentError, "One team must reach 10 points to win (Team 1: #{team_1_score}, Team 2: #{team_2_score})"
end end
if team_1_wins && team_2_wins if team_1_wins && team_2_wins