I'm looking for ideas on the best way to approach this problem.
Should I write raw SQL, stay with the ORM or even mix Javascript with
either ORM or SQL?

I want to keep up with player stats for a baseball team.  I've been
reading up on aggregates and annotations.  And, I'm getting somewhere
with it.  But, not quite all the way yet.  I  also wrote some SQL that
accomplishes most everything I need all at once.  I think I could run
with it, too.

To calculate things like "on base percentage" or "batting average", I
need to mix math both vertically and horizontally in the table.  One
way I thought about handling this is to build an HTML table of data
using a queryset based on this example in the Django documentation:

Book.objects.aggregate(Avg('price'), Max('price'), Min('price'))

except, I would need something that summed 3 or 4 different columns.

At that point, I could use javascript to Sum() the total of each and
calculate averages.  So, a table would be built like:

          A            B              C                D            E
                                 F
             G                                     H
Player Name |  Hits  |  Strike Outs  |  Walks  |  Fouled Out |
Javascript Calcuated Total at Bats |  Javascript Calc. Batting AVG  |
Javasctipt On Base %
Player 1             3              2                5             2
                         A+B+C+D+E
  B/F                              (B+D)/F
Player 2             4              2                5             1
                         A+B+C+D+E
  B/F                              (B+D)/F


My models contain 3 tables that join people, tournaments and an "at
bat".  The "AtBat" class is where the statistical data will be
recorded. The model looks like this.  So, I'm saving one result per
record:

101  class AtBat(models.Model):
102     atbat_id = models.AutoField(primary_key=True)
103     player = models.ForeignKey(Person, to_field='f_name',
verbose_name='Player', limit_choices_to={'relationship' : 'Player' })
104     game = models.ForeignKey(Score, to_field='scores_id',
verbose_name='Game')
105     result = models.CharField('Result', choices=(('H', 'Hit'),
('BB', 'Walk'), ('K', 'Strike Out'), ('FO', 'Ground or Fly Out'),
('Sacrifice', 'Sacrafice')), max_length=10)

One of my goals would be to allow users to select certain players,
date ranges or games to filter the results. I'm not sure how that
might impact the solution.

Any suggestions?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to