jbholden / cdcpool_google

0 stars 1 forks source link

Encapsulate a players picks for a week into a single structure? #4

Closed jbholden closed 10 years ago

jbholden commented 10 years ago

From Byron:

Also, would it be a good idea to encapsulate a players picks for a week into a single structure? I'm just thinking out loud, but to see a particular player's picks, you have to do multiple lookups from the picks table.

Brent's Response:

player picks in one place:

The way I implemented the week data class might encapsulate each player's picks in one place. When it is loaded the value is retrieved from the memcache.

It currently looks like this:

class WeekData:
    week = None
    games = None
    player_picks = None
    picks = None
    teams = None
    players = None

The player_picks variable is a dictionary. The key is the player key and the value is a list of all the player's picks for that week. This dictionary is kept in the memcache so it would only need to read the database 1 time once all the picks are made.

Example:

weekdata = database.load_week_data(year=2013,week_number=1)
brent_key = weekdata.get_player_key("Brent H.")
brent_picks_2013_week1 = weekdata.player_picks[brent_key]

picks variable not used

The "picks" variable is similar but the key is the Pick datastore key value and the result in the Pick datastore object. So far I have not used the picks variable for anything so it might be deleted unless we find a use for it.

feedback

Do you think this satisfies the requirement of keeping all the picks by player in one place (one variable in memcache)? Or do you think that this should be added to the datastore models somehow?

Maybe something like this?

class WeekPicks(db.Model):
    week = db.StringProperty(required=True)   # key to the Week class
    player = db.StringProperty(required=True)  # key to the Player class
    picks = db.ListProperty(db.Key)  # list of keys to the Pick class
blreams commented 10 years ago

Keeping player picks available in memcache should be sufficient for our purposes.

jbholden commented 10 years ago

I'm closing this issue. No changes will be made to the datastore and the player picks will be kept in memcache.