def getUser(self, username): if (username != ""): listOfUser = UserFileManagement().getUsers() user = filter(lambda x: x[0] == username, listOfUser) if (user): return user[0] return None
def addStatisticsFor(self, username, numKills, numDeaths, levelsCompleted, numRestarts, currentLevel, maxLevelAchieved, currNumLives): UserFileManagement().addStatistics(username, numKills, numDeaths, levelsCompleted, numRestarts, currentLevel, maxLevelAchieved, currNumLives)
def addUser(self, username, password): if (username != "" and len(username) < 25 and len(username) > 3): if (self.verifyUsernameUnique(username)): userFileManagement = UserFileManagement().addUser( username, password) return True return False
def getKDROf(self, username): if (username != ""): stats = UserFileManagement().getStatistics() user = filter(lambda x: x[0] == username, stats)[0] if (int(user[2]) == 0): if (int(user[1]) == 0): return 0.0 return float(1000000 * user[1]) return round(float(user[1]) / float(user[2]), 2) return None
def getUsersWithKDR(self, condition, value): def _sorting(x): if (int(x[2]) != 0): return round(float(x[1]) / float(x[2]), 2) elif (x[1] == 0): return float(x[2]) else: # x 1,000,000 to ensure zero deaths come on top return float(x[1]) * 1000000.0 if (self._checkValidCondition(condition)): users = UserFileManagement().getStatistics() return filter(lambda x: condition(_sorting(x), value), users)
def getStatsByKDR(self, inverse): def _sorting(x): if (int(x[2]) != 0): return round(float(x[1]) / float(x[2]), 2) elif (x[1] == 0): return round(float(x[2]), 2) else: # x 1,000,000 to ensure zero deaths come on top return float(x[1]) * 1000000.0 stats = UserFileManagement().getStatistics() sortedStats = sorted(stats, key=lambda x: _sorting(x)) if (inverse == False): return sortedStats[::-1] return sortedStats
def getCurrNumLives(self, username): if (username != ""): stats = UserFileManagement().getStatistics() user = filter(lambda x: x[0] == username, stats)[0] return int(user[7]) return None
def addNumDeathsFor(self, username, numDeaths): UserFileManagement().addStatistics(username, 0, numDeaths, 0, 0, 0, 0, 0)
def getNumRestartsOf(self, username): if (username != ""): stats = UserFileManagement().getStatistics() user = filter(lambda x: x[0] == username, stats)[0] return int(user[4]) return None
def getMaxLevelAchievedOf(self, username): if (username != ""): stats = UserFileManagement().getStatistics() user = filter(lambda x: x[0] == username, stats)[0] return int(user[6]) return None
def removeUser(self, username): if (username != ""): userFileManagement = UserFileManagement().removeUser(username) return True return False
def addLevelsCompletedFor(self, username, levelsCompleted): UserFileManagement().addStatistics(username, 0, 0, levelsCompleted, 0, 0, 0, 0)
def getStatsByMaxLevelAchieved(self, inverse): stats = UserFileManagement().getStatistics() sortedStats = sorted(stats, key=lambda x: int(x[6])) if (inverse == False): return sortedStats[::-1] return sortedStats
def updateCurrentLevelFor(self, username, currentLevel): user = self.getStatsOf(username) UserFileManagement().updateStatistics(username, user[1], user[2], user[3], user[4], currentLevel, user[6], user[7])
def getUsersWithCurrNumLives(self, condition, value): if (self._checkValidCondition(condition)): users = UserFileManagement().getStatistics() return filter(lambda x: condition(int(x[7]), value), users)
def addMap(self, map): if (len(map) == 196): UserFileManagement().addMap(map)
def getStatsByUsername(self, inverse): stats = UserFileManagement().getStatistics() sortedStats = sorted(stats, key=lambda x: x[0].lower()) if (inverse == True): return sortedStats[::-1] return sortedStats
def updateCurrNumLivesFor(self, username, currNumLives): user = self.getStatsOf(username) UserFileManagement().updateStatistics(username, user[1], user[2], user[3], user[4], user[5], user[6], currNumLives)
def updateMaxLevelAchievedFor(self, username, maxLevelAchieved): user = self.getStatsOf(username) UserFileManagement().updateStatistics(username, user[1], user[2], user[3], user[4], user[5], maxLevelAchieved, user[7])
def addNumKillsFor(self, username, numKills): UserFileManagement().addStatistics(username, numKills, 0, 0, 0, 0, 0, 0)
def getStatsByCurrNumLives(self, inverse): stats = UserFileManagement().getStatistics() sortedStats = sorted(stats, key=lambda x: int(x[7])) if (inverse == False): return sortedStats[::-1] return sortedStats
def getUsersWithMaxLevelAchieved(self, condition, value): if (self._checkValidCondition(condition)): users = UserFileManagement().getStatistics() return filter(lambda x: condition(int(x[6]), value), users)
def addNumRestartsFor(self, username, numRestarts): UserFileManagement().addStatistics(username, 0, 0, 0, numRestarts, 0, 0, 0)
def getUsersAlphabetically(self, inverse): listOfUser = UserFileManagement().getUsers() sortedUsers = sorted(listOfUser, key=lambda x: x[0].lower()) if (inverse == True): return sortedUsers[::-1] return sortedUsers
def getMaps(self): return UserFileManagement().getMaps()