Amir,

This is one of those cases that's tough because App Engine's datastore
has no on-the-fly SUM ability.  You'd have to write an updating
process that makes periodic calls to your server app to process recent
results and update the entities used for your 24-hour scoring table.

Here's how I'd do it:
- Record each event affecting scoring in an entity (call the model
ScoreEvent) with a timestamp.  The key_name of each ScoreEvent would
be the timestamp + user info.  On write of this entity, update a 24-hr
score entity (call the model Score24) for this particular user.
- Periodically do maintenance calls to your server to update the
Score24 entities.  Each maintenance call would sort ScoreEvents on the
key and then fetch all ScoreEvents since the last Score24 maintenance
call (use a key to mark your place in the ScoreEvents stream).
Querying on keys was added to datastore in Nov:
http://code.google.com/appengine/docs/datastore/queriesandindexes.html#Queries_on_Keys
So for each Score24 maintenance call, you'd fetch some # of ScoreEvent
entities, make a first pass so you combine all events into user
deltas, then update the associated user Score24 entities.  Then save
the last ScoreEvent key that you processed in this maintenance call.
On the next maintenance call, use that "last ScoreEvent key" in the
query just as if you were paging:

query = ScoreEvent.gql('WHERE __key__ > :1 ORDER BY __key__',
last_key)

So your Score24 entities will reflect each user's score over the last
24 hours with some error due to the frequency of your maintenance
calls.

Now getting the top X scoring users over the last 24 hours is a query
on Score24 entities where you sort on score and fetch the top X
entities.

Best,
Bill


Amir Michail wrote:
> Hi,
>
> How can this be done efficiently with the current version of the GAE?
>
> I suppose you could keep track of all events affecting scoring for the
> last 24 hours.  Whenever you handle a request -- even one that does
> not affect scoring -- you could prune out events older than 24 hours
> and add a new one if the player has received more points as a result
> of the current request.
>
> As you take out old events and add in new ones, you also update the
> top 10 ranking for the last 24 hours accordingly.
>
> The problem here is that taking out all the old events can be quite
> expensive.  As an extreme example, if you don't get any requests for
> over 24 hours, then on the next request, you will need to clear out at
> a day's worth of scoring events.
>
> Amir
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to