Exemplo n.º 1
0
class Record():
    def __init__(self):
        self.data = {}
        self.data["ID"] = 0

    def connectDB(self):
        self.db = Database()
        self.db.connect()

    def disconnectDB(self):
        self.db.disconnect()
        del self.db
Exemplo n.º 2
0
def test_database_lastInsertID():
    d = Database()
    d.connect()
    # LAST_INSERT_ID() is zero if you haven't done anything yet
    assert d.lastInsertID() == 0
    sql = ('INSERT INTO tbl_games '
           '(MatchTime, MatchTypeID) '
           'VALUES '
           '(%s, %s)')
    params = ('1960-01-01 19:30:00', 1, )
    d.query(sql, params)
    # Now that we've inserted something, LAST_INSERT_ID() should be positive
    assert d.lastInsertID() > 0
    # Clean up our mess
    sql = ('DELETE FROM tbl_games '
           'WHERE MatchTime = %s AND MatchTypeID = %s')
    rs = d.query(sql, params)
Exemplo n.º 3
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()
Exemplo n.º 4
0
def check_db(ctx, param, value):
    if not value or ctx.resilient_parsing:
        return
    click.echo('=============================================')
    click.echo('Checking database connection...')
    # Load the connection details
    db = Database()
    connection = db.loadConnection()
    click.echo('Credentials:')
    click.echo('dbuser:   '******'dbuser']))
    click.echo('dbpwd:    ' + str(connection['dbpwd']))
    click.echo('dbhost:   ' + str(connection['dbhost']))
    click.echo('dbschema: ' + str(connection['dbschema']))
    # Try to establish the connection
    db.connect()
    # print result
    click.echo(str(db.cnx))
    click.echo(str(db.cursor))
    click.echo('Warnings: ' + str(db.warnings()))
    ctx.exit()
Exemplo n.º 5
0
def test_database_init():
    d = Database()
    assert d.cnx == ''
    assert d.cursor == ''
Exemplo n.º 6
0
def test_database_convertDate():
    d = Database()
    testDate = (1996, 4, 13, 19, 30, 0, 0, 0, 0)
    assert d.convertDate(testDate) == '1996-04-13 19:30:00'
Exemplo n.º 7
0
def test_database_query():
    d = Database()
    d.connect()
    # Inserts
    sql = ('INSERT INTO tbl_games '
           '(MatchTime, MatchTypeID) '
           'VALUES '
           '(%s, %s)')
    params = ('1960-01-01 19:30:00', 1, )
    rs = d.query(sql, params)
    assert d.warnings() is None
    # Updates
    sql = ('UPDATE tbl_games '
           'SET HteamID = %s '
           'WHERE MatchTime = %s AND MatchTypeID = %s')
    rs = d.query(sql, (1, '1960-01-01 19:30:00', 1, ))
    assert d.warnings() is None
    # Selects
    sql = ('SELECT ID '
           'FROM tbl_games '
           'WHERE MatchTime = %s AND MatchTypeID = %s')
    rs = d.query(sql, params)
    if (rs.with_rows):
        records = rs.fetchall()
    for term in records:
        needleID = records[0][0]
    assert needleID > 0
    assert d.warnings() is None
    # Deletes
    sql = ('DELETE FROM tbl_games '
           'WHERE MatchTime = %s AND MatchTypeID = %s')
    rs = d.query(sql, params)
    assert d.warnings() is None
    d.disconnect()
Exemplo n.º 8
0
 def connectDB(self):
     self.db = Database()
     self.db.connect()