post it somewhere where it is more legible. But, it will be a few
hours.
One idea that came to mind after I submitted my question was to break
out the results column into individual booleans. So, my model would
look more like:
Class AtBat(model.models):
.....
hit = BooleanField()
strikeOut = BooleanField()
walk = BooleanField()
.....
That would allow me to sum those columns like:
select sum('hit'), sum('strikeOut'), sum('walk') from AtBat
But, I'm not sure I like this because some columns are mutually
exclusive. You can't have a walk and a strike out at the same 'at
bat'.
On Thu, May 27, 2010 at 2:19 PM, darren <backdoctor@gmail.com> wrote:
> 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-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment