GithubHelp home page GithubHelp logo

flamontagne / rrschedule Goto Github PK

View Code? Open in Web Editor NEW
39.0 4.0 8.0 120 KB

Round-Robin Schedule generator

Home Page: http://flamontagne.github.com/rrschedule

License: MIT License

Ruby 99.46% Shell 0.54%

rrschedule's Introduction

RRSchedule

RRSchedule makes it easier to generate round-robin schedules for sport leagues.

It takes into consideration the number of available playing surfaces and game times and split games into gamedays that respect these contraints.

Installation

gem install rrschedule
require 'rrschedule'

Prepare the schedule

schedule=RRSchedule::Schedule.new(
  #array of teams that will compete against each other. If you group teams into multiple flights (divisions),
  #a separate round-robin is generated in each of them but the "physical constraints" are shared
  :teams => [
    %w(A1 A2 A3 A4 A5 A6 A7 A8),
    %w(B1 B2 B3 B4 B5 B6 B7 B8)
  ],

  #Setup some scheduling rules
  :rules => [
    RRSchedule::Rule.new(:wday => 3, :gt => ["7:00PM","9:00PM"], :ps => ["field #1", "field #2"]),
    RRSchedule::Rule.new(:wday => 5, :gt => ["7:00PM"], :ps => ["field #1"])
  ],
      
  #First games are played on...
  :start_date => Date.parse("2010/10/13"),
  
  #array of dates to exclude
  :exclude_dates => [Date.parse("2010/11/24"),Date.parse("2010/12/15")],
                    
  #Number of times each team must play against each other (default is 1)
  :cycles => 1,
   
  #Shuffle team order before each cycle. Default is true
  :shuffle => true
)

Generate the schedule

schedule.generate

Playing with the output

human readable schedule

puts schedule.to_s

Iterate through schedule

schedule.gamedays.each do |gd|
  puts gd.date.strftime("%Y/%m/%d")
  puts "===================="
  gd.games.each do |g|
    puts g.team_a.to_s + " Vs " + g.team_b.to_s + " on playing surface ##{g.playing_surface} at #{g.game_time.strftime("%I:%M %p")}"     
  end
  puts "\n"
end

Display each round of the round-robin(s) without any date/time or playing location info

puts s.rounds.collect{|r| r.to_s}

Issues / Other

Hope this gem will be useful to some people!

You can read my blog

rrschedule's People

Contributors

flamontagne avatar

Stargazers

Ryan Macdonald avatar Diogo Gomes avatar amanda southworth avatar Brad Crawford avatar Jonathan MacDonald avatar João Pedro Netto avatar Mauro Giacomini avatar Jose Moreno avatar Michał Kuklis avatar Patrick Meunier avatar Chris Greenwood avatar Sean Eshbaugh avatar Florent Monbillard avatar Mike Marcott avatar  avatar Chris Brooks avatar Aaron Glenn avatar Marcin Lewandowski avatar Imran Shakir avatar Joshua Jansen avatar Matthew Levandowski avatar George Faraj avatar Daniel Nitsikopoulos avatar Marcos Sánchez avatar Guillermo Vargas avatar Sam Bauch avatar Mike Vormwald avatar Thomas Athanas avatar Mathias Gawlista avatar Thomas Shelton avatar  avatar Phil Wilson avatar dsimard avatar Brian Moelk avatar Mike Griffin avatar David Demers avatar Josh Kalderimis avatar Brian Smith avatar

Watchers

 avatar Papa Pathé SENE avatar Christoph Seydel avatar George Faraj avatar

rrschedule's Issues

balanced_ps => false throws error in get_best_ps

Hey man. Great gem.

schedule=RRSchedule::Schedule.new(
              :teams => [
                %w(A1 A2 A3 A4 A5 A6 A7 A8),
                %w(B1 B2 B3 B4 B5 B6 B7 B8),
                %w(C1 C2 C3 C4 C5 C6 C7 C8),
                %w(D1 D2 D3 D4 D5 D6 D7 D8),
                %w(E1 E2 E3 E4 E5 E6 E7 E8),                                                                
              ],

              :rules => [
                RRSchedule::Rule.new(
                  :wday => 3,
                  :gt => ["6:00 PM", "6:50 PM"],
                  :ps => ["North Field", "South Field"],
                )
                
              ],
              :cycles => 1,
              :start_date => Date.parse("2010/10/13"),
              :balanced_gt => false,
              :balanced_ps => false
            ).generate

