-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_reports.sh
More file actions
95 lines (80 loc) · 3.46 KB
/
generate_reports.sh
File metadata and controls
95 lines (80 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -euo pipefail
# ================================================
# Generate HTML and Excel reports from quality dirs
# and from top-level results (contamination/svevrste)
# ================================================
# Base results directory (relative to where this script runs)
BASE_DIR="$(pwd)/results"
# Path to your Python reporting script (html.py)
SCRIPT_PATH="$(pwd)/python/html.py"
# Log file for tracking actions
LOG_FILE="${BASE_DIR}/report_generation.log"
echo "=== Report generation started at $(date) ===" > "$LOG_FILE"
# --------------------------------------------
# Function: Generate and rename reports
# --------------------------------------------
generate_and_rename_report() {
local quality_dir="$1"
local report_prefix="$2"
echo "[$(date)] Generating report for $quality_dir" >> "$LOG_FILE"
# Copy the Python script into the directory
cp "$SCRIPT_PATH" "$quality_dir"
cd "$quality_dir"
# Run the report generator
if python3 html.py; then
# Rename HTML report
if [ -f "final_report.html" ]; then
mv "final_report.html" "${report_prefix}_final_report.html"
echo "Renamed final_report.html to ${report_prefix}_final_report.html" >> "$LOG_FILE"
else
echo "final_report.html not found in $quality_dir" >> "$LOG_FILE"
fi
# Rename Excel report
if [ -f "final_report.xlsx" ]; then
mv "final_report.xlsx" "${report_prefix}_final_report.xlsx"
echo "Renamed final_report.xlsx to ${report_prefix}_final_report.xlsx" >> "$LOG_FILE"
else
echo "final_report.xlsx not found in $quality_dir" >> "$LOG_FILE"
fi
else
echo "Error running html.py in $quality_dir" >> "$LOG_FILE"
fi
# Remove the copied script to keep directories clean
rm -f "html.py"
echo "[$(date)] Report generation completed for $quality_dir" >> "$LOG_FILE"
}
# --------------------------------------------
# Find all quality directories automatically
# (exactly three levels deep, avoids nested dups)
# --------------------------------------------
mapfile -t quality_dirs < <(find "$BASE_DIR" -mindepth 3 -maxdepth 3 -type d -name quality)
# --------------------------------------------
# Process each quality directory
# --------------------------------------------
for quality_dir in "${quality_dirs[@]}"; do
if [ "$(ls -A "$quality_dir")" ]; then
report_prefix=$(basename "$(dirname "$quality_dir")")
generate_and_rename_report "$quality_dir" "$report_prefix"
else
echo "[$(date)] $quality_dir is empty or does not exist, skipping" >> "$LOG_FILE"
fi
done
# --------------------------------------------
# Generate top-level results summary (for contamination/svevrste)
# --------------------------------------------
if compgen -G "${BASE_DIR}/contamination*.txt" > /dev/null || \
compgen -G "${BASE_DIR}/svevrste*.txt" > /dev/null; then
echo "[$(date)] Generating top-level results report for $BASE_DIR" >> "$LOG_FILE"
cp "$SCRIPT_PATH" "$BASE_DIR"
cd "$BASE_DIR"
if python3 html.py; then
mv "final_report.html" "results_summary_final_report.html"
mv "final_report.xlsx" "results_summary_final_report.xlsx"
echo "Top-level results summary created in $BASE_DIR" >> "$LOG_FILE"
else
echo "Error running html.py in $BASE_DIR" >> "$LOG_FILE"
fi
rm -f "html.py"
fi
echo "=== All reports generated successfully at $(date) ===" >> "$LOG_FILE"