Created
November 8, 2013 04:42
-
-
Save egibney/7366366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A function for recording a new game | |
def newgame(request): | |
if request.method == 'POST': | |
form = GameForm(request.POST) | |
if form.is_valid(): | |
player1 = form.cleaned_data['player1'] | |
player2 = form.cleaned_data['player2'] | |
player3 = form.cleaned_data['player3'] | |
player4 = form.cleaned_data['player4'] | |
score1 = form.cleaned_data['score1'] | |
score2 = form.cleaned_data['score2'] | |
form.save() | |
p1 = Player | |
p1.calculateStats(player1) | |
p2 = Player | |
p2.calculateStats(player2) | |
p3 = Player | |
p3.calculateStats(player3) | |
p4 = Player | |
p4.calculateStats(player4) | |
return HttpResponseRedirect('/') | |
else: | |
form = GameForm | |
return render(request, 'scorekeeper/newgame.html', { | |
'form': form, | |
}) | |
render_to_response('scorekeeper/newgame.html', | |
context_instance=RequestContext(request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculateWins(self): | |
count = 0 | |
all_games = Game.objects.all() | |
for game in all_games: | |
if ( game.player1 or game.player2 == self): | |
if ( game.score1 > game.score2 ): | |
count += 1 | |
elif ( game.player3 or game.player4 == self): | |
if ( game.score2 > game.score1 ): | |
count+=1 | |
self.wins = count | |
self.save() | |
def calculateLosses(self): | |
count = 0 | |
all_games = Game.objects.all() | |
for game in all_games: | |
if ( game.player1 or game.player2 == self): | |
if ( game.score1 < game.score2 ): | |
count += 1 | |
elif ( game.player3 or game.player4 == self): | |
if ( game.score2 < game.score1 ): | |
count+=1 | |
self.losses = count | |
self.save() | |
def calclatePoints(self): | |
count = 0 | |
all_games = Game.objects.all() | |
for game in all_games: | |
if ( game.player1 or game.player2 == self): | |
if ( game.score1 > game.score2 ): | |
count += 1 | |
elif (game.score1 < game.score2 ): | |
count -= 1 | |
elif ( game.player3 or game.player4 == self): | |
if ( game.score2 > game.score1 ): | |
count += 1 | |
elif ( game.score2 < game.score1 ): | |
count -= 1 | |
self.points = count | |
self.save() | |
def calculateGamesPlayed(self): | |
count = 0 | |
all_games = Game.objects.all() | |
for game in all_games: | |
if ( game.player1 or game.player2 or game.player3 or game.player4 == self): | |
count += 1 | |
self.games = count | |
self.save() | |
def calculateGoalsFor(self): | |
count = 0 | |
all_games = Game.objects.all() | |
for game in all_games: | |
if (game.player1 or game.player2 == self): | |
count += game.score1 | |
elif (game.player3 or game.player4 == self): | |
count += game.score2 | |
self.goalsfor = count | |
self.save() | |
def calculateGoalsAgainst(self): | |
count = 0 | |
all_games = Game.objects.all() | |
for game in all_games: | |
if (game.player1 or game.player2 == self): | |
count += game.score2 | |
elif (game.player3 or game.player4 == self): | |
count += game.score1 | |
self.goalsagainst = count | |
self.save() | |
def calculateStats(self): | |
self.calculateWins() | |
self.calculateLosses() | |
self.calclatePoints() | |
self.calculateGamesPlayed() | |
self.calculateGoalsFor() | |
self.calculateGoalsAgainst() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment