#!/bin/bash # Load shared libraries SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/../lib/init.sh" # Comprehensive metrics tracking script set -e METRICS_FILE="docs/SUCCESS_METRICS.md" METRICS_DATA_FILE="docs/metrics-data.json" echo "📊 Comprehensive Metrics Tracking" echo "" # Create metrics data file if it doesn't exist if [ ! -f "$METRICS_DATA_FILE" ]; then cat > "$METRICS_DATA_FILE" << 'EOF' { "lastUpdated": "2025-01-27", "metrics": { "infrastructure": { "costReduction": { "target": 35, "current": null, "unit": "percent" }, "sharedInfrastructure": { "target": 80, "current": 0, "unit": "percent" }, "infrastructureAsCode": { "target": 100, "current": null, "unit": "percent" } }, "code": { "sharedPackages": { "target": 10, "current": 7, "unit": "count" }, "duplicateCodeReduction": { "target": 50, "current": null, "unit": "percent" }, "projectsUsingPackages": { "target": 80, "current": 0, "unit": "percent" } }, "deployment": { "deploymentTimeReduction": { "target": 50, "current": null, "unit": "percent" }, "unifiedCICD": { "target": 90, "current": null, "unit": "percent" } }, "developerExperience": { "onboardingTimeReduction": { "target": 50, "current": null, "unit": "percent" }, "developerSatisfaction": { "target": 80, "current": null, "unit": "percent" }, "documentationCoverage": { "target": 90, "current": 100, "unit": "percent" } }, "operational": { "uptime": { "target": 99.9, "current": null, "unit": "percent" }, "incidentReduction": { "target": 50, "current": null, "unit": "percent" }, "incidentResolution": { "target": 80, "current": null, "unit": "percent" }, "operationalOverheadReduction": { "target": 20, "current": null, "unit": "percent" } }, "services": { "duplicateServicesReduction": { "target": 50, "current": null, "unit": "percent" } } } } EOF echo "✅ Created metrics data file: $METRICS_DATA_FILE" fi # Function to calculate progress calculate_progress() { local current=$1 local target=$2 if [ -z "$current" ] || [ "$current" == "null" ]; then echo "0" else local progress=$(echo "scale=2; ($current / $target) * 100" | bc) if (( $(echo "$progress > 100" | bc -l) )); then echo "100" else echo "$progress" fi fi } # Update metrics file echo "📝 Updating metrics tracking..." # Read current metrics if command -v jq &> /dev/null; then CURRENT_PACKAGES=$(jq -r '.metrics.code.sharedPackages.current' "$METRICS_DATA_FILE") TARGET_PACKAGES=$(jq -r '.metrics.code.sharedPackages.target' "$METRICS_DATA_FILE") echo "📊 Current Metrics Summary:" echo " Shared Packages: ${CURRENT_PACKAGES}/${TARGET_PACKAGES} ($(calculate_progress "$CURRENT_PACKAGES" "$TARGET_PACKAGES")%)" echo "" echo "💡 To update metrics:" echo " 1. Edit $METRICS_DATA_FILE" echo " 2. Update current values" echo " 3. Run this script to regenerate report" else echo "⚠️ jq not found, using basic tracking" echo "💡 Edit $METRICS_DATA_FILE manually to update metrics" fi echo "" echo "📊 Metrics Tracking Active" echo " → Data file: $METRICS_DATA_FILE" echo " → Report file: $METRICS_FILE" echo " → Run monthly to track progress"