mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added a rake task that randomly selects winners for tournament 204 from seeded tournaments.
This commit is contained in:
@@ -31,6 +31,7 @@ From here, you can run the normal rails commands.
|
|||||||
* ` rails s -b 0.0.0.0` port 3000 is exposed. You can open [http://localhost:3000](http://localhost:3000) after running that command
|
* ` rails s -b 0.0.0.0` port 3000 is exposed. You can open [http://localhost:3000](http://localhost:3000) after running that command
|
||||||
* etc.
|
* etc.
|
||||||
* `rake finish_seed_tournaments` will complete all matches from the seed data. This command takes about 5 minutes to execute
|
* `rake finish_seed_tournaments` will complete all matches from the seed data. This command takes about 5 minutes to execute
|
||||||
|
* `docker-compose -f deploy/docker-compose-test.yml exec -T app rails tournament:assign_random_wins` will complete all matches for tournament 204 from seed data. This task takes a while since it waits for the worker to complete tasks. In my testing, it takes about 3.5 hours to complete.
|
||||||
|
|
||||||
To deploy a a full local version of the app `bash deploy/deploy-test.sh` (this requires docker-compose to be installed). This deploys a full version of the app. App, delayed job, memcached, and mariadb. Now, you can open [http://localhost](http://localhost). Delayed jobs are turned off in dev and everything that is a delayed job in prod just runs in browser.
|
To deploy a a full local version of the app `bash deploy/deploy-test.sh` (this requires docker-compose to be installed). This deploys a full version of the app. App, delayed job, memcached, and mariadb. Now, you can open [http://localhost](http://localhost). Delayed jobs are turned off in dev and everything that is a delayed job in prod just runs in browser.
|
||||||
|
|
||||||
|
|||||||
@@ -18,3 +18,6 @@ docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app rake
|
|||||||
|
|
||||||
echo Resetting the db with seed data
|
echo Resetting the db with seed data
|
||||||
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app bash -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rake db:reset"
|
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app bash -c "DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rake db:reset"
|
||||||
|
|
||||||
|
# echo Simulating tournament 204
|
||||||
|
# docker-compose -f ${project_dir}/deploy/docker-compose-test.yml exec -T app rails tournament:assign_random_wins
|
||||||
|
|||||||
53
lib/tasks/finish_tournament_204.rake
Normal file
53
lib/tasks/finish_tournament_204.rake
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
namespace :tournament do
|
||||||
|
desc "Assign random win types and scores to matches"
|
||||||
|
task assign_random_wins: :environment do
|
||||||
|
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin"]
|
||||||
|
|
||||||
|
@tournament = Tournament.find(204)
|
||||||
|
|
||||||
|
GenerateTournamentMatches.new(@tournament).generate
|
||||||
|
sleep(180)
|
||||||
|
|
||||||
|
@tournament.matches.sort_by(&:bout_number).each do |match|
|
||||||
|
match.reload
|
||||||
|
if match.loser1_name != "BYE" and match.loser2_name != "BYE"
|
||||||
|
# Choose a random winner
|
||||||
|
wrestlers = [match.w1, match.w2]
|
||||||
|
match.winner_id = wrestlers.sample
|
||||||
|
|
||||||
|
# Choose a random win type
|
||||||
|
win_type = WIN_TYPES.sample
|
||||||
|
match.win_type = win_type
|
||||||
|
|
||||||
|
# Assign score based on win type
|
||||||
|
match.score = case win_type
|
||||||
|
when "Decision"
|
||||||
|
low_score = rand(0..10)
|
||||||
|
high_score = low_score + rand(1..7)
|
||||||
|
"#{high_score}-#{low_score}"
|
||||||
|
when "Major"
|
||||||
|
low_score = rand(0..10)
|
||||||
|
high_score = low_score + rand(8..14)
|
||||||
|
"#{high_score}-#{low_score}"
|
||||||
|
when "Tech Fall"
|
||||||
|
low_score = rand(0..10)
|
||||||
|
high_score = low_score + rand(15..19)
|
||||||
|
"#{high_score}-#{low_score}"
|
||||||
|
when "Pin"
|
||||||
|
pin_times = ["0:30","1:12","5:37","2:34","3:54","4:23","5:56","0:12","1:00"]
|
||||||
|
pin_times.sample
|
||||||
|
else
|
||||||
|
"" # Default score
|
||||||
|
end
|
||||||
|
|
||||||
|
# Mark match as finished
|
||||||
|
match.finished = 1
|
||||||
|
match.save
|
||||||
|
|
||||||
|
# Pause to simulate processing delay
|
||||||
|
sleep(30)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user