Esempio n. 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()
Esempio n. 2
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'
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
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()
Esempio n. 6
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()
Esempio n. 7
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,
    ))