Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ndPPPhz/Fixture-Generator

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fixture-Generator

foot-ball-icons

The matches calendar generator you have been looking for

Overview

Fixture-Generator is a fancy, quick and random generator of matches you can import in your JS code to create a football league, basketball tournament or any other sport in which all the partecipants have to challenge each other.

Under the hood is driven by the Round-robin alghorithm which guarantees thah each contestant meets all other contestants in turn.

I have used this tool during the development of What If. Take a look at it if you are a fantasy football player.

Usage

NPM

    npm install fixture-generator

Manual integration

  • Download the source code from Github
  • Import it into your project

Implementation

There are actually two ways for generating fixtures:

  1. Using generateRandomFixture. It will return only one random fixture
const { generateRandomFixture } = require('.fixtureGenerator.js')

/*
    @param  {Array}     array   The array containing all the attendees
*/
const tournaments = generateRandomFixture([1,2,3,4])

console.log(tournaments)

/*
    [
        {
          name: "MatchDay 1",
          value: [
            {
              teamA: 1,
              teamB: 3,
            },
            {
              teamA: 2,
              teamB: 4,
            },
          ],
        },
        {
          name: "MatchDay 2",
          value: [
            {
              teamA: 1,
              teamB: 2,
            },
            {
              teamA: 4,
              teamB: 3,
            },
          ],
        },
        {
          name: "MatchDay 3",
          value: [
            {
              teamA: 1,
              teamB: 4,
            },
            {
              teamA: 3,
              teamB: 2,
            },
          ],
        }
    ]
*/
  1. generateRandomFixtureFromAllPermutations takes as argument the number of fixtures you want to generate.
const { generateRandomFixtureFromAllPermutations } = require('.fixtureGenerator.js')

/*
    @param  {Array}     array   The array containing all the attendees
    @param  {Number}    n       The number of tournaments that needs to be randomly generated 
*/
const tournaments = generateRandomFixtureFromAllPermutations([1,2,3,4], 2)

console.log(tournaments)

/*
    // First calendar
    [.....],
    // Second calendar
    [
        {
          name: "MatchDay 1",
          value: [
            {
              teamA: 1,
              teamB: 3,
            },
            {
              teamA: 2,
              teamB: 4,
            },
          ],
        },
        {
          name: "MatchDay 2",
          value: [
            {
              teamA: 1,
              teamB: 2,
            },
            {
              teamA: 4,
              teamB: 3,
            },
          ],
        },
        {
          name: "MatchDay 3",
          value: [
            {
              teamA: 1,
              teamB: 4,
            },
            {
              teamA: 3,
              teamB: 2,
            },
          ],
        }
    ]
*/

License

License

MIT license

  • Copyright 2020 © Annino De Petra

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.