Package nflgame :: Module seq :: Class Gen
[frames] | no frames]

Class Gen

source code

object --+
         |
        Gen
Known Subclasses:

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
 
filter(self, **kwargs)
filters the sequence based on a set of criteria.
source code
 
limit(self, n)
Limit the sequence to N items.
source code
 
sort(self, field, descending=True)
sorts the sequence according to the field specified---where field is a property on an item in the sequence.
source code
 
__str__(self)
Returns a list of items 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__

filter(self, **kwargs)

source code 

filters the sequence based on a set of criteria. Parameter names should be equivalent to the properties accessible in the items of the sequence. For example, where the items are instances of the Stats class:

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

Returns a 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 item, that item is excluded from the result set.

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

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

Also, special suffixes that begin with '__' may be added to the end of a field name to invoke built in predicates. For example, this:

   players.filter(receiving_rec=lambda v: v > 0)

Is equivalent to:

   players.filter(receiving_rec__gt=0)

Other suffixes includes gt, le, lt, ne, ge, etc.

(Django users should feel right at home.)

sort(self, field, descending=True)

source code 

sorts the sequence according to the field specified---where field is a property on an item in the sequence. If descending is false, items will be sorted in order from least to greatest.

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

__str__(self)
(Informal representation operator)

source code 

Returns a list of items in the sequence.

Overrides: object.__str__