|
|
@ -10,40 +10,95 @@ class Person(object):
|
|
|
|
def __init__(self, name):
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
self.name = name
|
|
|
|
self.kukPoints = 0
|
|
|
|
self.kukPoints = 0
|
|
|
|
self.kukMealCount = 0
|
|
|
|
|
|
|
|
self.kukServingCount = 0
|
|
|
|
|
|
|
|
self.attendanceRate = 0.5
|
|
|
|
|
|
|
|
self.eatenCount = 0
|
|
|
|
|
|
|
|
people[name] = self
|
|
|
|
people[name] = self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
|
|
def fromFile(self, name, kukPoints):
|
|
|
|
|
|
|
|
person = Person(name)
|
|
|
|
|
|
|
|
self.kukPoints = kukPoints
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def get(name):
|
|
|
|
def get(name):
|
|
|
|
if name not in people:
|
|
|
|
if name not in people:
|
|
|
|
people[name] = Person(name)
|
|
|
|
people[name] = Person(name)
|
|
|
|
return people[name]
|
|
|
|
return people[name]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialized(self):
|
|
|
|
|
|
|
|
return self.__dict__
|
|
|
|
|
|
|
|
|
|
|
|
mealHistory = {}
|
|
|
|
mealHistory = {}
|
|
|
|
midTop = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Meal(object):
|
|
|
|
class Meal(object):
|
|
|
|
global mealHistory
|
|
|
|
global mealHistory
|
|
|
|
def __init__(self, kuk, date):
|
|
|
|
def __init__(self):
|
|
|
|
self.mid = self.getNextMID()
|
|
|
|
self.mid = ''
|
|
|
|
self.kuk = kuk
|
|
|
|
self.kuk = ''
|
|
|
|
self.eaters = []
|
|
|
|
self.eaters = []
|
|
|
|
self.date = date
|
|
|
|
self.date = ''
|
|
|
|
self.meal = "food"
|
|
|
|
self.flavorText = ''
|
|
|
|
mealHistory[self.mid] = self
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
|
|
def fromFile(self, mid, kuk, eaters, date, flavorText):
|
|
|
|
|
|
|
|
meal = Meal()
|
|
|
|
|
|
|
|
meal.mid = mid
|
|
|
|
|
|
|
|
meal.kuk = kuk
|
|
|
|
|
|
|
|
meal.eaters = eaters
|
|
|
|
|
|
|
|
meal.date = date
|
|
|
|
|
|
|
|
meal.flavorText = flavorText
|
|
|
|
|
|
|
|
mealHistory[meal.mid] = meal
|
|
|
|
|
|
|
|
return meal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
|
|
def new(self, date):
|
|
|
|
|
|
|
|
meal = Meal()
|
|
|
|
|
|
|
|
meal.mid = self.getNextMID()
|
|
|
|
|
|
|
|
meal.date = date
|
|
|
|
|
|
|
|
mealHistory[meal.mid] = meal
|
|
|
|
|
|
|
|
return meal
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def getNextMID():
|
|
|
|
def getNextMID():
|
|
|
|
global midTop
|
|
|
|
if len(mealHistory) == 0:
|
|
|
|
midTop += 1
|
|
|
|
return 1
|
|
|
|
return midTop
|
|
|
|
return max(mealHistory.keys())+1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialized(self):
|
|
|
|
|
|
|
|
return self.__dict__
|
|
|
|
|
|
|
|
|
|
|
|
def save():
|
|
|
|
def save():
|
|
|
|
with open(config['mealHistoryFile'], 'w') as outfile:
|
|
|
|
with open(config['mealHistoryFile'], 'w') as outfile:
|
|
|
|
json.dump(mealHistory, outfile)
|
|
|
|
mealListJson = []
|
|
|
|
|
|
|
|
for mid,meal in mealHistory.iteritems():
|
|
|
|
|
|
|
|
mealListJson.append(meal.serialized())
|
|
|
|
|
|
|
|
json.dump(mealListJson, outfile)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(config['peopleFile'], 'w') as outfile:
|
|
|
|
|
|
|
|
peopleJson = []
|
|
|
|
|
|
|
|
for name,person in people.iteritems():
|
|
|
|
|
|
|
|
peopleJson.append(person.serialized())
|
|
|
|
|
|
|
|
json.dump(peopleJson, outfile)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load():
|
|
|
|
|
|
|
|
mealHistory = {}
|
|
|
|
|
|
|
|
people = {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with open(config['mealHistoryFile'], 'r') as infile:
|
|
|
|
|
|
|
|
fileData = json.load(infile)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
print "no meal history file!"
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
for meal in fileData:
|
|
|
|
|
|
|
|
Meal.fromFile(meal['mid'], meal['kuk'], meal['eaters'], meal['date'], meal['flavorText'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with open(config['peopleFile'], 'r') as infile:
|
|
|
|
|
|
|
|
fileData = json.load(infile)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
print "no people file!"
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
for person in fileData:
|
|
|
|
|
|
|
|
Person.fromFile(person['name'], person['kukPoints'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
points = {}
|
|
|
|
points = {}
|
|
|
|
points[3] = 52
|
|
|
|
points[3] = 52
|
|
|
@ -105,6 +160,9 @@ def newDay():
|
|
|
|
cookies.remove(kuk)
|
|
|
|
cookies.remove(kuk)
|
|
|
|
|
|
|
|
|
|
|
|
#kuking and points
|
|
|
|
#kuking and points
|
|
|
|
|
|
|
|
m = Meal.new(day);
|
|
|
|
|
|
|
|
m.kuk = kuk.name
|
|
|
|
|
|
|
|
|
|
|
|
reward = points[n_people]
|
|
|
|
reward = points[n_people]
|
|
|
|
payment = points[n_people] / (n_people-1)
|
|
|
|
payment = points[n_people] / (n_people-1)
|
|
|
|
kuk.kukPoints -= reward
|
|
|
|
kuk.kukPoints -= reward
|
|
|
@ -114,9 +172,7 @@ def newDay():
|
|
|
|
for cookie in cookies:
|
|
|
|
for cookie in cookies:
|
|
|
|
cookie.kukPoints += payment
|
|
|
|
cookie.kukPoints += payment
|
|
|
|
cookie.eatenCount += 1
|
|
|
|
cookie.eatenCount += 1
|
|
|
|
|
|
|
|
m.eaters.append(cookie.name)
|
|
|
|
m = Meal(kuk.name, day);
|
|
|
|
|
|
|
|
m.eaters = "many people"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print ""
|
|
|
|
print ""
|
|
|
@ -138,13 +194,8 @@ if __name__ == '__main__':
|
|
|
|
config['port'] = 5000
|
|
|
|
config['port'] = 5000
|
|
|
|
config['debug'] = True
|
|
|
|
config['debug'] = True
|
|
|
|
config['mealHistoryFile'] = "MealHistory.json"
|
|
|
|
config['mealHistoryFile'] = "MealHistory.json"
|
|
|
|
|
|
|
|
config['peopleFile'] = "People.json"
|
|
|
|
|
|
|
|
|
|
|
|
Person("Mark")
|
|
|
|
|
|
|
|
Person("Davide")
|
|
|
|
Person("Davide")
|
|
|
|
Person("Wille")
|
|
|
|
Person("Marek")
|
|
|
|
Person("Sven")
|
|
|
|
|
|
|
|
Person("David")
|
|
|
|
|
|
|
|
Person("Ahmed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for name, person in people.iteritems():
|
|
|
|
|
|
|
|
person.attendanceRate = 0.2 + random.random() * 0.8
|
|
|
|
|
|
|
|