Пример #1
0
def compileYears():
    # This is the compiler for year-level summary data
    # This is the third compilation step.
    print('Compiling years data')
    log = Log('trapp-compile-years.log')
    log.message('Compiling years data')
    log.end()
Пример #2
0
def importLineups(infile):
    # TODO: Lookup teams in a specified league and year?
    # TODO: Iterate over team list, with separate Importer for each?
    # Feedback, setup
    print('Importing lineups from ' + str(infile))
    log = Log('trapp-import-lineups.log')
    importer = ImporterLineups(infile, log)

    # Check for required fields
    requiredColumns = ([
        'Code',
        'Date',
        'H/A',
        'Opponent',
        'Score',
        'WDL',
        'Record',
        'Goals',
        'Lineup',
    ])
    importer.checkFields(requiredColumns)

    # Do the import
    importer.doImport()

    # Shutdown
    log.end()

    return True
Пример #3
0
def test_log_write():
    l = Log('test.log')
    msg = 'Hello'
    l.message(msg)
    # Re-open file in read mode
    l.file = open('test.log', 'r')
    # Test for message with a newline appended
    assert l.file.readline() == msg + '\n'
Пример #4
0
def compileTeammates():
    # This is the compiler for teammate networks
    # This is the fourth compilation step.
    print('Compiling teammates data')
    log = Log('trapp-compile-teammates.log')
    log.message('Compiling teammates data')
    c = CompilerTeammates(log)
    c.doCompile()
    log.end()
Пример #5
0
def compileGames():
    # This is the compiler for game-level summary data
    # This is the first compilation step.
    print('Compiling games data')
    log = Log('trapp-compile-games.log')
    log.message('Compiling games data')
    c = CompilerGames(log)
    c.doCompile()
    log.end()
Пример #6
0
def test_checkerGames_reviewCompetition():
    log = Log('test.log')
    output = Log('test.csv')
    c = CheckerGames(log, output)
    c.reviewCompetition(1, 1980)
    # Re-open output in read mode
    output.file = open('test.csv', 'r')
    # Two games in the sample dataset for 1980
    assert output.file.readline() == '1,1980,2\n'
Пример #7
0
def test_checkerGames_checkGames():
    log = Log('test.log')
    output = Log('test.csv')
    c = CheckerGames(log, output)
    c.checkGames()
    # Re-open output in read mode
    output.file = open('test.csv', 'r')
    # Default start year is 2012, but sample games are in 1980.
    # This is by design, to give a negative test.
    assert output.file.readline() == ''
Пример #8
0
def importGames(infile):
    # Feedback, setup
    print('Importing games from ' + str(infile))
    log = Log('trapp-import-games.log')
    importer = ImporterGames(infile, log)

    # Check for required fields
    requiredColumns = ([
        'MatchTime',
        'MatchTypeID',
        'HTeamID',
        'ATeamID',
        'VenueID'
    ])
    importer.checkFields(requiredColumns)

    # Do the import
    importer.doImport()

    # Shutdown
    log.end()

    return True
Пример #9
0
def checkGames(args):
    print('Checking game counts\n')

    # Start log
    log = Log('trapp-check-games.log')
    log.message('Started')

    # Output file
    output = Log('trapp-check-games.csv')

    c = CheckerGames(log, output)
    c.checkGames()

    output.end()

    log.end()
Пример #10
0
def importPlayers(infile):
    # Feedback, setup
    print('Importing players from ' + str(infile))
    log = Log('trapp-import-players.log')
    importer = ImporterPlayers(infile, log)

    # Check for required fields
    requiredColumns = ([
        'FirstName',
        'LastName',
        'Position',
        'DOB',
        'Hometown'
    ])
    importer.checkFields(requiredColumns)

    # Do the import
    importer.doImport()

    # Shutdown
    log.end()

    return True
Пример #11
0
def importGoals(infile):
    # Feedback, setup
    print('Importing goals from ' + str(infile))
    log = Log('trapp-import-goals.log')
    importer = ImporterGoals(infile, log)

    # Check for required fields
    requiredColumns = ([
        'Code',
        'Date',
        'H/A',
        'Opponent',
        'Score',
        'Goals',
    ])
    importer.checkFields(requiredColumns)
    log.message('Required fields checked')

    # Do the import
    importer.doImport()
    log.message('Import done')

    # Shutdown
    log.end()
Пример #12
0
def test_log_end():
    l = Log('test.log')
    l.end()
    assert l.file is None
Пример #13
0
def test_gamestat_saveDict():
    log = Log('test.log')
    gs = GameStat()
    gs.connectDB()

    # Formats
    with pytest.raises(RuntimeError) as excinfo:
        data = 'foo'
        gs.saveDict(data, log)
    assert 'saveDict requires a dictionary' in str(excinfo.value)

    # Inserts
    data = {
        'GameID': 1,
        'TeamID': 1,
        'PlayerID': 1,
        'Goals': 0,
        'Ast': 0,
        'Shots': 0,
        'SOG': 0,
        'FC': 0,
        'FS': 0,
        'Off': 0,
        'CK': 0,
        'Blk': 0,
        'YC': 0,
        'RC': 0,
        'ShotsFaced': 0,
        'Saves': 0,
        'GA': 0,
        'CP': 0,
        'Plus': 0,
        'Minus': 0
    }
    assert gs.saveDict(data, log) is True
    assert gs.db.warnings() is None

    # Get last ID
    sql = "SELECT Max(ID) FROM tbl_gamestats"
    rs = gs.db.query(sql, (
    ))
    if (rs.with_rows):
        records = rs.fetchall()
    for item in records:
        lastID = item[0]
    log.message(str(lastID))

    # Updates
    data = {
        'ID': lastID,
        'GameID': 2,
        'TeamID': 2,
        'PlayerID': 2,
        'Goals': 0,
        'Ast': 0,
        'Shots': 0,
        'SOG': 0,
        'FC': 0,
        'FS': 0,
        'Off': 0,
        'CK': 0,
        'Blk': 0,
        'YC': 0,
        'RC': 0,
        'ShotsFaced': 0,
        'Saves': 0,
        'GA': 0,
        'CP': 0,
        'Plus': 0,
        'Minus': 0
    }
    assert gs.saveDict(data, log) is True
    assert gs.db.warnings() is None

    # Delete
    rs = gs.db.query("DELETE FROM tbl_gamestats WHERE ID = %s", (
        lastID,
    ))