picking the kuk for real this time

master
Marek Baczynski 7 years ago
parent 92d45841f3
commit 240a2e3b08

@ -163,8 +163,20 @@ def index():
meal = Meal.getCurrent() meal = Meal.getCurrent()
if meal.accounted == 'no': if meal.accounted == 'no':
cook = {} cook = {}
if meal.kuk[-1] == '?': #no kuk confirmed if meal.kuk == '': #no kuk confirmed
cook['name'] = meal.kuk[:-1] leaderboard = []
for eater in meal.eaters:
candidate = {}
candidate['name'] = eater
candidate['score'] = Person.get(eater).kukPoints
leaderboard.append(candidate)
leaderboard.sort(key=lambda tup : tup['score'], reverse = True)
leaders = [p for p in leaderboard if p['score'] == leaderboard[0]['score']]
if len(leaders) > 1:
print "tie breaking!"
cook['name'] = leaders[0]['name']
else:
cook['name'] = leaders[0]['name']
cook['confirmed'] = 'no' cook['confirmed'] = 'no'
else: else:
cook['name'] = meal.kuk cook['name'] = meal.kuk
@ -222,7 +234,7 @@ def removeme():
@login_required @login_required
def volunteer(): def volunteer():
meal = Meal.getCurrent() meal = Meal.getCurrent()
if meal.kuk[-1] == '?': if meal.kuk == '':
meal.kuk = current_user.name meal.kuk = current_user.name
save() save()
return '<p>we commend you for your bravery!</p>' return '<p>we commend you for your bravery!</p>'
@ -243,9 +255,9 @@ def finish():
@login_required @login_required
def plan(): def plan():
meal = Meal.new('someday') meal = Meal.new('someday')
leaderboard = Person.leaderboard() # leaderboard = Person.leaderboard()
leaders = [p for p in leaderboard if p['score'] == leaderboard[0]['score']] # leaders = [p for p in leaderboard if p['score'] == leaderboard[0]['score']]
meal.kuk = random.choice(leaders)['name'] + '?' # meal.kuk = random.choice(leaders)['name'] + '?'
save() save()
return '<p>meal waiting!</p>' return '<p>meal waiting!</p>'

Loading…
Cancel
Save