Integrate performance scoring and report file saving features

- Add calculate_performance_score() function that counts CRITICAL/WARNING issues
- Calculate A-F grade based on severity: A (90+), B (80-89), C (70-79), D (60-69), F (<60)
- Score formula: 100 - (critical_count * 10) - (warning_count * 2), bounded 0-100
- Integrate performance score display at top of diagnostic report with box formatting
- Add save_report_to_file() function to save full report to /tmp with timestamp
- Add interactive prompt after report generation to save to file (y/n)
- Display file path where report was saved for easy reference
- Improve score parsing using cut instead of read for more reliable variable assignment

The diagnostic report now displays overall site health grade and score summary at the
beginning, making it easy to quickly assess site performance. Users can optionally save
the full report to file for archival, sharing, or future reference.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-02-26 20:19:26 -05:00
parent e53ea6f866
commit 66acf190e1
@@ -1955,6 +1955,144 @@ analyze_redirects() {
return 0
}
################################################################################
# PERFORMANCE SCORING
################################################################################
# Calculate overall performance score based on issues found
calculate_performance_score() {
local temp_dir="$1"
# Count CRITICAL and WARNING issues
local critical_count=0
local warning_count=0
for file in "$temp_dir"/*.tmp; do
[ -f "$file" ] || continue
critical_count=$((critical_count + $(grep -c "CRITICAL" "$file" 2>/dev/null || echo 0)))
warning_count=$((warning_count + $(grep -c "WARNING" "$file" 2>/dev/null || echo 0)))
done
# Calculate score (100 - issues)
local score=$((100 - (critical_count * 10) - (warning_count * 2)))
[ $score -lt 0 ] && score=0
[ $score -gt 100 ] && score=100
# Determine grade
local grade
if [ $score -ge 90 ]; then
grade="A - EXCELLENT"
elif [ $score -ge 80 ]; then
grade="B - GOOD"
elif [ $score -ge 70 ]; then
grade="C - FAIR"
elif [ $score -ge 60 ]; then
grade="D - POOR"
else
grade="F - CRITICAL"
fi
echo "$score|$grade|$critical_count|$warning_count"
}
# Save report to file
save_report_to_file() {
local domain="$1"
local temp_dir="$2"
local report_file="/tmp/slowness-report-${domain}-$(date +%Y%m%d-%H%M%S).txt"
{
echo "================================================================================"
echo " WEBSITE SLOWNESS DIAGNOSTIC REPORT"
echo " Domain: $domain"
echo " Generated: $(date)"
echo "================================================================================"
echo ""
# Add performance score at top
read_analysis_data "framework_info.tmp"
echo ""
# Rest of report
echo "================================================================================"
echo " Framework Information"
echo "================================================================================"
read_analysis_data "framework_info.tmp"
echo ""
echo "================================================================================"
echo " System Information"
echo "================================================================================"
read_analysis_data "system_info.tmp"
echo ""
echo "================================================================================"
echo " Database Analysis"
echo "================================================================================"
read_analysis_data "database_analysis.tmp"
echo ""
echo "================================================================================"
echo " Configuration Analysis"
echo "================================================================================"
read_analysis_data "config_analysis.tmp"
echo ""
echo "================================================================================"
echo " Resource Usage & Limits"
echo "================================================================================"
read_analysis_data "resource_analysis.tmp"
echo ""
echo "================================================================================"
echo " WordPress-Specific Analysis"
echo "================================================================================"
read_analysis_data "wordpress_analysis.tmp"
echo ""
echo "================================================================================"
echo " Log Analysis"
echo "================================================================================"
read_analysis_data "log_analysis.tmp"
echo ""
echo "================================================================================"
echo " Caching Status"
echo "================================================================================"
read_analysis_data "caching_info.tmp"
echo ""
echo "================================================================================"
echo " TTFB Measurements"
echo "================================================================================"
read_analysis_data "ttfb_data.tmp"
echo ""
echo "================================================================================"
echo " Image Analysis"
echo "================================================================================"
read_analysis_data "image_analysis.tmp"
echo ""
echo "================================================================================"
echo " Redirect Chain Analysis"
echo "================================================================================"
read_analysis_data "redirect_analysis.tmp"
echo ""
echo "================================================================================"
echo " END OF REPORT"
echo "================================================================================"
} > "$report_file" 2>/dev/null
if [ -f "$report_file" ]; then
echo "$report_file"
return 0
else
return 1
fi
}
################################################################################
# REPORT GENERATION
################################################################################
@@ -1962,6 +2100,22 @@ analyze_redirects() {
generate_report() {
print_section "=== SLOWNESS DIAGNOSTIC REPORT ==="
# Calculate and display performance score
local score_data=$(calculate_performance_score "$TEMP_DIR")
local score=$(echo "$score_data" | cut -d'|' -f1)
local grade=$(echo "$score_data" | cut -d'|' -f2)
local critical=$(echo "$score_data" | cut -d'|' -f3)
local warning=$(echo "$score_data" | cut -d'|' -f4)
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ PERFORMANCE SCORE SUMMARY ║"
echo "╠════════════════════════════════════════════════════════════════╣"
printf "║ Overall Grade: %-51s║\n" "$grade"
printf "║ Score: %d/100 | Issues: %d Critical, %d Warning(s)%15s║\n" "$score" "$critical" "$warning" ""
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Read and display all analysis data
print_banner "Framework Information"
read_analysis_data "framework_info.tmp" | while read -r line; do
@@ -2205,6 +2359,20 @@ run_diagnostics() {
print_banner "Generating report..."
generate_report
# Offer to save report to file
echo ""
read -p "Save report to file? (y/n): " save_choice
if [[ "$save_choice" =~ ^[Yy]$ ]]; then
local report_file=$(save_report_to_file "$domain" "$TEMP_DIR")
if [ $? -eq 0 ]; then
echo ""
print_success "Report saved to: $report_file"
echo ""
else
print_error "Failed to save report"
fi
fi
press_enter
return 0
}