Example #1
0
def game_statistics(bot, user, *args):
    amount_games = db.session.query(db.GameStatistic).filter(
        db.or_(
            db.GameStatistic.challenger_user_id == user.db_data.id,
            db.GameStatistic.challenged_user_id == user.db_data.id)).count()
    amount_wins = db.session.query(db.GameStatistic).filter(
        db.or_(db.GameStatistic.winner_user_id == user.db_data.id)).count()
    """print(f"----------{user.db_data.twitch_user_name}----------")
    print(f"amount_games: {amount_games}")
    print(f"amount_wins: {amount_wins}")"""
    if amount_games == 0: return None
    win_streak = db.query_game_streak(user.db_data.id, "roulette")
    return f"Deine Gewinnrate bei Chatroulette ist: {round((amount_wins*100/amount_games),2)}% mit einer " \
           f"Siegesserie von {win_streak}."
Example #2
0
 def get_task_list(self, start_task_id=0, limit=30, q="", t="", a="", order=db.Task.createtime, dis=db.desc, all=False):
     session = Session()
     self._last_get_task_list = self.time()
     # base query
     query = session.query(db.Task)
     # query or tags
     if q:
         query = query.filter(db.or_(db.Task.taskname.like("%%%s%%" % q),
             db.Task.tags.like("%%%s%%" % q)))
     elif t:
         query = query.filter(db.Task.tags.like("%%|%s|%%" % t));
     # author query
     if a:
         query = query.filter(db.Task.creator == a)
     # next page offset
     if start_task_id:
         value = session.query(order).filter(db.Task.id == start_task_id).first()
         if not value:
             return []
         if dis == db.desc:
             query = query.filter(order < value[0])
         else:
             query = query.filter(order > value[0])
         query = query.filter(db.Task.id < start_task_id)
     # order or limit
     if not all:
         query = query.filter(db.Task.invalid == False)
     query = query.order_by(dis(order), dis(db.Task.id)).limit(limit)
     return query.all()
Example #3
0
 def get_task_list(self, start_task_id=0, limit=30, q="", t="", a="", order=db.Task.createtime, dis=db.desc):
     self._last_get_task_list = self.time()
     # base query
     query = self.session.query(db.Task)
     # query or tags
     if q:
         query = query.filter(db.or_(db.Task.taskname.like("%%%s%%" % q),
             db.Task.tags.like("%%%s%%" % q)))
     elif t:
         query = query.filter(db.Task.tags.like("%%|%s|%%" % t));
     # author query
     if a:
         query = query.filter(db.Task.creator == a)
     # next page offset
     if start_task_id:
         value = self.session.query(order).filter(db.Task.id == start_task_id).first()
         if not value:
             return []
         if dis == db.desc:
             query = query.filter(order < value[0])
         else:
             query = query.filter(order > value[0])
         query = query.filter(db.Task.id < start_task_id)
     # order or limit
     query = query.filter(db.Task.invalid == False)\
                  .order_by(dis(order), dis(db.Task.id)).limit(limit)
     return query.all()
Example #4
0
    def update(self):
        if self._last_update_task + options.finished_task_check_interval < time():
            self._last_update_task = time()
            self._update_task_list(options.task_list_limit)

        if self._last_update_downloading_task + \
                options.downloading_task_check_interval < self._last_get_task_list or \
           self._last_update_downloading_task + \
                options.finished_task_check_interval < time():
            self._last_update_downloading_task = time()
            need_update = Session().query(db.Task).filter(db.or_(db.Task.status == "waiting", db.Task.status == "downloading")).all()
            if need_update:
                self._update_tasks(need_update)

            # as we can't get real status of a task when it's status is waiting, stop the task with lowest
            # speed. when all task is stoped, restart them.
            nm_list = []
            bt_list = []
            for task_id, task_type in Session().query(db.Task.id, db.Task.task_type).filter(db.Task.status == "downloading"):
                if task_type in ("bt", "magnet"):
                    bt_list.append(task_id)
                else:
                    nm_list.append(task_id)
            if bt_list or nm_list:
                downloading_tasks, summery = self.xunlei.get_task_process(nm_list, bt_list, with_summary=True)
                if int(summery['waiting_num']) == 0:
                    self._restart_all_paused_task()
                need_stop_task = min(downloading_tasks, key=lambda x: x['speed'])
                self.xunlei.task_pause([need_stop_task['task_id'], ])
            else:
                self._restart_all_paused_task()
Example #5
0
 def serach_count(self, key):
     q = db.select(self.table).fields(db.expr('count(*)',
             'total')).condition('status', 'published')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key, 'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     return q.execute()[0][0]
