Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would model your requirements with a <em>one-to-many</em> relationship like this:</p> <pre><code>class Player(db.Model): name = db.StringProperty() class DailyHomeruns(db.Model): date = db.DateProperty() counter = db.IntegerProperty() player = db.ReferenceProperty(Player) </code></pre> <p>To retrieve all the <code>DailyHomeruns</code> of a given <code>Player</code> you can do it in this way:</p> <pre><code>daily_homeruns = DailyHomeruns.all().filter('player =', player) .filter('date &gt;', date_start) .filter('date &lt;=', date_end) .order('date') </code></pre> <p><em><strong>Read Requirement</em></strong>: </p> <blockquote> <p>Google App Engine performance queries scales with the size of the result set and not with the size of the data set.</p> </blockquote> <p>This means that if your <em>last 5 years homeruns query</em> set contains in average 800 entities <sup>*</sup>, this query performs the same whether it searches over a thousand entities or a million entities.</p> <p><em><strong>Write Requirement</em></strong>:<br> Writes are slow in Google App Engine but your scenario seems quite trivial and I don't see any possible contention/timeout problem; after all you just need to serially update the <code>DailyHomeruns</code> incrementing the counter for a small number of times per day.</p> <p><em><strong>Other thoughts</em></strong>:<br> If you need to calculate some stats, for example the total number of Homeruns of a given <code>Player</code> ,don't even think to use <a href="http://code.google.com/intl/it/appengine/docs/python/datastore/gqlreference.html" rel="nofollow">GQL</a> for this purpose because it does not provide any aggregate function à la <code>SQL</code>.<br> Instead, you have to design your database upfront, defining a model to store the total count of Homeruns per player.<br> Using the <a href="http://code.google.com/intl/it/appengine/docs/python/datastore/transactions.html#Using_Transactions" rel="nofollow">transactions</a> API, each time you increment the <code>DailyHomeruns</code> you will need to increment the TotalHomeruns entity for that Player.</p> <p><sup>* I have estimated 3 matches per week for 52 weeks multiplied per 5 years</sup></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload