From 240a2e3b08b62825720bda5ea56bb6e071dfdc16 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Sun, 22 Oct 2017 21:37:09 +0200 Subject: [PATCH] picking the kuk for real this time --- kuk.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/kuk.py b/kuk.py index 66f4f66..6b05cdd 100644 --- a/kuk.py +++ b/kuk.py @@ -163,8 +163,20 @@ def index(): meal = Meal.getCurrent() if meal.accounted == 'no': cook = {} - if meal.kuk[-1] == '?': #no kuk confirmed - cook['name'] = meal.kuk[:-1] + if meal.kuk == '': #no kuk confirmed + 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' else: cook['name'] = meal.kuk @@ -222,7 +234,7 @@ def removeme(): @login_required def volunteer(): meal = Meal.getCurrent() - if meal.kuk[-1] == '?': + if meal.kuk == '': meal.kuk = current_user.name save() return '

we commend you for your bravery!

' @@ -243,9 +255,9 @@ def finish(): @login_required def plan(): meal = Meal.new('someday') - leaderboard = Person.leaderboard() - leaders = [p for p in leaderboard if p['score'] == leaderboard[0]['score']] - meal.kuk = random.choice(leaders)['name'] + '?' + # leaderboard = Person.leaderboard() + # leaders = [p for p in leaderboard if p['score'] == leaderboard[0]['score']] + # meal.kuk = random.choice(leaders)['name'] + '?' save() return '

meal waiting!

'