This throws an error on this line: https://github.com/flamontagne/rrschedule/blob/master/lib/rrschedule.rb#L299

Debugging shows that it's only pulling the first letter, so it seems that inside the 'else' it should be @gt_ps_avail[gt].first instead of @gt_ps_avail[gt].first[0]

I know you haven't updated this in quite a while, so I'm not sure if there's an edge case that I'm missing.

I'd be happy to submit a pull request if you'd like. I've got some other ideas that I'd like to play with on this gem also.

Have a way to specify the maximum of playing locations in a rule

Say for example that there are 8 volleyball fields available and that you want a maximum of 4 games played at 7:00 PM. Currently you have to specify 4 playing locations in the array, like [1,2,3,4]. The problem is that no games will be played on fields 5,6,7 and 8. There should be a way to say: "Here is the list of all my playing locations. Now choose 4 of them for the games"

Bug when extra available resources

If you have more playing surfaces available for the number of teams competing, the same playing surfaces might repeat themselves on the same gameday

Error when passed object contains paperclip data

If the object passed into the schedule generator has a paperclip object that was just created using a form, then it does not know how to handle the information and I get a type error. I solved the problem by passing an integer instead of the object itself, but this does break the specification for the gem. It could also be an issue with paperclip. Will submit a similar report.

Home and Away issue for Round Robin

Hi,

I notice there is an issue with rrschedule when generating home and away for certain Teams.

schedule = RRSchedule::Schedule.new(:teams => (1..6).collect.to_a,
:rules => [RRSchedule::Rule.new(:wday => 1)],
:cycles => 2,
:shuffle => false
).generate

The data that it generates out

@rules=[#<RRSchedule::Rule:0x007fac6480a418 @gt=[Thu, 11 Feb 2016 19:00:00 +0000], @ps=["Field #1", "Field #2"], @wday=1>],
 @schedule=
  [{:team_a=>6, :team_b=>1, :gamedate=>Mon, 15 Feb 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>5, :team_b=>2, :gamedate=>Mon, 15 Feb 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>4, :team_b=>3, :gamedate=>Mon, 22 Feb 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>5, :team_b=>1, :gamedate=>Mon, 22 Feb 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>4, :team_b=>6, :gamedate=>Mon, 29 Feb 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>3, :gamedate=>Mon, 29 Feb 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>1, :team_b=>4, :gamedate=>Mon, 07 Mar 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>3, :team_b=>5, :gamedate=>Mon, 07 Mar 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>6, :gamedate=>Mon, 14 Mar 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>3, :team_b=>1, :gamedate=>Mon, 14 Mar 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>4, :gamedate=>Mon, 21 Mar 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>6, :team_b=>5, :gamedate=>Mon, 21 Mar 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>1, :gamedate=>Mon, 28 Mar 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>6, :team_b=>3, :gamedate=>Mon, 28 Mar 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>4, :team_b=>5, :gamedate=>Mon, 04 Apr 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>6, :team_b=>1, :gamedate=>Mon, 04 Apr 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>5, :gamedate=>Mon, 11 Apr 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>3, :team_b=>4, :gamedate=>Mon, 11 Apr 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>1, :team_b=>5, :gamedate=>Mon, 18 Apr 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>6, :team_b=>4, :gamedate=>Mon, 18 Apr 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>3, :gamedate=>Mon, 25 Apr 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>4, :team_b=>1, :gamedate=>Mon, 25 Apr 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>3, :team_b=>5, :gamedate=>Mon, 02 May 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>6, :gamedate=>Mon, 02 May 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>1, :team_b=>3, :gamedate=>Mon, 09 May 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>4, :team_b=>2, :gamedate=>Mon, 09 May 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>5, :team_b=>6, :gamedate=>Mon, 16 May 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>2, :team_b=>1, :gamedate=>Mon, 16 May 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>6, :team_b=>3, :gamedate=>Mon, 23 May 2016, :ps=>"Field #1", :gt=>Thu, 11 Feb 2016 19:00:00 +0000},
   {:team_a=>5, :team_b=>4, :gamedate=>Mon, 23 May 2016, :ps=>"Field #2", :gt=>Thu, 11 Feb 2016 19:00:00 +0000}],

As you look through the data, it seems like Team 1 and Team 6 is challenging each other on the same team_a and team_b slot for both rounds. By right for round 2, Team 6 should be team_b and Team 1 should be team_a.

I tried looking at your code but I can't see to find the issue. Do let me know if you need more info to help you in rectifying the issue. Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.