event scoring
This commit is contained in:
parent
3bf01181ec
commit
f2c168b0c9
@ -31,6 +31,20 @@ class League(models.Model):
|
|||||||
wildcard_picks = models.IntegerField(default=1)
|
wildcard_picks = models.IntegerField(default=1)
|
||||||
oldtimer_picks = models.IntegerField(default=2)
|
oldtimer_picks = models.IntegerField(default=2)
|
||||||
|
|
||||||
|
def score_event(self, event):
|
||||||
|
ppv_bonus = 1 if event.name.lower() not in ('raw', 'smackdown') else 0
|
||||||
|
TeamPoints.objects.filter(match__event=event).delete()
|
||||||
|
for match in event.matches.all():
|
||||||
|
for star, points in match.points().iteritems():
|
||||||
|
try:
|
||||||
|
team = self.teams.get(stars=star)
|
||||||
|
TeamPoints.objects.create(points=points + ppv_bonus,
|
||||||
|
team=team,
|
||||||
|
star_id=star,
|
||||||
|
match=match)
|
||||||
|
except Team.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@ -200,3 +214,13 @@ class MatchTeam(models.Model):
|
|||||||
if self.victorious:
|
if self.victorious:
|
||||||
ret += ' (v)'
|
ret += ' (v)'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
class TeamPoints(models.Model):
|
||||||
|
points = models.IntegerField()
|
||||||
|
team = models.ForeignKey(Team, related_name='points')
|
||||||
|
star = models.ForeignKey(Star)
|
||||||
|
match = models.ForeignKey(Match)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "{0} recieved {1} points for {2}'s performance in {3}".format(
|
||||||
|
self.team, self.points, self.star, self.match)
|
@ -1,6 +1,7 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from .models import Match, Event
|
from django.contrib.auth.models import User
|
||||||
|
from .models import Match, Event, League, Team, TeamPoints
|
||||||
|
|
||||||
class MatchTest(TestCase):
|
class MatchTest(TestCase):
|
||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
@ -195,49 +196,65 @@ class MatchTest(TestCase):
|
|||||||
'cmpunk': 0, 'christian': 0})
|
'cmpunk': 0, 'christian': 0})
|
||||||
|
|
||||||
|
|
||||||
class EventTest(TestCase):
|
|
||||||
|
class LeagueTest(TestCase):
|
||||||
fixtures = ['testdata']
|
fixtures = ['testdata']
|
||||||
|
|
||||||
def test_points(self):
|
def setUp(self):
|
||||||
smackdown = Event.objects.create(name='smackdown', date='2012-01-01')
|
self.user = User.objects.create_user('me', 'test@example.com',
|
||||||
match = Match.objects.create(event=smackdown)
|
'password')
|
||||||
match.add_team('reymysterio')
|
self.user2 = User.objects.create_user('me2', 'test@example.com',
|
||||||
match.add_team('sin-cara')
|
'password')
|
||||||
match.record_win('sin-cara', 'pin')
|
self.league = League.objects.create(name='FOWL')
|
||||||
match = Match.objects.create(event=smackdown)
|
self.teddy = Team.objects.create(name='Team Teddy', login=self.user,
|
||||||
match.add_team('santinomarella', 'mickfoley')
|
league=self.league)
|
||||||
match.add_team('markhenry')
|
self.johnny = Team.objects.create(name='Team Johnny', login=self.user2,
|
||||||
match.record_win('mickfoley', 'pin')
|
league=self.league)
|
||||||
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
|
def test_team_add_star(self):
|
||||||
ppv = Event.objects.create(name='In Your House', date='2012-01-01')
|
self.teddy.add_star(pk='reymysterio')
|
||||||
match = Match.objects.create(event=ppv)
|
self.johnny.add_star(pk='sin-cara')
|
||||||
match.add_team('reymysterio')
|
with self.assertRaises(ValueError):
|
||||||
match.add_team('sin-cara')
|
self.teddy.add_star(pk='reymysterio')
|
||||||
match.record_win('sin-cara', 'pin')
|
with self.assertRaises(ValueError):
|
||||||
match = Match.objects.create(event=ppv)
|
self.johnny.add_star(pk='sin-cara')
|
||||||
match.add_team('santinomarella', 'mickfoley')
|
|
||||||
match.add_team('markhenry')
|
def test_score_event(self):
|
||||||
match.record_win('mickfoley', 'pin')
|
self.teddy.add_star(pk='reymysterio')
|
||||||
match = Match.objects.create(event=ppv, title_at_stake=True)
|
self.teddy.add_star(pk='santinomarella')
|
||||||
match.add_team('codyrhodes', title='ic')
|
self.johnny.add_star(pk='sin-cara')
|
||||||
match.add_team('sin-cara')
|
self.johnny.add_star(pk='markhenry')
|
||||||
match.record_win('sin-cara', 'pin')
|
event = Event.objects.create(name='smackdown', date='2012-01-01')
|
||||||
self.assertEqual(ppv.points(), {'reymysterio': 1,
|
match1 = Match.objects.create(event=event)
|
||||||
'sin-cara': 15,
|
match1.add_team('reymysterio')
|
||||||
'santinomarella': 2,
|
match1.add_team('sin-cara')
|
||||||
'mickfoley': 3,
|
match1.record_win('sin-cara', 'pin')
|
||||||
'markhenry': 1,
|
match2 = Match.objects.create(event=event)
|
||||||
'codyrhodes': 1
|
match2.add_team('santinomarella', 'mickfoley')
|
||||||
})
|
match2.add_team('markhenry')
|
||||||
|
match2.record_win('mickfoley', 'pin')
|
||||||
|
match3 = Match.objects.create(event=event, title_at_stake=True)
|
||||||
|
match3.add_team('codyrhodes', title='ic')
|
||||||
|
match3.add_team('sin-cara')
|
||||||
|
match3.record_win('sin-cara', 'pin')
|
||||||
|
self.league.score_event(event)
|
||||||
|
|
||||||
|
# check TeamPoints objects
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='reymysterio').points, 0)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='santinomarella').points, 1)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match1, star__pk='sin-cara').points, 2)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match3, star__pk='sin-cara').points, 12)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.johnny, star__pk='markhenry').points, 0)
|
||||||
|
for obj in TeamPoints.objects.all():
|
||||||
|
print obj
|
||||||
|
|
||||||
|
# rename the event and rescore
|
||||||
|
event.name = 'Wrestlemania'
|
||||||
|
event.save()
|
||||||
|
self.league.score_event(event)
|
||||||
|
# all should be one higher than before
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='reymysterio').points, 1)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.teddy, star__pk='santinomarella').points, 2)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match1, star__pk='sin-cara').points, 3)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.johnny, match=match3, star__pk='sin-cara').points, 13)
|
||||||
|
self.assertEqual(TeamPoints.objects.get(team=self.johnny, star__pk='markhenry').points, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user