Пример #1
0
    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
Пример #2
0
    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))))
Пример #3
0
    def exists(cls, user: str) -> bool:
        try:
            if cls.execute(Executor.select("*", "user", f"name='{user}'")):
                return True
        except:
            return False

        return False
Пример #4
0
    def exists(self) -> None:
        try:
            if self.execute(
                    Executor.select("name", "lang", f"name='{self.name}'")):
                return True
        except:
            return False

        return False
Пример #5
0
    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
Пример #6
0
    def exist(cls, beatmap: int) -> bool:
        try:
            if cls.execute(
                    Executor.select("beatmap", "user", f"beatmap={beatmap}")):
                return True
        except:
            return False

        return False
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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
Пример #10
0
    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)))
Пример #11
0
    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}'"))
Пример #12
0
 def insert_language(self, language: str) -> None:
     self.execute(
         Executor.insert("lang", ("name", "lang"), (self.name, language)))
Пример #13
0
    def getLastNP(cls) -> list:
        last = cls.execute(Executor.select('*', 'np'))[0]

        return last
Пример #14
0
 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')
Пример #15
0
 def pushMap(cls, beatmap: int) -> None:
     cls.execute(
         Executor.update('user', 'rating=rating+1', f"beatmap='{beatmap}'"))
Пример #16
0
 def set_language(self, language: str) -> None:
     self.execute(
         Executor.update("lang", f"lang='{language}'",
                         f"name='{self.name}'"))
Пример #17
0
 def get_language(self) -> str:
     lang = self.execute(
         Executor.select("lang", "lang", f"name='{self.name}'"))[0]
     return lang[0]
Пример #18
0
 def truncateTable(cls, table: str = 'month') -> None:
     cls.execute(Executor.delete(table))