Exemplo n.º 1
0
 def getEventSummary(self, item):
     ge = GameEvent()
     ge.connectDB()
     temp = ge.summarizeEvents(item, self.log)
     if(len(temp) == 0):
         temp = [{'Goals': 0, 'Ast': 0}]
     item = dict(item.items() + temp[0].items())
     return item
Exemplo n.º 2
0
    def assemblePlusMinus(self, record):
        # Looks up plus/minus data for this appearance

        # Get eligible goals for this player in this game
        ge = GameEvent()
        ge.connectDB()
        impact = ge.summarizeRelevantGoals(record, self.log)

        # Transfer impact information to record
        record = dict(record, **impact[0])

        return record
Exemplo n.º 3
0
    def importRecord(self, record):
        self.log.message('\nImporting record:\n  ' + str(record))

        for item in record['NewEvents']:
            self.log.message(str(item))

            # Skip over items
            if item is False:
                self.log.message('Skipping FALSE item')
                continue

            e = GameEvent()
            e.connectDB()

            eventID = e.lookupID(item, self.log)

            if (len(eventID) > 1):
                # We have more than one record of this player/team/game/minute.
                # This is a problem.
                self.log.message('Error: ' +
                                 str(len(eventID)) +
                                 ' events found during lookup')
                self.errored += 1
            elif (len(eventID) == 1):
                # We already have a record of this event.
                # We add that eventID to ensure an update.
                item['ID'] = eventID[0]
                e.saveDict(item, self.log)
                self.updated += 1
            else:
                e.saveDict(item, self.log)
                self.imported += 1

        return True
Exemplo n.º 4
0
def test_gameevent_checkData():
    ge = GameEvent()
    required = ['GameID', 'TeamID', 'PlayerID', 'MinuteID']

    # This should raise a format error
    with pytest.raises(RuntimeError) as excinfo:
        needle = 'Foo'
        ge.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'
        }
        ge.checkData(needle, required)
    assert 'Submitted data is missing the following fields' in str(excinfo.value)
Exemplo n.º 5
0
def test_gameevent_lookupID():
    log = Log('test.log')
    ge = GameEvent()
    ge.connectDB()

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

    needle = {
        'GameID': -1,
        'TeamID': -1,
        'PlayerID': -1,
        'MinuteID': -1,
    }
    result = ge.lookupID(needle, log)
    assert len(result) == 0
Exemplo n.º 6
0
def test_gameevent_summarizeRelevantGoals():
    log = Log('test.log')
    ge = GameEvent()
    ge.connectDB()

    # Make sure we can get back zeroes
    data = {
        'TeamID': 0,
        'GameID': 0,
        'TimeOn': 89,
        'TimeOff': 90
    }
    assert ge.summarizeRelevantGoals(data, log) == [{'Plus': 0, 'Minus': 0}]

    # Look up a known test record
    data = {
        'TeamID': 2,
        'GameID': 1,
        'TimeOn': 0,
        'TimeOff': 90
    }
    assert ge.summarizeRelevantGoals(data, log) == [{'Plus': 1, 'Minus': 0}]
Exemplo n.º 7
0
def test_gameevent_saveDict():
    log = Log('test.log')
    ge = GameEvent()
    ge.connectDB()

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

    # Insert dummy data
    data = {
        'GameID': 1,
        'TeamID': 1,
        'PlayerID': 1,
        'MinuteID': 1,
        'Event': 1,
        'Notes': 'DeleteMe'
    }
    assert ge.saveDict(data, log) is True
    assert ge.db.warnings() is None

    # Updates
    data = {
        'ID': 2,
        'GameID': 0,
        'TeamID': 0,
        'PlayerID': 0,
        'MinuteID': 0,
        'Event': 0,
        'Notes': 'EditMe'
    }
    assert ge.saveDict(data, log) is True
    assert ge.db.warnings() is None

    # Delete dummy data
    sql = "DELETE FROM tbl_gameevents WHERE Notes = 'DeleteMe'"
    ge.db.query(sql, ())
Exemplo n.º 8
0
def test_gameevent_disconnect():
    ge = GameEvent()
    ge.connectDB()
    assert hasattr(ge, 'db')
    ge.disconnectDB()
    assert hasattr(ge, 'db') is False