Hi Prasad,
I think you've done a great job thinking this through, and I do have a suggestion. First though, to clear up a difference in vocabulary, "datastore" is the term I'm using for the service that stores data. What you're referring to as a datastore I would call an "Entity kind", or (I think somewhat inaccurately) a "Table".
In any case, here's what I would suggest:
Entity Kind: WeeklyPlayerStats
Entries:
- Player ID (presumably Google App Engine ID)
- Player Nickname
- Week
- Best Score this week
So an entry will look like:
player_id='123456'
player_nickname='Ruberik'
week=53
best_score=9999999
Then there will be a different WeeklyPlayerStats Entity representing my score in week 54. All you need to do is manually specify a "composite index" in index.yaml for [week, best_score].
For bonus speed -- I recommend this, and it makes the composite index unnecessary -- specify a "parent" for each WeeklyPlayerStats, so your key looks like:
parent_key = ndb.Key(pairs=[('AllWeeklyPlayerStats', 'all'), ('WeekGroup', 'week=%d' % this_week)])
user_key = ndb.Key(pairs=parent_key.pairs() + [('WeeklyPlayerStats', 'u=%s' % user_id)])
Your procedure for fetching data sounds about right, though ties make it trickier. I'd consider:
1. Retrieve the user's row, which you can get without a query -- just construct the key as above and do user_key.get(), which is faster than a query.
2. Ask the ranker for the rank for the user's score. It will also tell you how many are tied at that rank.
3. Ask the ranker for the scores for ranks user_rank - 25 and user_rank + 25.
4. Do some stuff to figure out how to display things in case of ties. :-) The ranker should return enough information for you to do that.
Good luck!
Bartholomew