Newlywed Party Monsters

    fixture-generator

    1.0.2 • Public • Published

    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.

    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

    Install

    npm i fixture-generator

    DownloadsWeekly Downloads

    17

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    12.4 kB

    Total Files

    4

    Last publish

    Collaborators

    • ndppphz