Skip to content

Commit 9e713c2

Browse files
committed
Fixes #15 added function to calculate first, second, third per table.
1 parent 936c5d5 commit 9e713c2

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

data_extraction/build_html.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,53 @@ def add_top_3_classes(df, actual_df):
504504

505505
return actual_df
506506

507+
def add_top_3_classes_per_type(
508+
df, actual_df, category_col="category", include_3dgs=True
509+
):
510+
colors = ["first", "second", "third"]
511+
for col in df.columns:
512+
try:
513+
float_col = df[col].astype(float)
514+
except ValueError:
515+
continue # Skip non-numeric columns
516+
517+
# Loop through each category type ('c', 'd')
518+
for category_type in df[category_col].unique():
519+
if category_type not in ["c", "d"]:
520+
continue # Skip unrelated categories
521+
522+
# Filter rows by category
523+
filtered_indices = df[df[category_col] == category_type].index
524+
filtered_col = float_col[filtered_indices]
525+
526+
# Explicitly include the 3DGS-30K row in the filtered column
527+
if include_3dgs:
528+
filtered_indices = filtered_indices.union(
529+
df[df["Method"].str.contains("3DGS-30K", na=False)].index
530+
)
531+
filtered_col = float_col[filtered_indices]
532+
533+
if (
534+
any(
535+
keyword in col[1].lower()
536+
for keyword in ["size", "lpips", "gauss", "b/g"]
537+
)
538+
or "rank" in col[0].lower()
539+
):
540+
top_3 = pd.Series(filtered_col.unique()).nsmallest(3)
541+
else:
542+
top_3 = pd.Series(filtered_col.unique()).nlargest(3)
543+
544+
# Assign "first", "second", "third" classes to the filtered rows
545+
for i, val in enumerate(top_3):
546+
matching_indices = filtered_col[filtered_col == val].index
547+
for index in matching_indices:
548+
actual_df.at[index, col] = (
549+
f'<td class="{colors[i]}">{actual_df.at[index, col]}</td>'
550+
)
551+
552+
return actual_df
553+
507554
multi_col_df_copy = multi_col_df.copy()
508555

509556
def numGaussians_to_k_Gauss(df):
@@ -527,7 +574,7 @@ def apply_dataset_names(df):
527574
)
528575

529576
numGaussians_to_k_Gauss(multi_col_df)
530-
multi_col_df = add_top_3_classes(
577+
multi_col_df = add_top_3_classes_per_type(
531578
multi_col_df_copy, multi_col_df.astype(str)
532579
).replace(["nan", "NaN", "None"], "")
533580

0 commit comments

Comments
 (0)