Skip to content

Commit

Permalink
make it colorfull
Browse files Browse the repository at this point in the history
  • Loading branch information
azimafroozeh committed Nov 16, 2024
1 parent 2bc3f8d commit 6c87238
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
30 changes: 22 additions & 8 deletions publication/master_script/generate_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,40 @@ def generate_markdown_table(input_folder, output_file, column_order, table_name)
df_combined.columns]
total_width = sum(col_widths) + (len(col_widths) - 1) * 3 # Account for separator widths

# ANSI escape codes for color
BLACK = "\033[30m"
GREEN = "\033[32m"
RESET = "\033[0m"

# Create a compact header with everything on one line
header_line = "=" * (total_width + 4)
print(header_line)
print(f"{table_name.center(total_width + 4)}")
print(header_line)
print(BLACK + header_line + RESET)
print(BLACK + f"{table_name.center(total_width + 4)}" + RESET)
print(BLACK + header_line + RESET)

# Print the table header
header = " | ".join(f"{col:{col_widths[i]}}" for i, col in enumerate(df_combined.columns))
separator = "-+-".join("-" * width for width in col_widths)

print(header)
print(separator)
print(BLACK + header + RESET)
print(BLACK + separator + RESET)

# Print each row with aligned columns
for _, row in df_combined.iterrows():
row_data = " | ".join(f"{str(value):{col_widths[i]}}" for i, value in enumerate(row))
print(row_data)
row_values = row[1:].apply(pd.to_numeric, errors='coerce') # Convert to numeric for comparison
min_value = row_values.min(skipna=True)
row_data = []
for i, value in enumerate(row):
if i == 0: # First column (Dataset) remains black
row_data.append(f"{BLACK}{value:{col_widths[i]}}{RESET}")
elif value == min_value and pd.notna(value): # Highlight the lowest value in green
row_data.append(f"{GREEN}{value:{col_widths[i]}}{RESET}")
else: # Other values remain black
row_data.append(f"{BLACK}{value:{col_widths[i]}}{RESET}")
print(" | ".join(row_data))

# Add a bottom-line border for the table
print(header_line)
print(BLACK + header_line + RESET)

# Write the Markdown table to a file
markdown_table = "| " + " | ".join(column_order) + " |\n"
Expand Down
7 changes: 6 additions & 1 deletion publication/master_script/master_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ brown_echo() {
echo -e "\033[33m $1\033[0m" >/dev/tty
}

black_echo() {
# Print to console only in black
echo -e "\033[30m $1\033[0m" >/dev/tty
}

red_echo() {
# Print to console only in red
echo -e "\033[31mError: $1\033[0m" >/dev/tty
Expand Down Expand Up @@ -86,7 +91,7 @@ fi

green_echo "Generating compression ratio tables ..."
output=$(python3 "$CLONED_DIR/publication/master_script/generate_tables.py")
brown_echo "$output"
black_echo "$output"

green_echo "Running benchmarks based on system architecture..."
# Run benchmarks based on system architecture
Expand Down

0 comments on commit 6c87238

Please sign in to comment.