예제 #1
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
예제 #2
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