def add_events_fitness(self): db = SQLConnection() users = db.get_all_users() category = "fitness" for username in users: if db.is_fitbit_setup(username): pet_name = db.find_pet_of_user(username) xp_change = self.make_score_fitness(username) type1 = 1 wore_fitbit = True if xp_change == None: db.insert_events( username, category, "no_effect", 0, "You did not sleep with your fitbit, so your score was uneffected", type1) wore_fitbit = False if wore_fitbit: db.change_xp(username, xp_change) if xp_change <= -300: message = "You have seriously harmed " + pet_name + " from neglagence yesterday. Make it up to " + pet_name + " by exercising today" pet_status = "sick" elif xp_change <= 100: message = pet_name + " is sad from the lack of exercise yesterday" pet_status = "sick" elif xp_change <= 300: message = pet_name + " got some exercise yesterday, but is still eager to play today " pet_status = "happy" else: message = pet_name + " got plenty of exercise yesterday and as a result he is very happy! +" + str( xp_change) + " xp" pet_status = "happy" print "added" current_xp = db.get_xp(username) db.insert_events(username, category, pet_status, xp_change, message, type1, current_xp)
def make_score_sleep(self): type = "sleep" db = SQLConnection() users = db.get_all_users() for username in users: if db.is_fitbit_setup(username): pet_name = db.find_pet_of_user(username) result = self.get_user_data(username, type) print result result = result['summary']['totalTimeInBed'] db.change_xp(username, result) print result db = SQLConnection() current_xp = db.get_xp(username) if result == 0: db.insert_events( username, "sleep", "home", 0, "You did not sleep with your fitbit, so your score was uneffected", "1", current_xp) elif result <= 400: db.insert_events( username, "sleep", "tired", -250, pet_name + " is tired from the lack of sleep. -250 xp", "1", current_xp) elif result <= 420: db.insert_events( username, "sleep", "tired", -125, pet_name + " is tired from the lack of sleep. -250 xp", "1", current_xp) else: db.insert_events( username, "sleep", "home", 250, pet_name + " feels great today! It must be from getting enough sleep. +250 xp", "1", current_xp)