switch win_type to outcome, add brawls and appearances

This commit is contained in:
James Turk 2012-05-27 23:49:30 -04:00
parent 956c7694d9
commit b3707c0386
3 changed files with 89 additions and 83 deletions

View File

@ -4,8 +4,9 @@ from django.contrib.auth.models import User
# these things are independent of the game
WIN_TYPES = (
('pin', 'pin'),
OUTCOMES = (
('no contest', 'no contest'),
('normal', 'normal'),
('DQ', 'DQ'),
('submission', 'submission'),
('appearance', 'appearance'),
@ -48,7 +49,7 @@ class Event(models.Model):
def add_match(self, *teams, **kwargs):
winner = kwargs.get('winner', None)
win_type = kwargs.get('win_type', '')
outcome = kwargs.get('outcome', '')
title_at_stake = kwargs.get('title_at_stake', False)
notes = kwargs.get('notes', '')
@ -71,9 +72,9 @@ class Event(models.Model):
mt.save()
mt.members.add(member)
if winner:
match.record_win(winner, win_type)
match.record_win(winner, outcome)
else:
match.win_type = win_type
match.outcome = outcome
match.save()
return match
@ -84,16 +85,16 @@ class Event(models.Model):
class Match(models.Model):
event = models.ForeignKey(Event, related_name='matches')
winner = models.ForeignKey(Star, null=True)
win_type = models.CharField(max_length=10, choices=WIN_TYPES)
outcome = models.CharField(max_length=10, choices=OUTCOMES)
title_at_stake = models.BooleanField(default=False)
notes = models.TextField(blank=True, default='')
def record_win(self, star, win_type):
def record_win(self, star, outcome):
team = self.teams.get(members__pk=star)
team.victorious = True
team.save()
self.winner_id = star
self.win_type = win_type
self.outcome = outcome
self.save()
def points(self):
@ -105,9 +106,9 @@ class Match(models.Model):
for team in self.teams.all():
for star in team.members.all():
points[star.id] = 0
if self.win_type == 'appearance' and not star.active:
if self.outcome == 'appearance' and not star.active:
points[star.id] += 10
if self.win_type == 'brawl':
if self.outcome == 'brawl':
points[star.id] += 2
if team.title:
title_teams[team.title] = team
@ -118,7 +119,7 @@ class Match(models.Model):
team_count += 1
# don't worry about winners of appearances or brawls
if self.win_type in ('appearance', 'brawl'):
if self.outcome in ('appearance', 'brawl'):
return points
if winners:
@ -127,7 +128,7 @@ class Match(models.Model):
# figure out base points for winning
# DQ wins are worth 1 point no matter what
if self.win_type == 'DQ':
if self.outcome == 'DQ':
base_points = 1
allies = 0 # allies don't matter in a DQ
# rumble is worth participants/2
@ -147,7 +148,7 @@ class Match(models.Model):
# w/ win, give them the bonus points
if allies and w.id == self.winner_id:
points[w.id] += 1
if w.id == self.winner_id and self.win_type == 'submission':
if w.id == self.winner_id and self.outcome == 'submission':
points[w.id] += 1
# look over all titles in this match
@ -161,13 +162,13 @@ class Match(models.Model):
# beat someone w/ title
elif winners.title != title:
# title win
if self.title_at_stake and self.win_type != 'DQ':
if self.title_at_stake and self.outcome != 'DQ':
if title in ('heavyweight', 'wwe'):
points[w.id] += 20
else:
points[w.id] += 10
# title team gets a point if they defend title by DQ
elif self.title_at_stake and self.win_type == 'DQ':
elif self.title_at_stake and self.outcome == 'DQ':
for star in title_team.members.all():
points[star.id] += 1
# beat tag champs in tag match w/o tag belt on line

View File

@ -42,56 +42,56 @@ class MatchTest(TestCase):
match = self.event.add_match('tripleh', 'undertaker')
self.assertEqual(unicode(match),
'Triple H vs. Undertaker (no contest)')
match.record_win('undertaker', 'pin')
match.record_win('undertaker', 'normal')
self.assertEqual(unicode(match), 'Triple H vs. Undertaker (v)')
_give_belt('cmpunk', 'wwe')
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
win_type='pin')
outcome='normal')
self.assertEqual(unicode(match), 'CM Punk (c) (v) vs. Rey Mysterio')
def test_scoring(self):
# one on one : 2 points
match = self.event.add_match('tripleh', 'undertaker',
winner='undertaker', win_type='pin')
winner='undertaker', outcome='normal')
self.assertEqual(match.points(), {'undertaker': 2, 'tripleh': 0})
# fatal 4 way: 6 points
match = self.event.add_match('randyorton', 'sheamus', 'albertodelrio',
'chrisjericho', winner='sheamus',
win_type='pin')
outcome='normal')
self.assertEqual(match.points(), {'sheamus': 6, 'randyorton': 0,
'albertodelrio': 0, 'chrisjericho': 0}
)
# win stacked match: 1 point for team (bonuses can apply)
match = self.event.add_match('santinomarella', ['markhenry', 'kane'],
winner='markhenry', win_type='pin')
winner='markhenry', outcome='normal')
self.assertEqual(match.points(), {'markhenry': 2, 'kane': 1,
'santinomarella': 0})
# DQ : 1 point
match = self.event.add_match('kane', 'undertaker', winner='undertaker',
win_type='DQ')
outcome='DQ')
self.assertEqual(match.points(), {'undertaker': 1, 'kane': 0})
# submission: +1
match = self.event.add_match('danielbryan', 'cmpunk',
winner='danielbryan',
win_type='submission')
outcome='submission')
self.assertEqual(match.points(), {'danielbryan': 3, 'cmpunk': 0})
# complicated one, outnumbered + submission
match = self.event.add_match('cmpunk', ['danielbryan', 'chrisjericho'],
winner='cmpunk', win_type='submission')
winner='cmpunk', outcome='submission')
self.assertEqual(match.points(), {'cmpunk': 5, 'chrisjericho': 0,
'danielbryan': 0})
# tag team: 2 points, +1 for the person who made pin
match = self.event.add_match(['kofikingston', 'rtruth'],
['jackswagger', 'dolphziggler'],
winner='dolphziggler', win_type='pin')
winner='dolphziggler', outcome='normal')
self.assertEqual(match.points(), {'jackswagger': 2,
'dolphziggler': 3,
'kofikingston': 0,
@ -101,7 +101,7 @@ class MatchTest(TestCase):
match = self.event.add_match(['kofikingston', 'rtruth'],
['jackswagger', 'dolphziggler'],
winner='dolphziggler',
win_type='submission')
outcome='submission')
self.assertEqual(match.points(), {'jackswagger': 2,
'dolphziggler': 4,
'kofikingston': 0,
@ -111,7 +111,7 @@ class MatchTest(TestCase):
match = self.event.add_match(['kofikingston', 'rtruth'],
['jackswagger', 'dolphziggler'],
winner='dolphziggler',
win_type='DQ')
outcome='DQ')
self.assertEqual(match.points(), {'jackswagger': 1,
'dolphziggler': 1,
'kofikingston': 0,
@ -122,7 +122,7 @@ class MatchTest(TestCase):
'dolphziggler', 'johncena', 'jackswagger',
'kharma', 'kane', 'albertodelrio',
'christian', winner='christian',
win_type='pin')
outcome='normal')
self.assertEqual(match.points(), {'christian': 5,
'kofikingston': 0,
'rtruth': 0,
@ -138,17 +138,17 @@ class MatchTest(TestCase):
def test_appearance_scoring(self):
# normal appearance worth 0 points
match = self.event.add_match('cmpunk', 'kofikingston',
win_type='appearance')
outcome='appearance')
self.assertEqual(match.points(), {'cmpunk': 0, 'kofikingston': 0})
# appearance of old timer, 10 points
match = self.event.add_match('brock-lesnar', win_type='appearance')
match = self.event.add_match('brock-lesnar', outcome='appearance')
self.assertEqual(match.points(), {'brock-lesnar': 10})
def test_brawl_scoring(self):
# brawls worth 2 points for all involved
match = self.event.add_match(['cmpunk', 'aj'], 'danielbryan',
win_type='brawl')
outcome='brawl')
self.assertEqual(match.points(), {'cmpunk': 2, 'aj': 2,
'danielbryan': 2})
@ -160,61 +160,61 @@ class MatchTest(TestCase):
# champ doesn't get a bonus just for winning
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
win_type='pin')
outcome='normal')
self.assertEqual(match.points(), {'cmpunk': 2, 'reymysterio': 0})
# +2 bonus for beating a champ in a non-title match
match = self.event.add_match('cmpunk', 'reymysterio',
winner='reymysterio', win_type='pin')
winner='reymysterio', outcome='normal')
self.assertEqual(match.points(), {'cmpunk': 0, 'reymysterio': 4})
# defending wwe belt is worth +5
match = self.event.add_match('cmpunk', 'reymysterio', winner='cmpunk',
win_type='pin', title_at_stake=True)
outcome='normal', title_at_stake=True)
self.assertEqual(match.points(), {'cmpunk': 7, 'reymysterio': 0})
# winning wwe belt
match = self.event.add_match('cmpunk', 'reymysterio',
winner='reymysterio', win_type='pin',
winner='reymysterio', outcome='normal',
title_at_stake=True)
self.assertEqual(match.points(), {'reymysterio': 22, 'cmpunk': 0})
# defending other belt is worth +3
match = self.event.add_match('christian', 'codyrhodes',
winner='christian', win_type='pin',
winner='christian', outcome='normal',
title_at_stake=True)
self.assertEqual(match.points(), {'christian': 5, 'codyrhodes': 0})
# winning other belt is worth +10
match = self.event.add_match('christian', 'codyrhodes',
winner='codyrhodes', win_type='pin',
winner='codyrhodes', outcome='normal',
title_at_stake=True)
self.assertEqual(match.points(), {'codyrhodes': 12, 'christian': 0})
# title non-defense (DQ/countout)
match = self.event.add_match('christian', 'codyrhodes',
winner='codyrhodes', win_type='DQ',
winner='codyrhodes', outcome='DQ',
title_at_stake=True)
self.assertEqual(match.points(), {'codyrhodes': 1, 'christian': 1})
# no bonus in a tag match
match = self.event.add_match(['cmpunk', 'christian'],
['reymysterio', 'codyrhodes'],
winner='reymysterio', win_type='pin')
winner='reymysterio', outcome='normal')
self.assertEqual(match.points(), {'codyrhodes': 2, 'reymysterio': 3,
'cmpunk': 0, 'christian': 0})
# ...unless it is the tag title
match = self.event.add_match(['kofikingston', 'rtruth'],
['reymysterio', 'sin-cara'],
winner='reymysterio', win_type='pin')
winner='reymysterio', outcome='normal')
self.assertEqual(match.points(), {'sin-cara': 4, 'reymysterio': 5,
'kofikingston': 0, 'rtruth': 0})
# test tag title changing hands
match = self.event.add_match(['kofikingston', 'rtruth'],
['reymysterio', 'sin-cara'],
winner='reymysterio', win_type='pin',
winner='reymysterio', outcome='normal',
title_at_stake=True)
self.assertEqual(match.points(), {'sin-cara': 12, 'reymysterio': 13,
'kofikingston': 0, 'rtruth': 0})
@ -249,12 +249,12 @@ class LeagueTest(TestCase):
self.johnny.add_star(pk='markhenry')
event = Event.objects.create(name='smackdown', date='2012-01-01')
match1 = event.add_match('reymysterio', 'sin-cara', winner='sin-cara',
win_type='pin')
outcome='normal')
match2 = event.add_match('markhenry', ['santinomarella', 'mickfoley'],
winner='mickfoley', win_type='pin')
winner='mickfoley', outcome='normal')
_give_belt('codyrhodes', 'ic')
match3 = event.add_match('sin-cara', 'codyrhodes', title_at_stake=True,
winner='sin-cara', win_type='pin')
winner='sin-cara', outcome='normal')
self.league.score_event(event)
# check TeamPoints objects

