Update functions for username length being in group.
This commit is contained in:
+5
-7
@@ -176,7 +176,6 @@ def format_highscore_message(group: CategoryGroup) -> str:
|
||||
ret_string = f"**{group.GroupName}**\n```"
|
||||
|
||||
stmt = select(Guild).where(Guild.GuildId == group.GuildId)
|
||||
guild = session.scalars(stmt).one()
|
||||
|
||||
# Get all categories in the group
|
||||
subq = (
|
||||
@@ -201,13 +200,12 @@ def format_highscore_message(group: CategoryGroup) -> str:
|
||||
category_ids.append(cat.CategoryId)
|
||||
|
||||
# get all scores in category group, load into data frame.
|
||||
# FIXME there is some slice warning here from pandas.
|
||||
d_f = pd.read_sql_query(sql=session.query(Score).where(Score.CategoryId.in_(category_ids)).statement, con=engine)
|
||||
|
||||
# this list is what will be printed in the discord message
|
||||
# first string will be category list, others will be score printouts
|
||||
str_list: "list[str]" = ["" for i in range(max_cat_size + 1)]
|
||||
groups = d_f.groupby("CategoryId")
|
||||
groups_df = d_f.groupby("CategoryId")
|
||||
|
||||
# TODO figure out how to have less nests.
|
||||
for category in categories:
|
||||
@@ -215,18 +213,18 @@ def format_highscore_message(group: CategoryGroup) -> str:
|
||||
str_list[0] += f"{category.CategoryName}".ljust(pad_length, " ")
|
||||
|
||||
# ensure there is data to print
|
||||
if category.CategoryId in groups.indices:
|
||||
group = groups.get_group(category.CategoryId)
|
||||
if category.CategoryId in groups_df.indices:
|
||||
group_df = groups_df.get_group(category.CategoryId)
|
||||
|
||||
# process data. Want each group sorted correctly and only top X results
|
||||
processed_group = (
|
||||
group.sort_values("Score", ascending=category.IsAscending).head(category.Size).reset_index()
|
||||
group_df.sort_values("Score", ascending=category.IsAscending).head(category.Size).reset_index()
|
||||
)
|
||||
|
||||
# add each score to list
|
||||
for ind in range(max_cat_size): # need to subtract to deal with category name string
|
||||
if ind in processed_group.index:
|
||||
user_length = guild.UsernameLength
|
||||
user_length = group.UsernameLength
|
||||
username = processed_group["UserName"][ind][:user_length].ljust(user_length, " ")
|
||||
|
||||
# get score, pad to correct length
|
||||
|
||||
Reference in New Issue
Block a user