tonystore / laravel-round-robin
Laravel package to generate sweepstakes using the Round Robin algorithm.
Installs: 1 186
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^7.3|^8.0|^8.1
Requires (Dev)
- phpunit/phpunit: ^7.5|^8|^9
This package is auto-updated.
Last update: 2024-10-27 08:59:06 UTC
README
Laravel package to generate sweepstakes using the Round Robin algorithm. Supports any number of teams, as long as they are greater than a minimum value specified in the configuration file. Built with Laravel Collections for better handling of arrays.
REQUIREMENTS
INSTALLATION VIA COMPOSER
Step 1: Composer
Run this command line in console.
composer require tonystore/laravel-round-robin
Step 2: Publish Config File
Publish Config File
php artisan vendor:publish --provider="Tonystore\LaravelRoundRobin\LaravelRoundRobinProvider" --tag=round-robin
In your configuration file you can define the following:
<?php return [ /** *---------------------------------------------------------------------- * Minimum number of teams to generate a schedule *---------------------------------------------------------------------- */ 'min_teams' => 2, /** *---------------------------------------------------------------------- * Custom name for the first phase of the schedule. *---------------------------------------------------------------------- */ 'one_phase' => 'one', /** *---------------------------------------------------------------------- * Custom name for the return phase of the schedule. *---------------------------------------------------------------------- */ 'way_phase' => 'way', ]
Usage
If you pass it an array of equipment, it will return an array, which contains an array of objects. For each object you will have the home team, away team and the round it belongs to:
['BSC','CSE','LDU','IDV']; [ [ { "phase": "one", "round": 1, "local": "BSC", "visitor": "IDV" }, { "phase": "one", "round": 1, "local": "LDU", "visitor": "CSE" } ], [ { "phase": "one", "round": 2, "local": "IDV", "visitor": "LDU" }, { "phase": "one", "round": 2, "local": "BSC", "visitor": "CSE" } ], [ { "phase": "one", "round": 3, "local": "CSE", "visitor": "IDV" }, { "phase": "one", "round": 3, "local": "BSC", "visitor": "LDU" } ], ]
You can use this package in several ways:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = new RoundRobin($teams); $schedule->schedule();
With static function:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->schedule();
OR
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::makeSchedule($teams, null, true, null, false);
With a helper function:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; schedule($teams, null, true, null, false);
To generate the schedule without shuffling the teams:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->doNotShuffle()->schedule();
To generate the calendar I shuffle the teams with a seed:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->shuffle(12)->schedule();
Any of the available options will generate a collection of ready-made rounds, which you can manipulate at will.
To generate the schedule without shuffling the teams:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->schedule(); $schedule->first(); //It will return the first round available on the connection. $schedule->last(); //It will return the last round available on the connection.
In the same way you can use all the options available in Laravel Collections. Additionally we added a collection to convert rounds to objects, you can use it in the following way.
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->schedule()->toObject(); $schedule[0][0]->local; //It will return the name of the home team, of the first game, of the first available round.
There is also the option to generate round-trip rounds. Example:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->doubleRound()->schedule();
You can filter the calendar by the available phases. Example:
$teams = ['BSC','CSE','CUMBAYA','U. CATOLICA','LDU','AUCAS','GUALACEO','ORENSE','CITY','TU','D. CUENCA','MUSHUCRUNA','IDV','DELFIN','MACARA','9 DE OCTUBRE']; $schedule = RoundRobin::addTeams($teams)->doubleRound()->schedule(); $firstLeg = $schedule->firstLeg(); //Will return only for the first leg. $secondLeg = $schedule->secondLeg(); //Will return only for the second leg.