diff --git a/src/stats/chat_commands.py b/src/stats/chat_commands.py index d73def7..d4d860b 100644 --- a/src/stats/chat_commands.py +++ b/src/stats/chat_commands.py @@ -99,7 +99,7 @@ async def cmd_summary(self, update: Update, context: ContextTypes.DEFAULT_TYPE): # Ratios fun_metric = self.calculate_fun_metric(chat_df, reactions_df) wholesome_metric = self.calculate_wholesome_metric(reactions_df) - user_stats['monologue_ratio'] = (user_stats['word_count'] / user_stats['message_count']).round(2) + user_stats['monologue_ratio'] = (user_stats['word_count']/user_stats['message_count']).round(2) # Calculate message and reaction count changes message_count_change = 0 if shifted_chat_df.empty else round((len(chat_df) - len(shifted_chat_df)) / len(shifted_chat_df) * 100, 1) @@ -116,12 +116,17 @@ async def cmd_summary(self, update: Update, context: ContextTypes.DEFAULT_TYPE): text += "\n- *Monologue index*: " + ", ".join([f"{row['final_username']}: *{row['monologue_ratio']}*" for _, row in user_stats.sort_values('monologue_ratio', ascending=False).head(3).iterrows()]) text += "\n- *Fun meter*: " + ", ".join([f"{row['final_username']}: *{row['ratio']}*" for _, row in fun_metric.head(3).iterrows()]) text += "\n- *Wholesome meter*: " + ", ".join([f"{row['reacting_username']}: *{row['ratio']}*" for _, row in wholesome_metric.head(3).iterrows()]) - text += "\n- *Unwholesome meter*: " + ", ".join([f"{row['reacting_username']}: *{row['ratio']}*" for _, row in wholesome_metric.sort_values('ratio', ascending=True).head(3).iterrows()]) + text += "\n- *Unwholesome meter*: " + ", ".join( + [f"{row['reacting_username']}: *{row['ratio']}*" for _, row in wholesome_metric.sort_values('ratio', ascending=True).head(3).iterrows()]) text += "\n- *Most liked*: " + ", ".join([f"{row['reacted_to_username']}: *{row['count']}*" for _, row in reactions_received_counts.head(3).iterrows()]) text += "\n- *Most liking*: " + ", ".join([f"{row['reacting_username']}: *{row['count']}*" for _, row in reactions_given_counts.head(3).iterrows()]) - text += "\n- *Most disliked*: " + ", ".join([f"{row['reacted_to_username']}: *{row['count']}*" for _, row in sad_reactions_received_counts.head(3).iterrows()]) - text += "\n- *Most disliking*: " + ", ".join([f"{row['reacting_username']}: *{row['count']}*" for _, row in sad_reactions_given_counts.head(3).iterrows()]) - text += "\n- *Top message*: " + ", ".join( [f"{row['final_username']} [{stats_utils.dt_to_str(row['timestamp'])}]: {row['text']} [{''.join(row['reaction_emojis'])}]" for _, row in text_only_chat_df.head(1).iterrows()]) + text += "\n- *Most disliked*: " + ", ".join( + [f"{row['reacted_to_username']}: *{row['count']}*" for _, row in sad_reactions_received_counts.head(3).iterrows()]) + text += "\n- *Most disliking*: " + ", ".join( + [f"{row['reacting_username']}: *{row['count']}*" for _, row in sad_reactions_given_counts.head(3).iterrows()]) + text += "\n- *Top message*: " + ", ".join( + [f"{row['final_username']} [{stats_utils.dt_to_str(row['timestamp'])}]: {row['text']} [{''.join(row['reaction_emojis'])}]" for _, row in + text_only_chat_df.head(1).iterrows()]) text = stats_utils.escape_special_characters(text) await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) @@ -268,26 +273,21 @@ async def cmd_set_username(self, update: Update, context: ContextTypes.DEFAULT_T await context.bot.send_message(chat_id=update.effective_chat.id, text=command_args.error) return - text = "Due to missuse of *set_username* command through various means, it has been *indefinitely disabled*, until decided otherwise by the Ozjasz Team. You can unlock this feature after subscribing to Ozjasz premium, for *5$ monthly*. \n\nRegards, *Ozjasz Team*." - escaped_text = stats_utils.escape_special_characters(text) - await context.bot.send_message(chat_id=update.effective_chat.id, text=escaped_text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) - return - - # user_id = update.effective_user.id - # current_username = self.users_df.at[user_id, 'final_username'] - # new_username = command_args.string - # is_valid, error = stats_utils.check_new_username(self.users_df, new_username) - # - # if not is_valid: - # error = stats_utils.escape_special_characters(error) - # await context.bot.send_message(chat_id=update.effective_chat.id, text=error, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) - # return - # - # self.users_df.at[user_id, 'final_username'] = new_username - # core_utils.save_df(self.users_df, USERS_PATH) - # text = f'Username changed from: *{current_username}* to *{new_username}*. It will get updated in a few minutes.' - # text = stats_utils.escape_special_characters(text) - # await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) + user_id = update.effective_user.id + current_username = self.users_df.at[user_id, 'final_username'] + new_username = command_args.string + is_valid, error = stats_utils.check_new_username(self.users_df, new_username) + + if not is_valid: + error = stats_utils.escape_special_characters(error) + await context.bot.send_message(chat_id=update.effective_chat.id, text=error, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) + return + + self.users_df.at[user_id, 'final_username'] = new_username + core_utils.save_df(self.users_df, USERS_PATH) + text = f'Username changed from: *{current_username}* to *{new_username}*. It will get updated in a few minutes.' + text = stats_utils.escape_special_characters(text) + await context.bot.send_message(chat_id=update.effective_chat.id, text=text, parse_mode=telegram.constants.ParseMode.MARKDOWN_V2) async def cmd_fun(self, update: Update, context: ContextTypes.DEFAULT_TYPE): command_args = CommandArgs(args=context.args, expected_args=[ArgType.PERIOD]) diff --git a/src/stats/chat_etl.py b/src/stats/chat_etl.py index 73a7770..ae2ef2d 100644 --- a/src/stats/chat_etl.py +++ b/src/stats/chat_etl.py @@ -194,10 +194,7 @@ def extract_users(self): if os.path.exists(USERS_PATH): log.info(f'Users already extracted, {USERS_PATH} exists.') - users_df = core_utils.read_df(USERS_PATH) - stats_utils.validate_schema(users_df, users_schema) return - log.info('Extracting users...') chat_df = core_utils.read_df(CHAT_HISTORY_PATH) @@ -208,7 +205,7 @@ def extract_users(self): filtered_users_df['nicknames'] = [[] for _ in range(len(filtered_users_df))] filtered_users_df = filtered_users_df.set_index('user_id') - stats_utils.validate_schema(filtered_users_df, users_schema) + stats_utils.validate_schema(users_df, users_schema) core_utils.save_df(filtered_users_df, USERS_PATH) def create_final_username(self, row):