Re: Baseball statistics

2010-01-03 Thread Tijmen
Thanks alot! This was really helpful, and yes you're right, the g
field is redundant.

Thanks again!

On Jan 3, 6:36 pm, greatlemer <greatle...@googlemail.com> wrote:
> On Jan 3, 2:36 pm, Tijmen <tijmen.vandenbr...@gmail.com> wrote:
>
>
>
> > Hi there,
>
> > First of all let me say I'm just starting here but need some help with
> > a rather basic question.
>
> > I want to make an app that holds baseball statistics for players of
> > each game and over several seasons. Now I'm new to this db
> > relationship thing and would like to hear your opinion.
>
> > My models.py currently looks like this:
>
> > 
> > from django.db import models
>
> > # Create your models here.
> > class Player(models.Model):
> >     GENDER_CHOICES = (
> >         ('M', 'Male'),
> >         ('F', 'Female'),
> >     )
>
> >     BATS_CHOICES = (
> >         ('R', 'Right'),
> >         ('L', 'Left'),
> >         ('B', 'Both'),
> >     )
>
> >     THROWS_CHOICES = (
> >         ('R', 'Right'),
> >         ('L', 'Left'),
> >         ('B', 'Both'),
> >     )
>
> >     first_name = models.CharField(max_length=50)
> >     last_name = models.CharField(max_length=50)
> >     gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
> >     bats = models.CharField(max_length=1, choices=BATS_CHOICES)
> >     throws = models.CharField(max_length=1, choices=THROWS_CHOICES)
> >     birthdate = models.DateTimeField('birth date')
> >     awards = models.CharField(max_length=200)
> >     height = models.IntegerField()
> >     weight = models.IntegerField()
> >     email = models.CharField(max_length=100)
> >     tel = models.CharField(max_length=50)
>
> >     def __unicode__(self):
> >         #return self.first_name, self.last_name, self.gender
> >         return self.first_name + " " +  self.last_name
>
> > class Game(models.Model):
> >     #players = models.ManyToManyField(Player)           #Player
> >     team = models.CharField(max_length=200)             #Team for
> > which the player plays
> >     league = models.CharField(max_length=200)           #League
> >     opponent = models.CharField(max_length=200)         #The opponent
> >     date = models.DateTimeField('date')                 #Date
>
> >     def __unicode__(self):
> >         return self.team + " vs " + self.opponent
>
> > class Season(models.Model):
> >     year = models.DateTimeField('year')
>
> >     def __unicode__(self):
> >         return self.year
>
> > class Statistic(models.Model):
> >     players = models.ManyToManyField(Player)
> >     games = models.ManyToManyField(Game)
> >     g = models.IntegerField()                           #Games played
> > or pitched
> >     pa = models.IntegerField()                          #Plate
> > appearances estimated using AB + BB + HBP + SF + SH missing catcher
> > interferences
> >     ab = models.IntegerField()                          #At bats
> >     r = models.IntegerField()                           #Runs scored/
> > allowed
> >     h = models.IntegerField()                           #Hits/hits
> > allowed
> >     doubles = models.IntegerField()                     #Doubles hit/
> > allowed
> >     triples = models.IntegerField()                     #Triples hit/
> > allowed
> >     hr = models.IntegerField()                          #Home Runs hit/
> > allowed
> >     rbi = models.IntegerField()                         #Runs Batted
> > In
> >     sb = models.IntegerField()                          #Stolen Bases
> >     cs = models.IntegerField()                          #Caught
> > Stealing
> >     bb = models.IntegerField()                          #Bases on
> > Balls/Walks
> >     so = models.IntegerField()                          #Strikeouts
> >     ba = models.IntegerField()                          #Hits/At bats
> >     obp = models.IntegerField()                         #On Base
> > Percentage (H + BB + HBP)/(AB + BB + HBP + SF)
> >     slg = models.IntegerField()                         #Slugging,
> > Total Bases/At Bats (1B + 2 * 2B + 3 * 3B + 4 * HR)/AB
> >     ops = models.IntegerField()                         #On base +
> > Slugging Percentages
> >     opsplus = models.IntegerField()                     #100*[OBP/lg
> > OBP + SLG/lg SLG -1]
> >     tb = models.IntegerField()                          #Total Bases
> >     gdp = models.IntegerField()                         #Double Plays
> > Gr

