Esempio n. 1
0
def test_gamestat_checkData():
    gs = GameStat()
    required = ['GameID', 'TeamID', 'PlayerID']

    # This should raise a format error
    with pytest.raises(RuntimeError) as excinfo:
        needle = 'Foo'
        gs.checkData(needle, required)
    assert 'lookupID requires a dictionary' in str(excinfo.value)

    # This should raise a field error
    with pytest.raises(RuntimeError) as excinfo:
        needle = {
            'Foo': 'Bar'
        }
        gs.checkData(needle, required)
    assert 'Submitted data is missing the following fields' in str(excinfo.value)
Esempio n. 2
0
def test_gamestat_lookupID():
    log = Log('test.log')
    gs = GameStat()
    gs.connectDB()

    needle = {
        'GameID': 1,
        'TeamID': 2,
        'PlayerID': 3
    }
    result = gs.lookupID(needle, log)
    assert len(result) == 1

    needle = {
        'GameID': 0,
        'TeamID': 0,
        'PlayerID': 0
    }
    result = gs.lookupID(needle, log)
    assert len(result) == 0
Esempio n. 3
0
    def doCompile(self):
        # The game stats compiler does the following:

        # 1) Assemble list of player appearances
        self.appearances = self.getAppearanceList()
        print("Processing " + str(len(self.appearances)) + " records")
        self.log.message(str(len(self.appearances)) + " records\n")

        # 2) For each appearance:
        for item in self.appearances:

            # 3) Look up ID for this statline
            gs = GameStat()
            gs.connectDB()
            needle = {
                'GameID': item['GameID'],
                'TeamID': item['TeamID'],
                'PlayerID': item['PlayerID']
            }
            statID = gs.lookupID(needle, self.log)
            if len(statID) > 0:
                item['ID'] = statID[0]

            # 4) Calculate summary statistics
            item = self.assembleStatLine(item)

            # 5) Goalkeeper stats

            # 6) Calculate plus/minus
            item = self.assemblePlusMinus(item)

            # Save record in the log
            self.log.message(str(item))

            # 7) Upsert those statistics as GameStat objects
            gs.saveDict(item, self.log)

            self.log.message('')

            # Trying a delay to prevent buffer space problems
            time.sleep(0.01)

        return True
Esempio n. 4
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,
    ))
Esempio n. 5
0
def test_gamestat_disconnect():
    gs = GameStat()
    gs.connectDB()
    assert hasattr(gs, 'db')
    gs.disconnectDB()
    assert hasattr(gs, 'db') is False