On Thu, Jan 8, 2009 at 3:53 PM, boson <[email protected]> wrote:
>
> I've been planning something like this for my app, and so far this is
> the best I've come up with:

But how would you do this with a 24 hour rolling window?

Amir

>
> First of all, you don't want to be querying to sum up scores for
> individual users, so you need to keep a tally in one place.  This is
> BigTable business as usual.
>
> In each relevant entity where you are tallying, track a day and a
> score for that day:
>  user = "Kobe"
>  weight = "180"
>  ...
>  lifetime_score = 14382  # total score over eternity
>  daily_day = "20090108"  # the last day a score was recorded
>  daily_score = 153       # the score for daily_day
>
> When you update the score, do a transaction as follows:
>  if today's date matches entity's daily_day:
>    lifetime_score += new_score
>    daily_score += new_score
>  else:
>    lifetime_score += new_score
>    daily_day = today
>    daily_score = new score
>
> Then your final query is:
>  filter("day =", today_as("YYYYMMDD")).order("-score")
>
> That requires a fairly simple (but custom) index.
>
> The query ignores people who haven't scored today (the first filter
> drops them), and sorts in descending on score.
>
> And of course you should memcache the query results.
>
> Hope this helps!
>
> On Jan 8, 12:33 pm, Amir  Michail <[email protected]> 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
> >
>



-- 
http://readmytweets.com
http://chatbotgame.com
http://numbrosia.com
http://twitter.com/amichail

--~--~---------~--~----~------------~-------~--~----~
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