Re: Baseball statistics

2010-01-03 Thread greatlemer
On Jan 3, 2:36 pm, Tijmen <tijmen.vandenbr...@gmail.com> wrote:
> Hi there,
>
> First of all let me say I'm just starting here but need some help with
> a rather basic question.
>
> I want to make an app that holds baseball statistics for players of
> each game and over several seasons. Now I'm new to this db
> relationship thing and would like to hear your opinion.
>
> My models.py currently looks like this:
>
> 
> from django.db import models
>
> # Create your models here.
> class Player(models.Model):
>     GENDER_CHOICES = (
>         ('M', 'Male'),
>         ('F', 'Female'),
>     )
>
>     BATS_CHOICES = (
>         ('R', 'Right'),
>         ('L', 'Left'),
>         ('B', 'Both'),
>     )
>
>     THROWS_CHOICES = (
>         ('R', 'Right'),
>         ('L', 'Left'),
>         ('B', 'Both'),
>     )
>
>     first_name = models.CharField(max_length=50)
>     last_name = models.CharField(max_length=50)
>     gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
>     bats = models.CharField(max_length=1, choices=BATS_CHOICES)
>     throws = models.CharField(max_length=1, choices=THROWS_CHOICES)
>     birthdate = models.DateTimeField('birth date')
>     awards = models.CharField(max_length=200)
>     height = models.IntegerField()
>     weight = models.IntegerField()
>     email = models.CharField(max_length=100)
>     tel = models.CharField(max_length=50)
>
>     def __unicode__(self):
>         #return self.first_name, self.last_name, self.gender
>         return self.first_name + " " +  self.last_name
>
> class Game(models.Model):
>     #players = models.ManyToManyField(Player)           #Player
>     team = models.CharField(max_length=200)             #Team for
> which the player plays
>     league = models.CharField(max_length=200)           #League
>     opponent = models.CharField(max_length=200)         #The opponent
>     date = models.DateTimeField('date')                 #Date
>
>     def __unicode__(self):
>         return self.team + " vs " + self.opponent
>
> class Season(models.Model):
>     year = models.DateTimeField('year')
>
>     def __unicode__(self):
>         return self.year
>
> class Statistic(models.Model):
>     players = models.ManyToManyField(Player)
>     games = models.ManyToManyField(Game)
>     g = models.IntegerField()                           #Games played
> or pitched
>     pa = models.IntegerField()                          #Plate
> appearances estimated using AB + BB + HBP + SF + SH missing catcher
> interferences
>     ab = models.IntegerField()                          #At bats
>     r = models.IntegerField()                           #Runs scored/
> allowed
>     h = models.IntegerField()                           #Hits/hits
> allowed
>     doubles = models.IntegerField()                     #Doubles hit/
> allowed
>     triples = models.IntegerField()                     #Triples hit/
> allowed
>     hr = models.IntegerField()                          #Home Runs hit/
> allowed
>     rbi = models.IntegerField()                         #Runs Batted
> In
>     sb = models.IntegerField()                          #Stolen Bases
>     cs = models.IntegerField()                          #Caught
> Stealing
>     bb = models.IntegerField()                          #Bases on
> Balls/Walks
>     so = models.IntegerField()                          #Strikeouts
>     ba = models.IntegerField()                          #Hits/At bats
>     obp = models.IntegerField()                         #On Base
> Percentage (H + BB + HBP)/(AB + BB + HBP + SF)
>     slg = models.IntegerField()                         #Slugging,
> Total Bases/At Bats (1B + 2 * 2B + 3 * 3B + 4 * HR)/AB
>     ops = models.IntegerField()                         #On base +
> Slugging Percentages
>     opsplus = models.IntegerField()                     #100*[OBP/lg
> OBP + SLG/lg SLG -1]
>     tb = models.IntegerField()                          #Total Bases
>     gdp = models.IntegerField()                         #Double Plays
> Grounded Into
>     hbp = models.IntegerField()                         #Times Hit by
> a Pitch
>     sh = models.IntegerField()                          #Sacrifice
> Hits/Bunts
>     sf = models.IntegerField()                          #Sacrifice
> Flies
>     ibb = models.IntegerField()                         #Intentional
> Bases on Balls
>     pos = models.CharField(max_length=15)               #Positions
>
>     def __unicode__(self):
>         return "Stats"
> 
>
> As you can see I have 4 classes defined:
>  - player
>  - game
>  - statistic
>  - season
>
> A 

