Class Index | File Index

Classes


Namespace db

Creating, migrating, and connecting to databases; working with transactions.
Defined in: <js/db.js>.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
db
Method Summary
Method Attributes Method Name and Description
<static>  
db.getContracts(ot, tid, cb)
Gets all the contracts a team owes.
<static>  
db.getObjectStore(ot, transactionObjectStores, objectStore, readwrite)
Get an object store or transaction based on input which may be the desired object store, a transaction to be used, or null.
<static>  
db.getPayroll(ot, tid, cb)
Get the total payroll for a team.
<static>  
db.getPayrolls(cb)
Get the total payroll for every team team.
<static>  
db.getPlayer(pa, season, tid, attributes, stats, ratings, options)
Get a filtered player object.
<static>  
db.getPlayers(playersAll, season, tid, attributes, stats, ratings, options)
Get an array of filtered player objects.
<static>  
db.getTeam(ta, season, attributes, stats, seasonAttributes, options, cb)
Get a filtered team object.
<static>  
db.getTeams(ot, season, attributes, stats, seasonAttributes, options, sortBy, cb)
Get an array of filtered team objects.
<static>  
db.putPlayer(ot, p, cb)
Add a new player to the database or update an existing player.
Namespace Detail
db
Method Detail
<static> db.getContracts(ot, tid, cb)
Gets all the contracts a team owes. This includes contracts for players who have been released but are still owed money.
Parameters:
{IDBTransaction|null} ot
An IndexedDB transaction on players and releasedPlayers; if null is passed, then a new transaction will be used.
{number} tid
Team ID.
{function(Array)} cb
Callback whose first argument is an array of objects containing contract information.

<static> {(IDBObjectStore|IDBTransaction)} db.getObjectStore(ot, transactionObjectStores, objectStore, readwrite)
Get an object store or transaction based on input which may be the desired object store, a transaction to be used, or null. This allows for the convenient use of transactions or object stores that have already been defined, which is often necessary.
Parameters:
{(IDBObjectStore|IDBTransaction|null)} ot
An IndexedDB object store or transaction to be used; if null is passed, then a new transaction will be used.
{(string|Array.)} transactionObjectStores
The object stores to open a transaction with, if necessary.
{?string} objectStore
The object store to return. If null, return a transaction.
{boolean=} readwrite
Should the transaction be readwrite or not? This only applies when a new transaction is created here (i.e. no transaction or objectStore is passed). Default false.
Returns:
{(IDBObjectStore|IDBTransaction)} The requested object store or transaction.

<static> db.getPayroll(ot, tid, cb)
Get the total payroll for a team. This includes players who have been released but are still owed money from their old contracts.
Parameters:
{IDBTransaction|null} ot
An IndexedDB transaction on players and releasedPlayers; if null is passed, then a new transaction will be used.
{number} tid
Team ID.
{function(number|Array=)} cb
Callback; first argument is the payroll in thousands of dollars, second argument is the list of contract objects from getContracts.

<static> db.getPayrolls(cb)
Get the total payroll for every team team.
Parameters:
{function(Array.)} cb
Callback whose first argument is an array of payrolls, ordered by team id.

<static> {Object} db.getPlayer(pa, season, tid, attributes, stats, ratings, options)
Get a filtered player object. For a player object (pa), create an object suitible for output based on the appropriate season and tid. attributes, stats, and ratings are lists of keys. In the output, the attributes keys will be in the root of the object. There will also be stats and ratings properties containing the filtered stats and ratings objects, if appropriate. If season is null, then the stats and ratings objects will contain lists of objects for each season and tid is ignored. Then, there will also be a careerStats property in the output object containing an object with career averages. This function is overcomplicated and convoluted.
Parameters:
{Object} pa
Player object.
{?number} season
Season to retrieve stats/ratings for. If null, return stats/ratings for all seasons in a list as well as career totals in player.careerStats.
{?number} tid
Team ID to retrieve stats for. This is useful in the case where a player played for multiple teams in a season. Eventually, there should be some way to specify whether the stats for multiple teams in a single season should be merged together or not. For now, passing null just picks the first entry, which is clearly wrong.
{Array.} attributes
List of player attributes to include in output.
{Array.} stats
List of player stats to include in output.
{Array.} ratings
List of player ratings to include in output.
{Object} options
Object containing various options. Possible keys include... "totals": Boolean representing whether to return total stats (true) or per-game averages (false); default is false. "playoffs": Boolean representing whether to return playoff stats (statsPlayoffs and careerStatsPlayoffs) or not; default is false. "showNoStats": Boolean, when true players are returned with zeroed stats objects even if they have accumulated no stats for a team (such as newly drafted players, or players who were just traded for, etc.); this applies only for regular season stats. "fuzz": Boolean, when true noise is added to any returned ratings based on the fuzz variable for the given season (default: false); any user-facing rating should use true, any non-user-facing rating should use false. Other keys should eventually be documented.
Returns:
{Object} Filtered object containing the requested information for the player.

<static> db.getPlayers(playersAll, season, tid, attributes, stats, ratings, options)
Get an array of filtered player objects. After the first argument, all subsequent arguments are passed on to db.getPlayer, where further documentation can also be found.
Parameters:
{Array} playersAll
Array of player objects.
season
tid
attributes
stats
ratings
options

<static> db.getTeam(ta, season, attributes, stats, seasonAttributes, options, cb)
Get a filtered team object. See db.getTeams for documentation.
Parameters:
ta
season
attributes
stats
seasonAttributes
options
cb

<static> db.getTeams(ot, season, attributes, stats, seasonAttributes, options, sortBy, cb)
Get an array of filtered team objects.
Parameters:
{(IDBTransaction|null)} ot
An IndexedDB transaction on players, releasedPlayers, and teams; if null is passed, then a new transaction will be used.
{number} season
Season to retrieve data for.
{Array.} attributes
List of non-seasonal attributes (such as team name) to include in output.
{Array.} stats
List of team stats to include in output.
{Array.} seasonAttributes
List of seasonal attributes (such as won or lost) to include in output.
{Object} options
Object containing various options. Possible keys include... "sortBy": String represeting the sorting method; "winp" sorts by descending winning percentage, "winpAsc" does the opposite, default is sort by team ID. "totals": Boolean representing whether to return total stats (true) or per-game averages (false); default is false. "playoffs": Boolean that, when true, replaces the resturned stats with playoff stats (it doesn't return both like db.getPlayer).
{string|null} sortBy
String represeting the sorting method. "winp" sorts by descending winning percentage, "winpAsc" does the opposite.
{function(Array)} cb
Callback whose first argument is an array of all the team objects.

<static> db.putPlayer(ot, p, cb)
Add a new player to the database or update an existing player. There could be race conditions here if anything calling this relies on the player actually being added/updated in the database before the callback fires, as that is not guaranteed.
Parameters:
{IDBObjectStore|IDBTransaction|null} ot
An IndexedDB object store or transaction on players, readwrite; if null is passed, then a new transaction will be used.
{Object} p
Player object.
{function()=} cb
Optional callback.

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 10 2013 23:08:32 GMT-0400 (EDT)