Пример #1
0
    def get_top_igor(cls, cid, date=None):
        monday = cls.__get_current_monday(
        ) if date is None else cls.__get_date_monday(date)
        db = cls.__get_db(monday, cid)
        stats = UserStat.get_chat_stats(cid, date)

        # подсчитаем всех по отношению игорь-слов к общему количеству слов этого участника
        igor_by_count = {}
        for user_stat, user in stats:
            count = user_stat.all_messages_count
            # учитываем только тек, кто написал от 30 сообщений
            if count < 30 or user_stat.words_count < 500:
                continue
            if user.uid not in db:
                continue
            igor_by_count[user.uid] = db[user.uid] / count

        if len(igor_by_count) > 0:
            uid, _ = cls.__sort_dict(igor_by_count)[0]
        elif len(stats) == 0:
            return None
        else:
            _, user = random.choice(stats)
            uid = user.uid
        return uid
Пример #2
0
def send_all_stat_handler(bot: telegram.Bot, update: telegram.Update) -> None:
    message: telegram.Message = update.message
    chat_id = message.chat_id
    chat_stats = UserStat.get_chat_stats(chat_id)

    rs = RedisChatStatistician(chat_id)
    rs.load()
    text = rs.chat_statistician.show_chat_stat(chat_stats)
    bot.send_message(chat_id, text, parse_mode=ParseMode.HTML)
Пример #3
0
def send_topmat(bot: telegram.Bot,
                send_to_cid: int,
                stats_from_cid: int,
                date=None) -> None:
    monday = get_current_monday() if date is None else get_date_monday(date)
    stats = UserStat.get_chat_stats(stats_from_cid, date)
    words = get_words_from_cache(monday, stats_from_cid)
    users_msg_stats = get_mat_users_msg_stats(stats)
    msg = format_msg(
        'Стата по мату', {
            'header_stats': get_header_stats(stats),
            'users_msg_stats': users_msg_stats,
            'users_words_stats': get_mat_users_words_stats(stats),
            'words_stats': get_words_stats(words),
        })
    set_top_mater(stats_from_cid, users_msg_stats)
    bot.send_message(send_to_cid, msg, parse_mode=telegram.ParseMode.HTML)