def send_activity_logs(bot, update, args=None, level=Statistic.INFO): num = 200 if args: try: num = int(args[0]) num = min(num, 500) except: pass uid = update.effective_user.id recent_statistic = Statistic.select().order_by( Statistic.date.desc()).limit(num) recent_statistic = list(reversed(recent_statistic)) step_size = 30 for i in range(0, len(recent_statistic), step_size): items = recent_statistic[i:i + step_size] text = "\n".join(x.md_str() for x in items) bot.formatter.send_message(uid, text)
def send_statistic(bot, update): interesting_actions = [ "explore", "menu", "command", "request", "made changes to their suggestion:", "issued deletion of conversation in BotListChat", ] stats = (Statistic.select( Statistic, fn.COUNT(Statistic.entity).alias("count")).where( Statistic.action << interesting_actions).group_by( Statistic.action, Statistic.entity)) maxlen = max(len(str(x.count)) for x in stats) text = "\n".join("`{}▪️` {} {}".format( str(s.count).ljust(maxlen), s.action.title(), s.entity) for s in stats) bot.formatter.send_message(update.effective_chat.id, text, parse_mode="markdown")
def extract_frequency(region): stats = Statistic.select(Statistic.video).where( Statistic.trending_region == region ).group_by(Statistic.video) #.limit(10000) unique_video = defaultdict() for s in tqdm(stats): if s.video.id not in unique_video: unique_video[s.video.id] = s.video valid_tag = [] print('videos {}'.format(len(unique_video))) for _, video in unique_video.items(): tags = extract_video_unique_keyword(video) for tag in tags: _tag = clean_tag(tag) if _tag and len(_tag) > 1: valid_tag.append(_tag) print('total tag {}, videos {}'.format(len(valid_tag), len(unique_video))) return Counter(valid_tag)