some team work
This commit is contained in:
parent
f1d309fa93
commit
86d1f452ba
@ -10,6 +10,9 @@ class Star(models.Model):
|
|||||||
division = models.CharField(max_length=100)
|
division = models.CharField(max_length=100)
|
||||||
active = models.BooleanField()
|
active = models.BooleanField()
|
||||||
|
|
||||||
|
def drafted(self, league):
|
||||||
|
return self.teams.filter(league=league).count() >= 1
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@ -40,6 +43,13 @@ class Team(models.Model):
|
|||||||
league = models.ForeignKey(League, related_name='teams')
|
league = models.ForeignKey(League, related_name='teams')
|
||||||
stars = models.ManyToManyField(Star, related_name='teams')
|
stars = models.ManyToManyField(Star, related_name='teams')
|
||||||
|
|
||||||
|
def add_star(self, **kwargs):
|
||||||
|
member = Star.objects.get(**kwargs)
|
||||||
|
if member.drafted(self.league):
|
||||||
|
raise ValueError('cannot add {0}, already drafted in {1}'.format(
|
||||||
|
member, self.league))
|
||||||
|
self.stars.add(member)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@ -53,6 +63,17 @@ class Event(models.Model):
|
|||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
date = models.DateField()
|
date = models.DateField()
|
||||||
|
|
||||||
|
def points(self):
|
||||||
|
total = defaultdict(int)
|
||||||
|
for match in self.matches.all():
|
||||||
|
for star, points in match.points().iteritems():
|
||||||
|
total[star] += points
|
||||||
|
# PPV bonus
|
||||||
|
if self.name.lower() not in ('smackdown', 'raw'):
|
||||||
|
for star in total:
|
||||||
|
total[star] += 1
|
||||||
|
return total
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return '{0} {1}'.format(self.name, self.date)
|
return '{0} {1}'.format(self.name, self.date)
|
||||||
|
|
||||||
@ -84,10 +105,9 @@ class Match(models.Model):
|
|||||||
def record_win(self, star, win_type):
|
def record_win(self, star, win_type):
|
||||||
self.teams.filter(members__pk=star).update(victorious=True)
|
self.teams.filter(members__pk=star).update(victorious=True)
|
||||||
self.win_type = win_type
|
self.win_type = win_type
|
||||||
self.winner__pk = star
|
self.winner_id = star
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
def points(self):
|
def points(self):
|
||||||
points = {}
|
points = {}
|
||||||
winners = None
|
winners = None
|
||||||
@ -129,9 +149,9 @@ class Match(models.Model):
|
|||||||
|
|
||||||
# if multiple people in this match and this person was credited
|
# if multiple people in this match and this person was credited
|
||||||
# w/ win, give them the bonus points
|
# w/ win, give them the bonus points
|
||||||
if allies and w.id == self.winner__pk:
|
if allies and w.id == self.winner_id:
|
||||||
points[w.id] += 1
|
points[w.id] += 1
|
||||||
if w.id == self.winner__pk and self.win_type == 'submission':
|
if w.id == self.winner_id and self.win_type == 'submission':
|
||||||
points[w.id] += 1
|
points[w.id] += 1
|
||||||
|
|
||||||
# look over all titles in this match
|
# look over all titles in this match
|
||||||
|
@ -192,3 +192,52 @@ class MatchTest(TestCase):
|
|||||||
match.record_win('reymysterio', 'pin')
|
match.record_win('reymysterio', 'pin')
|
||||||
self.assertEqual(match.points(), {'codyrhodes': 4, 'reymysterio': 5,
|
self.assertEqual(match.points(), {'codyrhodes': 4, 'reymysterio': 5,
|
||||||
'cmpunk': 0, 'christian': 0})
|
'cmpunk': 0, 'christian': 0})
|
||||||
|
|
||||||
|
|
||||||
|
class EventTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
call_command('loadstars')
|
||||||
|
|
||||||
|
def test_points(self):
|
||||||
|
smackdown = Event.objects.create(name='smackdown', date='2012-01-01')
|
||||||
|
match = Match.objects.create(event=smackdown)
|
||||||
|
match.add_team('reymysterio')
|
||||||
|
match.add_team('sin-cara')
|
||||||
|
match.record_win('sin-cara', 'pin')
|
||||||
|
match = Match.objects.create(event=smackdown)
|
||||||
|
match.add_team('santinomarella', 'mickfoley')
|
||||||
|
match.add_team('markhenry')
|
||||||
|
match.record_win('mickfoley', 'pin')
|
||||||
|
match = Match.objects.create(event=smackdown, title_at_stake=True)
|
||||||
|
match.add_team('codyrhodes', title='ic')
|
||||||
|
match.add_team('sin-cara')
|
||||||
|
match.record_win('sin-cara', 'pin')
|
||||||
|
self.assertEqual(smackdown.points(), {'reymysterio': 0,
|
||||||
|
'sin-cara': 14,
|
||||||
|
'santinomarella': 1,
|
||||||
|
'mickfoley': 2,
|
||||||
|
'markhenry': 0,
|
||||||
|
'codyrhodes': 0
|
||||||
|
})
|
||||||
|
|
||||||
|
# exact same matches on a PPV, +1 to everyone
|
||||||
|
ppv = Event.objects.create(name='In Your House', date='2012-01-01')
|
||||||
|
match = Match.objects.create(event=ppv)
|
||||||
|
match.add_team('reymysterio')
|
||||||
|
match.add_team('sin-cara')
|
||||||
|
match.record_win('sin-cara', 'pin')
|
||||||
|
match = Match.objects.create(event=ppv)
|
||||||
|
match.add_team('santinomarella', 'mickfoley')
|
||||||
|
match.add_team('markhenry')
|
||||||
|
match.record_win('mickfoley', 'pin')
|
||||||
|
match = Match.objects.create(event=ppv, title_at_stake=True)
|
||||||
|
match.add_team('codyrhodes', title='ic')
|
||||||
|
match.add_team('sin-cara')
|
||||||
|
match.record_win('sin-cara', 'pin')
|
||||||
|
self.assertEqual(ppv.points(), {'reymysterio': 1,
|
||||||
|
'sin-cara': 15,
|
||||||
|
'santinomarella': 2,
|
||||||
|
'mickfoley': 3,
|
||||||
|
'markhenry': 1,
|
||||||
|
'codyrhodes': 1
|
||||||
|
})
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from fowl.game.models import League, Star, Team, Event, Match
|
from fowl.game.models import League, Star, Team, Event, Match
|
||||||
|
|
||||||
|
User.objects.all().delete()
|
||||||
|
League.objects.all().delete()
|
||||||
|
Team.objects.all().delete()
|
||||||
|
|
||||||
james = User.objects.create_superuser('james', 'james.p.turk@gmail.com', 'james')
|
james = User.objects.create_superuser('james', 'james.p.turk@gmail.com', 'james')
|
||||||
erin = User.objects.create_user('erin', 'erin.braswell@gmail.com', 'erin')
|
erin = User.objects.create_user('erin', 'erin.braswell@gmail.com', 'erin')
|
||||||
kevin = User.objects.create_user('kevin', 'kevin.wohlgenant@gmail.com', 'kevin')
|
kevin = User.objects.create_user('kevin', 'kevin.wohlgenant@gmail.com', 'kevin')
|
||||||
@ -9,8 +13,20 @@ gm_punk = Team.objects.create(name='GM Punk', login=james, league=league)
|
|||||||
awesome = Team.objects.create(name="I'm AWEsome!", login=kevin, league=league)
|
awesome = Team.objects.create(name="I'm AWEsome!", login=kevin, league=league)
|
||||||
cobra = Team.objects.create(name='COBRA!', login=erin, league=league)
|
cobra = Team.objects.create(name='COBRA!', login=erin, league=league)
|
||||||
|
|
||||||
|
punks = ('cmpunk', 'kane', 'rtruth', 'codyrhodes', 'sin-cara', 'antoniocesaro',
|
||||||
|
'wadebarrett', 'aj', 'bethphoenix')
|
||||||
|
for person in punks:
|
||||||
|
print person
|
||||||
|
gm_punk.add_star(pk=person)
|
||||||
|
|
||||||
wm = Event.objects.create(name='Wrestlemania XXX', date='2013-01-01')
|
awesomes = ('chrisjericho', 'sheamus', 'danielbryan', 'ryback', 'damien-sandow',
|
||||||
m1 = Match.objects.create(event=wm)
|
'kharma', 'kellykelly', 'brodusclay', 'johncena')
|
||||||
m1.add_team('dolphziggler')
|
for person in awesomes:
|
||||||
m1.add_team('randysavage')
|
print person
|
||||||
|
awesome.add_star(pk=person)
|
||||||
|
|
||||||
|
cobras = ('santinomarella', 'dolphziggler', 'kofikingston', 'albertodelrio',
|
||||||
|
'randyorton', 'bigshow', 'christian', 'layla', 'natalya')
|
||||||
|
for person in cobras:
|
||||||
|
print person
|
||||||
|
cobra.add_star(pk=person)
|
Loading…
Reference in New Issue
Block a user