示例#1
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
示例#2
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,'
示例#3
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
示例#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
示例#5
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
示例#6
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()
示例#7
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