def getTop(cls, by: str = 'user', limit: int = 10) -> list: if limit == 'max': top = cls.execute( Executor.select("*", f"{by}", order="rating desc")) return top top = cls.execute( Executor.select("*", f"{by}", order="rating desc", limit=limit)) return top
def addMap(cls, beatmap, category='user'): if cls.exist(beatmap): if category == 'np': return cls.pushMap(beatmap) else: # Let's add map to base, but first, we need to calculate some data... # PP Calculation initializaion... beatmap_data = PP_Calculator.PP_Calculator( 'max', beatmap, f_accs=[0.95, 0.98, 0.99, 1], f_miss=[0, 0, 0, 0]) title = f"{beatmap_data[2][0]} [{beatmap_data[2][1]}]" pps = beatmap_data[1] data = beatmap_data[0] # Insert into table cls.execute( Executor.insert(category, ("beatmap", "title", "pp", "rating", "data"), (beatmap, title, str(pps), 1, str(data))))
def exists(cls, user: str) -> bool: try: if cls.execute(Executor.select("*", "user", f"name='{user}'")): return True except: return False return False
def exists(self) -> None: try: if self.execute( Executor.select("name", "lang", f"name='{self.name}'")): return True except: return False return False
def getStat(cls, user: str) -> list: if not (cls.exists(user)): cls.addStat(user) stat = cls.execute(Executor.select("*", "user", f"name='{user}'")) stat = stat[0] return stat
def exist(cls, beatmap: int) -> bool: try: if cls.execute( Executor.select("beatmap", "user", f"beatmap={beatmap}")): return True except: return False return False
def dropMap(cls, beatmap: int) -> None: if cls.exist(beatmap): cls.execute( Executor.update('user', 'rating=rating-1', f"beatmap='{beatmap}'")) return cls.addMap(beatmap) cls.dropMap(beatmap)
def addMapToPushed(cls, user: str, beatmap: int) -> None: if cls.exists(user): pushed = cls.getPushedMaps(user) pushed.append(beatmap) cls.execute(Executor.update("user", f"pushed='{pushed}'")) else: cls.addStat(user) cls.addMapToPushed(user, beatmap)
def getPushedMaps(cls, user: str) -> list: pushed = cls.execute( Executor.select("pushed", "user", f"name='{user}'"))[0][0] if pushed: pushed = eval(pushed) else: pushed = list() return pushed
def addStat(cls, user: str) -> None: if cls.exists(user): return user_data = us.User() user_data.setUser(user) acc = user_data.acc pp = user_data.pp star_avg = user_data.calcAvgStar() now = round(time()) cls.execute( Executor.insert( "user", ("name", "acc", "pp", "star_avg", "pushed", "last_use"), (user, acc, pp, star_avg, '[]', now)))
def dailyUpdate(cls, user: str, debug: bool = False) -> None: now = round(time()) if debug: now = 999999999999999 if round((now - cls.getLastUpdate(user)) / 60 / 60) > 24: user_data = us.User() user_data.setUser(user) acc = user_data.acc pp = user_data.pp star_avg = user_data.calcAvgStar() now = round(time()) cls.execute( Executor.update( "user", f"acc={acc}, pp={pp}, star_avg={star_avg}, last_use={now}", f"name='{user}'"))
def insert_language(self, language: str) -> None: self.execute( Executor.insert("lang", ("name", "lang"), (self.name, language)))
def getLastNP(cls) -> list: last = cls.execute(Executor.select('*', 'np'))[0] return last
def addLastNP(cls, beatmap: int) -> None: # Delete from np last song cls.execute(Executor.delete('np')) # Insert to np last song cls.addMap(beatmap, 'np')
def pushMap(cls, beatmap: int) -> None: cls.execute( Executor.update('user', 'rating=rating+1', f"beatmap='{beatmap}'"))
def set_language(self, language: str) -> None: self.execute( Executor.update("lang", f"lang='{language}'", f"name='{self.name}'"))
def get_language(self) -> str: lang = self.execute( Executor.select("lang", "lang", f"name='{self.name}'"))[0] return lang[0]
def truncateTable(cls, table: str = 'month') -> None: cls.execute(Executor.delete(table))