83 lines
No EOL
2.2 KiB
Bash
Executable file
83 lines
No EOL
2.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Scenario Visualizer Launcher
|
|
# Starts a local HTTP server and opens the visualization page
|
|
|
|
echo "🚀 Starting Scenario Visualizer..."
|
|
echo "=================================="
|
|
|
|
# Check if CSV file exists
|
|
if [ ! -f "profitable_scenario.csv" ]; then
|
|
echo "⚠️ No profitable_scenario.csv found in analysis folder"
|
|
echo "Run analysis first: forge script analysis/SimpleAnalysis.s.sol --ffi"
|
|
echo ""
|
|
read -p "Continue anyway? (y/n): " -n 1 -r
|
|
echo ""
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Function to detect available Python
|
|
detect_python() {
|
|
if command -v python3 &> /dev/null; then
|
|
echo "python3"
|
|
elif command -v python &> /dev/null; then
|
|
echo "python"
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
# Function to start server
|
|
start_server() {
|
|
local python_cmd=$1
|
|
local port=$2
|
|
|
|
echo "📡 Starting HTTP server on port $port..."
|
|
echo "🌐 Opening http://localhost:$port/scenario-visualizer.html"
|
|
echo ""
|
|
echo "Press Ctrl+C to stop the server"
|
|
echo "=================================="
|
|
|
|
# Start server in background first
|
|
$python_cmd -m http.server $port &
|
|
SERVER_PID=$!
|
|
|
|
# Give server a moment to start
|
|
sleep 1
|
|
|
|
# Try to open browser (works on most systems)
|
|
if command -v xdg-open &> /dev/null; then
|
|
xdg-open "http://localhost:$port/scenario-visualizer.html" 2>/dev/null &
|
|
elif command -v open &> /dev/null; then
|
|
open "http://localhost:$port/scenario-visualizer.html" 2>/dev/null &
|
|
else
|
|
echo "🔗 Manual: Open http://localhost:$port/scenario-visualizer.html in your browser"
|
|
fi
|
|
|
|
# Wait for the server process
|
|
wait $SERVER_PID
|
|
}
|
|
|
|
# Main execution
|
|
cd "$(dirname "$0")"
|
|
|
|
# Check for Python
|
|
PYTHON_CMD=$(detect_python)
|
|
if [ -z "$PYTHON_CMD" ]; then
|
|
echo "❌ Python not found. Please install Python 3 or use alternative:"
|
|
echo " npx http-server . --port 8000"
|
|
echo " php -S localhost:8000"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if port is available
|
|
PORT=8000
|
|
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null 2>&1; then
|
|
echo "⚠️ Port $PORT is already in use. Trying port $((PORT + 1))..."
|
|
PORT=$((PORT + 1))
|
|
fi
|
|
|
|
# Start the server
|
|
start_server "$PYTHON_CMD" "$PORT" |