View File

@ -23,92 +23,97 @@ gm_punk = Team.objects.create(name='GM Punk', login=james, league=league)
awesome = Team.objects.create(name="I'm AWEsome!", login=kevin, league=league)
cobra = Team.objects.create(name='COBRA!', login=erin, league=league)
punks = ('cmpunk', 'markhenry', 'rtruth', 'codyrhodes', 'tensai', 'antoniocesaro',
'wadebarrett', 'aj', 'bethphoenix')
punks = ('cmpunk', 'markhenry', 'rtruth', 'codyrhodes',
'tensai', 'antoniocesaro', 'wadebarrett', 'aj', 'bethphoenix',
'brock-lesnar', 'mickfoley')
for person in punks:
gm_punk.add_star(pk=person)
awesomes = ('chrisjericho', 'sheamus', 'danielbryan', 'ryback', 'damien-sandow',
'kharma', 'kellykelly', 'brodusclay', 'johncena')
'kharma', 'kellykelly', 'brodusclay', 'johncena',
'paulheyman', 'paulbearer')
for person in awesomes:
awesome.add_star(pk=person)
cobras = ('santinomarella', 'dolphziggler', 'kofikingston', 'albertodelrio',
'randyorton', 'bigshow', 'titusoneil', 'layla', 'natalya')
'randyorton', 'bigshow', 'titusoneil', 'layla', 'natalya',
'edge', 'jimross')
for person in cobras:
cobra.add_star(pk=person)
# RAW 5/14
event = Event.objects.create(name='RAW', date='2012-05-14')
event.add_match(['cmpunk', 'santinomarella'], ['codyrhodes', 'danielbryan'],
winner='cmpunk', win_type='pin')
winner='cmpunk', outcome='normal')
event.add_match('aliciafox', 'bethphoenix', winner='bethphoenix',
win_type='pin')
event.add_match('bigshow', 'kane', winner='kane', win_type='pin')
outcome='normal')
event.add_match('bigshow', 'kane', winner='kane', outcome='normal')
event.add_match(['brodusclay', 'kofikingston', 'rtruth'],
['themiz', 'jackswagger', 'dolphziggler'],
winner='brodusclay', win_type='pin')
winner='brodusclay', outcome='normal')
event.add_match('chrisjericho', 'randyorton',
winner='chrisjericho', win_type='DQ',
note='Sheamus interfered, giving Jericho the win')
# MISSING heyman's appearance
winner='chrisjericho', outcome='DQ',
notes='Sheamus interfered, giving Jericho the win')
event.add_match('paulheyman', outcome='appearance',
notes='Paul Heyman is going to sue for Bork Laser')
league.score_event(event)
# Smackdown 5/18
event = Event.objects.create(name='Smackdown', date='2012-05-18')
event.add_match(['kofikingston', 'rtruth'], ['darrenyoung', 'titusoneil'],
winner='rtruth', win_type='pin')
event.add_match('damien-sandow', 'yoshitatsu', notes='sandow refuses to fight')
winner='rtruth', outcome='normal')
event.add_match('damien-sandow', 'yoshitatsu',
outcome='brawl',
notes='sandow refuses to fight, leads to a brawl')
event.add_match('zackryder', 'danielbryan', winner='danielbryan',
win_type='submission')
event.add_match('cmpunk', 'kane', winner='kane', win_type='dq',
outcome='submission')
event.add_match('cmpunk', 'kane', winner='kane', outcome='dq',
notes='bryan hits kane with a chair, kane wins by DQ')
event.add_match('santinomarella', 'codyrhodes', winner='santinomarella',
win_type='pin')
event.add_match('randyorton', 'sheamus', winner='sheamus', win_type='pin')
# MISSING sandow brawl points
outcome='normal')
event.add_match('randyorton', 'sheamus', winner='sheamus', outcome='normal')
league.score_event(event)
# Over the Limit 5/20
event = Event.objects.create(name='Over the Limit', date='2012-05-20')
event.add_match('zackryder', 'kane', winner='kane', win_type='pin')
event.add_match('zackryder', 'kane', winner='kane', outcome='normal')
event.add_match('alexriley', 'christian', 'curthawkins', 'darrenyoung',
'davidotunga', 'drewmcintyre', 'ezekieljackson',
'thegreatkhali', 'heathslater', 'jeyuso', 'jimmyuso', 'jindermahal',
'jtg', 'michaelmcgillicutty', 'themiz', 'titusoneil',
'tylerreks', 'tysonkidd', 'williamregal', 'yoshitatsu',
winner='christian', win_type='pin')
winner='christian', outcome='normal')
event.add_match(['kofikingston', 'rtruth'], ['dolphziggler', 'jackswagger'],
winner='kofikingston', win_type='pin', title_at_stake=True)
winner='kofikingston', outcome='normal', title_at_stake=True)
event.add_match('layla', 'bethphoenix', winner='layla',
win_type='pin', title_at_stake=True)
outcome='normal', title_at_stake=True)
event.add_match('sheamus', 'randyorton', 'chrisjericho', 'albertodelrio',
winner='sheamus', win_type='pin', title_at_stake=True)
event.add_match('brodusclay', 'themiz', winner='brodusclay', win_type='pin')
event.add_match('christian', 'codyrhodes', winner='christian', win_type='pin',
winner='sheamus', outcome='normal', title_at_stake=True)
event.add_match('brodusclay', 'themiz', winner='brodusclay', outcome='normal')
event.add_match('christian', 'codyrhodes', winner='christian', outcome='normal',
title_at_stake=True)
_give_belt('christian', 'ic')
event.add_match('cmpunk', 'danielbryan', winner='cmpunk', win_type='pin',
event.add_match('cmpunk', 'danielbryan', winner='cmpunk', outcome='normal',
title_at_stake=True)
event.add_match('ryback', 'camacho', winner='ryback', win_type='pin')
event.add_match('ryback', 'camacho', winner='ryback', outcome='normal')
event.add_match('john-laurinaitis', 'johncena', 'bigshow',
winner='john-laurinaitis',
win_type='pin', notes='Big Show interferes in a big way')
outcome='normal', notes='Big Show interferes in a big way')
league.score_event(event)
# 5/21 RAW
event = Event.objects.create(name='RAW', date='2012-05-21')
event.add_match('davidotunga', 'johncena', winner='johncena',
win_type='submission')
outcome='submission')
# Brawl: Tyler Reks & Curt Hawkins & Titus O'Neil & Daren Young & Sheamus
# Brawl: Santino vs. Ricardo
event.add_match('albertodelrio', 'randyorton', winner='randyorton',
win_type='DQ', notes='Jericho codebreaks RKO, Orton wins')
event.add_match('danielbryan', 'kane', winner='danielbryan', win_type='DQ',
outcome='DQ', notes='Jericho codebreaks RKO, Orton wins')
event.add_match('danielbryan', 'kane', winner='danielbryan', outcome='DQ',
notes='Kane uses chair, Bryan wins')
event.add_match('christian', 'jindermahal', winner='christian', win_type='pin')
event.add_match('christian', 'jindermahal', winner='christian', outcome='normal')
event.add_match('bethphoenix', 'kellykelly', winner='bethphoenix',
win_type='pin')
outcome='normal')
event.add_match(['johncena', 'sheamus'],
['tensai', 'jackswagger', 'dolphziggler'],
notes='Lumberjacks rush ring, no contest')
@ -126,23 +131,23 @@ gm_punk.add_star('kane')
# 5/25 Smackdown
event = Event.objects.create(name='Smackdown', date='2012-05-25')
event.add_match('christian', 'hunico', winner='christian',
win_type='pin')
outcome='normal')
event.add_match(['titusoneil', 'darrenyoung'],
['jimmyuso', 'jeyuso'],
winner='titusoneil', win_type='pin')
winner='titusoneil', outcome='normal')
Star.objects.create(name='Nobody One', pk='nobody1')
Star.objects.create(name='Nobody Two', pk='nobody2')
event.add_match('ryback',
['nobody1', 'nobody2'], winner='ryback',
win_type='pin')
outcome='normal')
event.add_match('santinomarella', 'ricardorodriguez',
winner='santinomarella', win_type='pin')
winner='santinomarella', outcome='normal')
event.add_match('sheamus', 'jackswagger', winner='sheamus',
win_type='pin')
outcome='normal')
event.add_match('damien-sandow', 'yoshitatsu',
winner='damien-sandow', win_type='pin')
winner='damien-sandow', outcome='normal')
# daniel bryan vs kane brawl
event.add_match('randyorton', 'kane', 'albertodelrio',
winner='albertodelrio', win_type='pin')
winner='albertodelrio', outcome='normal')
league.score_event(event)