Example #6
0
    def get_task_list(self,
                      start_task_id=0,
                      offset=0,
                      limit=30,
                      q="",
                      t="",
                      a="",
                      order=db.Task.createtime,
                      dis=db.desc,
                      all=False):
        session = Session()
        self._last_get_task_list = self.time()
        # base query
        query = session.query(db.Task)
        # query or tags
        if q:
            query = query.filter(
                db.or_(db.Task.taskname.like("%%%s%%" % q),
                       db.Task.tags.like("%%%s%%" % q)))
        elif t:
            query = query.filter(db.Task.tags.like("%%|%s|%%" % t))
        # author query
        if a:
            query = query.filter(db.Task.creator == a)
        # next page offset
        if start_task_id:
            value = session.query(order).filter(
                db.Task.id == start_task_id).first()
            if not value:
                return []
            if dis == db.desc:
                query = query.filter(order < value[0])
            else:
                query = query.filter(order > value[0])
        # order or limit
        if not all:
            query = query.filter(db.Task.invalid == False)
        query = query.order_by(dis(order),
                               dis(db.Task.id)).offset(offset).limit(limit)

        result = query.all()
        if result and start_task_id:
            for i, each in enumerate(result):
                if each.id == start_task_id:
                    result = result[i + 1:]
                    if not result:
                        return self.get_task_list(start_task_id=start_task_id,
                                                  offset=offset + i + 1,
                                                  limit=limit,
                                                  q=q,
                                                  t=t,
                                                  a=a,
                                                  order=order,
                                                  dis=dis,
                                                  all=all)
                    else:
                        return result
        session.close()
        return result
Example #7
0
    def test_select_or_condition(self):
        from db import or_
        or_con = or_()
        or_con.condition('name', 'user_1')
        or_con.condition('name', 'user_2')
        res = (self.select.condition(or_con).execute())

        self.assertEquals(res[0][1], 'user_1')
Example #8
0
 def search(self, key, page=1, perpage=10):
     q = db.select(self.table).fields('title', 'slug', 'description', 'html', 'css', 'js',
                                      'category', 'status', 'allow_comment', 'author', 'updated', 'created', 'pid')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key, 'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     results = (q.condition('status', 'published').limit(perpage).offset((page - 1) * perpage)
                 .order_by('created', 'DESC').execute())
     return [self.load(data, self.model) for data in results]
Example #9
0
 def serach_count(self, key):
     q = db.select(self.table).fields(db.expr('count(*)',
                                              'total')).condition(
                                                  'status', 'published')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key,
                   'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     return q.execute()[0][0]
Example #10
0
    def test_select_or_condition(self):
        from db import or_
        or_con = or_()
        or_con.condition('name', 'user_1')
        or_con.condition('name', 'user_2')
        res = (self.select
               .condition(or_con)
               .execute())

        self.assertEquals(res[0][1], 'user_1')
Example #11
0
 def search(self, key, page=1, perpage=10):
     q = db.select(self.table).fields('title', 'slug', 'description',
                                      'html', 'css', 'js', 'category',
                                      'status', 'allow_comment', 'author',
                                      'updated', 'created', 'pid')
     _or = db.or_()
     _or.condition('slug', '%%%s%%' % key,
                   'LIKE').condition('title', '%%%s%%' % key, 'LIKE')
     q.condition(_or)
     results = (q.condition('status', 'published').limit(perpage).offset(
         (page - 1) * perpage).order_by('created', 'DESC').execute())
     return [self.load(data, self.model) for data in results]
Example #12
0
    def update(self):
        if self._last_update_task + options.finished_task_check_interval < time():
            self._last_update_task = time()
            self._update_task_list(options.task_list_limit)

        if self._last_update_downloading_task + \
                options.downloading_task_check_interval < self._last_get_task_list or \
           self._last_update_downloading_task + \
                options.finished_task_check_interval < time():
            self._last_update_downloading_task = time()
            need_update = Session().query(db.Task).filter(db.or_(db.Task.status == "waiting", db.Task.status == "downloading")).all()
            if need_update:
                self._update_tasks(need_update)
Example #13
0
    def update(self):
        if self._last_update_task + options.finished_task_check_interval < time(
        ):
            self._last_update_task = time()
            self._update_task_list(options.task_list_limit)

        if self._last_update_downloading_task + \
                options.downloading_task_check_interval < self._last_get_task_list or \
           self._last_update_downloading_task + \
                options.finished_task_check_interval < time():
            self._last_update_downloading_task = time()
            need_update = Session().query(db.Task).filter(
                db.or_(db.Task.status == "waiting",
                       db.Task.status == "downloading")).all()
            if need_update:
                self._update_tasks(need_update)
