Package nflgame :: Module player :: Class Players
[frames] | no frames]

Class Players

source code

object --+
         |
        Players

Players implements a sequence type and provides a convenient API for searching sets of players.

Instance Methods
 
__init__(self, iterable)
Creates a new Players sequence from an iterable where each element of the iterable is an instance of the Player class.
source code
 
name(self, name)
Returns a single player whose name equals `name`.
source code
 
playerid(self, playerid)
Returns a single player whose NFL GameCenter identifier equals `playerid`.
source code
 
touchdowns(self)
touchdowns is a convenience method for returning a Players sequence of all players with at least one touchdown.
source code
 
filter(self, **kwargs)
filters the Players sequence based on a set of criteria.
source code
 
passing(self)
Returns players that have a "passing" statistical category.
source code
 
rushing(self)
Returns players that have a "rushing" statistical category.
source code
 
receiving(self)
Returns players that have a "receiving" statistical category.
source code
 
fumbles(self)
Returns players that have a "fumbles" statistical category.
source code
 
kicking(self)
Returns players that have a "kicking" statistical category.
source code
 
punting(self)
Returns players that have a "punting" statistical category.
source code
 
kickret(self)
Returns players that have a "kickret" statistical category.
source code
 
puntret(self)
Returns players that have a "puntret" statistical category.
source code
 
defense(self)
Returns players that have a "kicking" statistical category.
source code
 
limit(self, n)
Limit the sequence to N players.
source code
 
sort(self, field, descending=True)
sorts the players according to the field specified---where field is a property in a Player object.
source code
 
csv(self, csvfile)
Given a file-like object `csvfile`, csv will write the contents of the Players sequence to csvfile formatted as comma-separated values.
source code
 
__add__(self, other)
Adds two Players sequences by concatenating the generators composing each Players sequence.
source code
 
__str__(self)
Returns a list of player names in the sequence.
source code
 
__iter__(self)
Make this an iterable sequence.
source code
 
__reversed__(self)
Satisfy the built in reversed.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, iterable)
(Constructor)

source code 

Creates a new Players sequence from an iterable where each element of the iterable is an instance of the Player class.

Overrides: object.__init__

name(self, name)

source code 

Returns a single player whose name equals `name`. If no such player can be found, None is returned.

Note that NFL GameCenter formats their names like "T.Brady" and "W.Welker". Thus, `name` should also be in this format.

playerid(self, playerid)

source code 

Returns a single player whose NFL GameCenter identifier equals `playerid`. This probably isn't too useful, unless you need to disambiguate between two players with the name first initial and last name.

If no such player with the given identifier is found, None is returned.

touchdowns(self)

source code 

touchdowns is a convenience method for returning a Players sequence of all players with at least one touchdown.

It is essentially a filter on the following fields: passing_tds, rushing_tds, receiving_tds, kickret_tds and puntret_tds.

filter(self, **kwargs)

source code 

filters the Players sequence based on a set of criteria. Parameter names should be equivalent to the properties accessible in instances of the Player class.

For example:

   players.filter(home=True, passing_tds=1, rushing_yds=lambda x: x>0)

Returns a Players sequence with only players on the home team that have a single passing touchdown and more than zero rushing yards.

If a field specified does not exist for a particular Player, that Player is excluded from the result set.

If a field is set to a value, then only players with fields that equal that value are returned.

If a field is set to a function---which must be a predicate---then only players with field values satisfying that function will be returned.

sort(self, field, descending=True)

source code 

sorts the players according to the field specified---where field is a property in a Player object. If descending is false, players will be sorted in order from least to greatest.

Note that if field does not exist in any Player being sorted, a KeyError will be raised.

csv(self, csvfile)

source code 

Given a file-like object `csvfile`, csv will write the contents of the Players sequence to csvfile formatted as comma-separated values. The resulting file can then be opened directly with programs like Excel, Google Docs, Libre Office and Open Office.

Note that since each player in a Players sequence may have differing statistical categories (like a quarterback and a receiver), the minimum constraining set of statisical categories is used as the header row for the resulting CSV file.

__str__(self)
(Informal representation operator)

source code 

Returns a list of player names in the sequence.

Overrides: object.__str__