Baseball statistics

2010-01-03 Thread Tijmen
Hi there,

First of all let me say I'm just starting here but need some help with
a rather basic question.

I want to make an app that holds baseball statistics for players of
each game and over several seasons. Now I'm new to this db
relationship thing and would like to hear your opinion.

My models.py currently looks like this:


from django.db import models

# Create your models here.
class Player(models.Model):
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)

BATS_CHOICES = (
('R', 'Right'),
('L', 'Left'),
('B', 'Both'),
)

THROWS_CHOICES = (
('R', 'Right'),
('L', 'Left'),
('B', 'Both'),
)

first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
bats = models.CharField(max_length=1, choices=BATS_CHOICES)
throws = models.CharField(max_length=1, choices=THROWS_CHOICES)
birthdate = models.DateTimeField('birth date')
awards = models.CharField(max_length=200)
height = models.IntegerField()
weight = models.IntegerField()
email = models.CharField(max_length=100)
tel = models.CharField(max_length=50)

def __unicode__(self):
#return self.first_name, self.last_name, self.gender
return self.first_name + " " +  self.last_name

class Game(models.Model):
#players = models.ManyToManyField(Player)   #Player
team = models.CharField(max_length=200) #Team for
which the player plays
league = models.CharField(max_length=200)   #League
opponent = models.CharField(max_length=200) #The opponent
date = models.DateTimeField('date') #Date

def __unicode__(self):
return self.team + " vs " + self.opponent

class Season(models.Model):
year = models.DateTimeField('year')

def __unicode__(self):
return self.year

class Statistic(models.Model):
players = models.ManyToManyField(Player)
games = models.ManyToManyField(Game)
g = models.IntegerField()   #Games played
or pitched
pa = models.IntegerField()  #Plate
appearances estimated using AB + BB + HBP + SF + SH missing catcher
interferences
ab = models.IntegerField()  #At bats
r = models.IntegerField()   #Runs scored/
allowed
h = models.IntegerField()   #Hits/hits
allowed
doubles = models.IntegerField() #Doubles hit/
allowed
triples = models.IntegerField() #Triples hit/
allowed
hr = models.IntegerField()  #Home Runs hit/
allowed
rbi = models.IntegerField() #Runs Batted
In
sb = models.IntegerField()  #Stolen Bases
cs = models.IntegerField()  #Caught
Stealing
bb = models.IntegerField()  #Bases on
Balls/Walks
so = models.IntegerField()  #Strikeouts
ba = models.IntegerField()  #Hits/At bats
obp = models.IntegerField() #On Base
Percentage (H + BB + HBP)/(AB + BB + HBP + SF)
slg = models.IntegerField() #Slugging,
Total Bases/At Bats (1B + 2 * 2B + 3 * 3B + 4 * HR)/AB
ops = models.IntegerField() #On base +
Slugging Percentages
opsplus = models.IntegerField() #100*[OBP/lg
OBP + SLG/lg SLG -1]
tb = models.IntegerField()  #Total Bases
gdp = models.IntegerField() #Double Plays
Grounded Into
hbp = models.IntegerField() #Times Hit by
a Pitch
sh = models.IntegerField()  #Sacrifice
Hits/Bunts
sf = models.IntegerField()  #Sacrifice
Flies
ibb = models.IntegerField() #Intentional
Bases on Balls
pos = models.CharField(max_length=15)   #Positions

def __unicode__(self):
return "Stats"


As you can see I have 4 classes defined:
 - player
 - game
 - statistic
 - season

A game is played with several players, each player has statistics for
this game and a game is part of a season. Now I'm a bit lost in what
kind of relationship I should use. models.ManyToManyField or
models.ForeignKey... And where I should put the statement.

Any help would be greatly appreciated.

Thanks

- Tijmen

--

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.