Example #14
0
def place_on_auto_vip_order(user: Chatuser):
    try:
        unsorted_user_list = [[
            user_in_db, (user_in_db.number_of_logins * 0.5) +
            (user_in_db.loyalty_points * 1) + (user_in_db.honor_counter * 2),
            user_in_db.warnings
        ] for user_in_db in db.session.query(db.User).filter(
            db.and_(db.User.twitch_user_name != 'gans', (
                db.or_(db.User.stream_badges == "AutoVIP",
                       db.User.stream_badges == "Tueftlie"))))]

        sorted_user_list = sorted(unsorted_user_list,
                                  key=lambda x: (x[1], -x[2]),
                                  reverse=True)
        return len(sorted_user_list), sorted_user_list.index(user.db_data)
    except ValueError as err:
        tetueSrc.log_event_warning(
            f'Vip Order Fehler für: {user.db_data.twitch_user_name} '
            f'mit dem Fehler {err}')
        return len(sorted_user_list), None
Example #15
0
    def update(self):
        if self._last_update_task + options.finished_task_check_interval < time(
        ):
            self._last_update_task = time()
            self._update_task_list(options.task_list_limit)

        if self._last_update_downloading_task + \
                options.downloading_task_check_interval < self._last_get_task_list or \
           self._last_update_downloading_task + \
                options.finished_task_check_interval < time():
            self._last_update_downloading_task = time()
            need_update = Session().query(db.Task).filter(
                db.or_(db.Task.status == "waiting",
                       db.Task.status == "downloading")).all()
            if need_update:
                self._update_tasks(need_update)

            # as we can't get real status of a task when it's status is waiting, stop the task with lowest
            # speed. when all task is stoped, restart them.
            nm_list = []
            bt_list = []
            for task_id, task_type in Session().query(
                    db.Task.id,
                    db.Task.task_type).filter(db.Task.status == "downloading"):
                if task_type in ("bt", "magnet"):
                    bt_list.append(task_id)
                else:
                    nm_list.append(task_id)
            if bt_list or nm_list:
                downloading_tasks, summery = self.xunlei.get_task_process(
                    nm_list, bt_list, with_summary=True)
                if int(summery['waiting_num']) == 0:
                    self._restart_all_paused_task()
                need_stop_task = min(downloading_tasks,
                                     key=lambda x: x['speed'])
                self.xunlei.task_pause([
                    need_stop_task['task_id'],
                ])
            else:
                self._restart_all_paused_task()
    def get_task_list(self, start_task_id=0, offset=0, limit=30, q="", t="", a="", order=db.Task.createtime, dis=db.desc, all=False):
        session = Session()
        self._last_get_task_list = self.time()
        # base query
        query = session.query(db.Task)
        # query or tags
        if q:
            query = query.filter(db.or_(db.Task.taskname.like("%%%s%%" % q),
                db.Task.tags.like("%%%s%%" % q)))
        elif t:
            query = query.filter(db.Task.tags.like("%%|%s|%%" % t));
        # author query
        if a:
            query = query.filter(db.Task.creator == a)
        # next page offset
        if start_task_id:
            value = session.query(order).filter(db.Task.id == start_task_id).first()
            if not value:
                return []
            if dis == db.desc:
                query = query.filter(order < value[0])
            else:
                query = query.filter(order > value[0])
        # order or limit
        if not all:
            query = query.filter(db.Task.invalid == False)
        query = query.order_by(dis(order), dis(db.Task.id)).offset(offset).limit(limit)

        result = query.all()
        if result and start_task_id:
            for i, each in enumerate(result):
                if each.id == start_task_id:
                    result = result[i+1:]
                    if not result:
                        return self.get_task_list(start_task_id=start_task_id, offset=offset+i+1, limit=limit, q=q, t=t, a=a, order=order, dis=dis, all=all)
                    else:
                        return result
        session.close()
        return result
Example #17
0
def listSubmissions(time=None):
    if not time:
        time = datetime.utcnow() - timedelta(hours=5)
    else:
        time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S")

    session = Session()
    problemmanagment.pull()
    return [
        (
            x.id,
            x.problem.name,
            x.problem_id,
            x.submitter.handle,
            x.submitter_id,
            status(x.code),
            str(x.judgeTime),
            str(x.submitTime),
        )
        for x in session.query(Submission)
        .filter(or_(Submission.judgeTime > time, Submission.submitTime > time))
        .order_by(Submission.submitTime)
    ]
Example #18
0
 def test_delete_or_condtions(self):
     from db import or_
     or_con = or_().condition('name', 'user_1').condition('name', 'user_2')
     res = self.delete.condition(or_con).execute()
     self.assertEqual(res, 2)
Example #19
0
 def test_delete_or_condtions(self):
     from db import or_
     or_con = or_().condition('name', 'user_1').condition('name', 'user_2')
     res = self.delete.condition(or_con).execute()
     self.assertEqual(res, 2)