コード例 #1
0
ファイル: import_player.py プロジェクト: matt-bernhardt/trapp
    def importRecord(self, record):
        record['PlayerName'] = (
            record['FirstName'] + " " + record['LastName']
        ).strip()

        self.log.message('Importing player ' + str(record))

        p = Player()
        p.connectDB()

        # Does the record exist?
        found = p.lookupIDbyName(record, self.log)
        if (len(found) == 0):
            # Nothing found, so we import
            p.saveDict(record, self.log)
            self.imported += 1
        elif (len(found) == 1):
            # Found one record, so we update
            record['PlayerID'] = found[0]
            p.saveDict(record, self.log)
            self.updated += 1
        else:
            # Something(s) found, so we skip
            self.processMissingRecords(found, len(found))

        self.log.message('')

        return True
コード例 #2
0
ファイル: test_player.py プロジェクト: matt-bernhardt/trapp
def test_player_lookupIDbyName():
    # Setup
    log = Log('test.log')
    p = Player()
    p.connectDB()

    # Format error
    with pytest.raises(RuntimeError) as excinfo:
        needle = 'Wil'
        p.lookupIDbyName(needle, log)
    assert 'lookupID requires a dictionary' in str(excinfo.value)

    # Missing fields error
    with pytest.raises(RuntimeError) as excinfo:
        needle = {
            'FirstName': 'Wil',
            'LastName': 'Trapp'
        }
        p.lookupIDbyName(needle, log)
    assert 'Submitted data is missing the following fields' in str(excinfo.value)

    # Look up a player we know doesn't exist.
    needle = {
        'PlayerName': 'asdf',
    }
    assert p.lookupIDbyName(needle, log) == []

    # Look up a known player in the test dataset.
    needle = {
        'PlayerName': 'Sample Player',
    }
    assert p.lookupIDbyName(needle, log) == [15]
コード例 #3
0
ファイル: import_lineup.py プロジェクト: matt-bernhardt/trapp
    def parsePlayer(self, starter, gameID, teamID, duration):
        result = []

        # Set default timeoff to game duration
        timeoff = duration

        # Split the player string into a list
        result = self.parsePlayerSplit(starter)

        augmented = []
        # parse each member of the list
        for string in result:
            # Split time from player name
            timeon = self.parsePlayerTimeOn(string)
            player = self.parsePlayerRemoveTime(string).strip()

            # Look up playerID
            playerID = [0]
            if (player != 'sent off' and player != 'ejected'):
                p = Player()
                p.connectDB()
                needle = {
                    'PlayerName': player,
                }
                playerID = p.lookupIDbyName(needle, self.log)

            if (len(playerID) == 1):
                playerID = playerID[0]
                augmented.append({
                    'PlayerID': playerID,
                    'PlayerName': player,
                    'TimeOn': timeon,
                    'TimeOff': timeoff,
                    'Ejected': False,
                    'GameID': gameID,
                    'TeamID': teamID
                })
            else:
                self.processMissingRecord(player, len(playerID))

        # Transfer timeon values to previous player's timeoff
        result = self.adjustTimeOff(augmented, timeoff)

        return result