|
|
@ -16,7 +16,7 @@ try:
|
|
|
|
with open (configFileName, 'r') as configFile:
|
|
|
|
with open (configFileName, 'r') as configFile:
|
|
|
|
config = json.load(configFile)
|
|
|
|
config = json.load(configFile)
|
|
|
|
except IOError:
|
|
|
|
except IOError:
|
|
|
|
print "Config file not found! Loading defaults"
|
|
|
|
print("Config file not found! Loading defaults")
|
|
|
|
config = {}
|
|
|
|
config = {}
|
|
|
|
config['ip'] = '0.0.0.0'
|
|
|
|
config['ip'] = '0.0.0.0'
|
|
|
|
config['port'] = 5000
|
|
|
|
config['port'] = 5000
|
|
|
@ -49,7 +49,7 @@ class Person(UserMixin):
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def leaderboard():
|
|
|
|
def leaderboard():
|
|
|
|
leaderboard = []
|
|
|
|
leaderboard = []
|
|
|
|
for name,person in people.iteritems():
|
|
|
|
for name,person in people.items():
|
|
|
|
entry = {}
|
|
|
|
entry = {}
|
|
|
|
entry['name'] = name
|
|
|
|
entry['name'] = name
|
|
|
|
entry['score'] = person.kukPoints
|
|
|
|
entry['score'] = person.kukPoints
|
|
|
@ -98,11 +98,11 @@ class Meal(object):
|
|
|
|
self.accounted = "yes"
|
|
|
|
self.accounted = "yes"
|
|
|
|
eaterCount = len(self.eaters)
|
|
|
|
eaterCount = len(self.eaters)
|
|
|
|
points = config['points'][eaterCount]
|
|
|
|
points = config['points'][eaterCount]
|
|
|
|
print "kuk {} clears {} points".format(self.kuk, points)
|
|
|
|
print("kuk {} clears {} points".format(self.kuk, points))
|
|
|
|
Person.get(self.kuk).kukPoints -= points
|
|
|
|
Person.get(self.kuk).kukPoints -= points
|
|
|
|
for eater in self.eaters:
|
|
|
|
for eater in self.eaters:
|
|
|
|
Person.get(eater).kukPoints += points / eaterCount
|
|
|
|
Person.get(eater).kukPoints += points / eaterCount
|
|
|
|
print "+{} gets {} points ".format(eater, points / eaterCount)
|
|
|
|
print("+{} gets {} points ".format(eater, points / eaterCount))
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def getCurrent():
|
|
|
|
def getCurrent():
|
|
|
@ -120,13 +120,13 @@ class Meal(object):
|
|
|
|
def save():
|
|
|
|
def save():
|
|
|
|
with open(config['mealHistoryFile'], 'w') as outfile:
|
|
|
|
with open(config['mealHistoryFile'], 'w') as outfile:
|
|
|
|
mealListJson = []
|
|
|
|
mealListJson = []
|
|
|
|
for mid,meal in mealHistory.iteritems():
|
|
|
|
for mid,meal in mealHistory.items():
|
|
|
|
mealListJson.append(meal.serialized())
|
|
|
|
mealListJson.append(meal.serialized())
|
|
|
|
json.dump(mealListJson, outfile)
|
|
|
|
json.dump(mealListJson, outfile)
|
|
|
|
|
|
|
|
|
|
|
|
with open(config['peopleFile'], 'w') as outfile:
|
|
|
|
with open(config['peopleFile'], 'w') as outfile:
|
|
|
|
peopleJson = []
|
|
|
|
peopleJson = []
|
|
|
|
for name,person in people.iteritems():
|
|
|
|
for name,person in people.items():
|
|
|
|
peopleJson.append(person.serialized())
|
|
|
|
peopleJson.append(person.serialized())
|
|
|
|
json.dump(peopleJson, outfile)
|
|
|
|
json.dump(peopleJson, outfile)
|
|
|
|
|
|
|
|
|
|
|
@ -137,7 +137,7 @@ def load():
|
|
|
|
with open(config['mealHistoryFile'], 'r') as infile:
|
|
|
|
with open(config['mealHistoryFile'], 'r') as infile:
|
|
|
|
fileData = json.load(infile)
|
|
|
|
fileData = json.load(infile)
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
print "no meal history file!"
|
|
|
|
print("no meal history file!")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
for meal in fileData:
|
|
|
|
for meal in fileData:
|
|
|
|
Meal.fromFile(meal['mid'], meal['kuk'], meal['eaters'], meal['date'], meal['flavorText'], meal['accounted'])
|
|
|
|
Meal.fromFile(meal['mid'], meal['kuk'], meal['eaters'], meal['date'], meal['flavorText'], meal['accounted'])
|
|
|
@ -146,7 +146,7 @@ def load():
|
|
|
|
with open(config['peopleFile'], 'r') as infile:
|
|
|
|
with open(config['peopleFile'], 'r') as infile:
|
|
|
|
fileData = json.load(infile)
|
|
|
|
fileData = json.load(infile)
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
print "no people file!"
|
|
|
|
print("no people file!")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
for person in fileData:
|
|
|
|
for person in fileData:
|
|
|
|
Person.fromFile(person['name'], person['kukPoints'], person['password'])
|
|
|
|
Person.fromFile(person['name'], person['kukPoints'], person['password'])
|
|
|
@ -176,21 +176,21 @@ def index():
|
|
|
|
leaderboard.sort(key=lambda tup : tup['score'], reverse = True)
|
|
|
|
leaderboard.sort(key=lambda tup : tup['score'], reverse = True)
|
|
|
|
leaders = [p['name'] for p in leaderboard if p['score'] == leaderboard[0]['score']]
|
|
|
|
leaders = [p['name'] for p in leaderboard if p['score'] == leaderboard[0]['score']]
|
|
|
|
if len(leaders) > 1:
|
|
|
|
if len(leaders) > 1:
|
|
|
|
print "tie breaking!"
|
|
|
|
print("tie breaking!")
|
|
|
|
mid = Meal.getCurrent().mid-1
|
|
|
|
mid = Meal.getCurrent().mid-1
|
|
|
|
while len(leaders)>1:
|
|
|
|
while len(leaders)>1:
|
|
|
|
thatkuk = mealHistory[mid].kuk
|
|
|
|
thatkuk = mealHistory[mid].kuk
|
|
|
|
print "meal " + str(mid)
|
|
|
|
print("meal " + str(mid))
|
|
|
|
print thatkuk + " cooked that time"
|
|
|
|
print(thatkuk + " cooked that time")
|
|
|
|
if thatkuk in leaders:
|
|
|
|
if thatkuk in leaders:
|
|
|
|
print "found one!"
|
|
|
|
print("found one!")
|
|
|
|
leaders.remove(thatkuk)
|
|
|
|
leaders.remove(thatkuk)
|
|
|
|
mid-=1
|
|
|
|
mid-=1
|
|
|
|
if mid == 0:
|
|
|
|
if mid == 0:
|
|
|
|
leaders.sort()
|
|
|
|
leaders.sort()
|
|
|
|
print "beaking!"
|
|
|
|
print("beaking!")
|
|
|
|
break
|
|
|
|
break
|
|
|
|
print str(len(leaders)) + " remaining"
|
|
|
|
print(str(len(leaders)) + " remaining")
|
|
|
|
cook['name'] = leaders[0]
|
|
|
|
cook['name'] = leaders[0]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
cook['name'] = leaders[0]
|
|
|
|
cook['name'] = leaders[0]
|
|
|
@ -208,7 +208,7 @@ def login():
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
|
username = request.form['username']
|
|
|
|
username = request.form['username']
|
|
|
|
password = request.form['password']
|
|
|
|
password = request.form['password']
|
|
|
|
print len(people)
|
|
|
|
print(len(people))
|
|
|
|
if Person.get(username).password == password:
|
|
|
|
if Person.get(username).password == password:
|
|
|
|
login_user(Person.get(username))
|
|
|
|
login_user(Person.get(username))
|
|
|
|
return redirect(request.args.get("next"))
|
|
|
|
return redirect(request.args.get("next"))
|
|
|
|