Esempio n. 1
0
def test_league_printStandings():
    log = Log('test.log')
    l = League()
    l.connectDB()
    l.lookupTeamsBySeason(1900, 'foo', '1900-01-01', log)
    output = l.printStandings()
    assert output == 'Team   Pts    GP\n'
    l.lookupTeamsBySeason(1996, 'mls', '1996-01-01', log)
    output = l.printStandings()
    assert len(output) > 0
Esempio n. 2
0
def test_league_lookupTeamsBySeason():
    log = Log('test.log')
    l = League()
    l.connectDB()
    l.lookupTeamsBySeason(1900, 'mls', '1900-01-01', log)
    assert len(l.teams) == 0
    l.lookupTeamsBySeason(1996, 'foo', '1996-01-01', log)
    assert len(l.teams) == 0
    l.lookupTeamsBySeason(1996, 'mls', '1996-01-01', log)
    assert len(l.teams) == 10
Esempio n. 3
0
def test_league_init():
    l = League()
    # object types
    assert isinstance(l, League)
    assert isinstance(l.data, dict)
    # Default values
    assert l.data['ID'] == 0
Esempio n. 4
0
def test_league_initSeason():
    log = Log('test.log')
    l = League()
    l.connectDB()
    l.lookupTeamsBySeason(1996, 'mls', '1996-01-01', log)
    assert l.teams['CLB']['GP'] == 0
    assert l.teams['CLB']['W'] == 0
    l.lookupTeamsBySeason(1996, 'mls', '1996-06-01', log)
    assert l.teams['CLB']['GP'] == 9
    assert l.teams['CLB']['W'] == 3
Esempio n. 5
0
def test_league_outputLine():
    log = Log('test.log')
    l = League()
    l.connectDB()
    l.lookupTeamsBySeason(1996, 'mls', '1996-01-01', log)
    line = l.outputLine('Abbv', l.teams)
    assert line == 'CLB,COL,DAL,DC,KC,LA,NE,NY,SJ,TB,'
Esempio n. 6
0
def test_league_simulateSeason():
    log = Log('test.log')
    model = 'v0'
    g = Game()
    g.connectDB()
    g.lookupGamesBySeason(1996, 'mls', '1996-01-01', log)
    l = League()
    l.connectDB()
    l.lookupTeamsBySeason(1996, 'mls', '1996-01-01', log)
    l.simulateSeason(g, model, log)
    assert l.standings['CLB']['GP'] == 32
Esempio n. 7
0
def test_league_connection():
    l = League()
    assert hasattr(l, 'db') is False
    l.connectDB()
    assert hasattr(l, 'db')
    l.disconnectDB()
    assert hasattr(l, 'db') is False
Esempio n. 8
0
def main(mode, competition, model, batch, season, start):
    settings = Settings(mode, competition, model, batch, season, start)

    # Reflect back the configuration being used
    click.echo(settings.output())

    # Initialize tooling
    click.echo('Initializing tooling...')
    filename = date.today().strftime("%y%m%d") + '-' + mode + '-' + model
    log = Log('logs/' + filename + '.log')
    log.message('Started')
    output = Log('output/' + filename + '.csv')
    db = Database()
    db.connect()
    log.message('Database connected')

    # Initialize data
    click.echo('Initializing data...')

    league = League()
    league.connectDB()
    league.lookupTeamsBySeason(settings.values['season'],
                               settings.values['competition'],
                               settings.values['start'], log)
    game = Game()
    game.connectDB()
    game.lookupGamesBySeason(settings.values['season'],
                             settings.values['competition'],
                             settings.values['start'], log)

    # Output the starting point for simulation, including the standings.
    click.echo(league.printStandings())
    log.message(league.printStandings())

    # Write top lines of output/labels once
    output.message(league.outputLine('Conference', league.teams))
    output.message(league.outputLine('Abbv', league.teams))

    # Iterate over games
    for i in range(settings.values['batch']):
        log.message("Season " + str(i))
        league.simulateSeason(game, settings.values['model'], log)
        output.message(league.outputLine('Points', league.standings))

    # Teardown
    click.echo('Finishing...')
    db.disconnect()
    log.message('Database disconnected')
    log.end()
Esempio n. 9
0
def test_league_updateStandings():
    log = Log('test.log')
    l = League()
    l.connectDB()
    l.lookupTeamsBySeason(1996, 'mls', '1996-01-01', log)
    l.initSeason()
    # Initial
    assert l.standings['SJ']['GP'] == 0
    assert l.standings['SJ']['Points'] == 0
    assert l.standings['DC']['Points'] == 0
    # Home win
    l.updateStandings('SJ', 'DC', 'home')
    assert l.standings['SJ']['GP'] == 1
    assert l.standings['DC']['GP'] == 1
    assert l.standings['SJ']['Points'] == 3
    assert l.standings['DC']['Points'] == 0
    # Away win
    l.initSeason()
    l.updateStandings('SJ', 'DC', 'away')
    assert l.standings['SJ']['GP'] == 1
    assert l.standings['DC']['GP'] == 1
    assert l.standings['SJ']['Points'] == 0
    assert l.standings['DC']['Points'] == 3
    # Draw
    l.initSeason()
    l.updateStandings('SJ', 'DC', 'draw')
    assert l.standings['SJ']['GP'] == 1
    assert l.standings['DC']['GP'] == 1
    assert l.standings['SJ']['Points'] == 1
    assert l.standings['DC']['Points'] == 1