-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_simulation.bat
More file actions
237 lines (193 loc) · 6.45 KB
/
run_simulation.bat
File metadata and controls
237 lines (193 loc) · 6.45 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
@echo on
REM Network-Performance-Monitor Simulation Mode Setup and Run Script (Windows)
REM This script runs the application in simulation mode for testing without real hardware
setlocal enabledelayedexpansion
REM Colors for output (using PowerShell for colored text)
set "INFO_COLOR=Blue"
set "SUCCESS_COLOR=Green"
set "WARNING_COLOR=Yellow"
set "ERROR_COLOR=Red"
REM Function to print colored output
call :print_status "Network-Performance-Monitor Setup and Run Script (Simulation Mode)"
call :print_status "Checking for required dependencies..."
REM Check for Python
python --version >nul 2>&1
if !errorlevel! equ 0 (
set "PYTHON_CMD=python"
for /f "tokens=*" %%i in ('python --version 2^>^&1') do set PYTHON_VERSION=%%i
call :print_success "Python found: !PYTHON_VERSION!"
) else (
python3 --version >nul 2>&1
if !errorlevel! equ 0 (
set "PYTHON_CMD=python3"
for /f "tokens=*" %%i in ('python3 --version 2^>^&1') do set PYTHON_VERSION=%%i
call :print_success "Python found: !PYTHON_VERSION!"
) else (
call :print_error "Python is not installed. Please install Python 3.x and try again."
pause
exit /b 1
)
)
REM Check for Node.js
node --version >nul 2>&1
if !errorlevel! equ 0 (
for /f "tokens=*" %%i in ('node --version') do set NODE_VERSION=%%i
call :print_success "Node.js found: !NODE_VERSION!"
) else (
call :print_error "Node.js is not installed. Please install Node.js and try again."
pause
exit /b 1
)
REM Check for npm
npm --version >nul 2>&1
if !errorlevel! equ 0 (
for /f "tokens=*" %%i in ('npm --version') do set NPM_VERSION=%%i
call :print_success "npm found: !NPM_VERSION!"
) else (
call :print_error "npm is not installed. Please install npm and try again."
pause
exit /b 1
)
REM Set simulation mode environment variable
set "SIMULATION_MODE=true"
call :print_status "Simulation mode enabled: !SIMULATION_MODE!"
REM Function to install Python dependencies
call :install_python_deps
REM Function to install Node.js dependencies
call :install_node_deps
REM Start the application in simulation mode
call :start_backend
call :start_frontend
call :print_status "Application started successfully in simulation mode!"
call :print_status "Backend API: http://127.0.0.1:8000"
call :print_status "Frontend: http://127.0.1:3000"
call :print_status "Backend and frontend are running in separate windows."
call :print_status "Press any key in this window to stop the application."
call :print_status "Or close this window to keep the applications running."
REM Wait for user input to stop the application
pause >nul
REM Attempt to clean up processes before exiting
call :cleanup_processes
goto :eof
REM Function definitions
:print_status
powershell -Command "Write-Host '[INFO] %~1' -ForegroundColor Blue"
goto :eof
:print_success
powershell -Command "Write-Host '[SUCCESS] %~1' -ForegroundColor Green"
goto :eof
:print_warning
powershell -Command "Write-Host '[WARNING] %~1' -ForegroundColor Yellow"
goto :eof
:print_error
powershell -Command "Write-Host '[ERROR] %~1' -ForegroundColor Red"
goto :eof
:install_python_deps
call :print_status "Installing Python dependencies from requirements.txt..."
if not exist "requirements.txt" (
call :print_error "requirements.txt not found in project root."
exit /b 1
)
REM Create virtual environment if it doesn't exist
if not exist "venv" (
call :print_status "Creating Python virtual environment..."
!PYTHON_CMD! -m venv venv
)
REM Deactivate any existing virtual environment first to prevent conflicts
if defined VIRTUAL_ENV (
call deactivate 2>nul
)
REM Activate virtual environment
if exist "venv\Scripts\activate.bat" (
call venv\Scripts\activate.bat
if !errorlevel! neq 0 (
call :print_error "Failed to activate virtual environment"
pause
exit /b 1
)
) else (
call :print_error "Virtual environment not found. Please run the script from the project root directory."
pause
exit /b 1
)
REM Upgrade pip
python -m pip install --upgrade pip
if !errorlevel! neq 0 (
call :print_error "Failed to upgrade pip"
pause
exit /b 1
)
REM Install requirements
python -m pip install -r requirements.txt
if !errorlevel! neq 0 (
call :print_error "Failed to install Python requirements"
pause
exit /b 1
)
call :print_success "Python dependencies installed successfully."
goto :eof
:install_node_deps
call :print_status "Installing Node.js dependencies in frontend/app1 directory..."
if not exist "frontend\app1" (
call :print_error "frontend\app1 directory not found."
pause
exit /b 1
)
cd frontend\app1
if !errorlevel! neq 0 (
call :print_error "Failed to change directory to frontend\app1"
pause
exit /b 1
)
if not exist "package.json" (
call :print_error "package.json not found in frontend\app1 directory."
pause
exit /b 1
)
npm install
if !errorlevel! neq 0 (
call :print_error "Failed to install Node.js dependencies"
pause
exit /b 1
)
call :print_success "Node.js dependencies installed successfully."
REM Return to project root
cd ..\..
if !errorlevel! neq 0 (
call :print_error "Failed to return to project root directory"
pause
exit /b 1
)
goto :eof
:start_backend
call :print_status "Starting backend API in simulation mode on port 8000..."
if not exist "backend\api" (
call :print_error "backend\api directory not found."
exit /b 1
)
REM Activate virtual environment
call venv\Scripts\activate.bat
REM Set simulation mode and start the backend in a new window
start "Network Performance Monitor - Backend (SIMULATION)" cmd /c "cd /d backend\api && set SIMULATION_MODE=true && !PYTHON_CMD! -m uvicorn main:app --host 127.0.0.1 --port 8000 --reload"
call :print_success "Backend API started successfully in simulation mode"
goto :eof
:start_frontend
call :print_status "Starting frontend on port 3000..."
if not exist "frontend\app1" (
call :print_error "frontend\app1 directory not found."
exit /b 1
)
cd frontend\app1
REM Start the frontend in development mode in a new window
start "Network Performance Monitor - Frontend" cmd /c "cd /d frontend\app1 && npm run dev"
call :print_success "Frontend started successfully."
REM Return to project root
cd ..\..
goto :eof
:cleanup_processes
call :print_status "Attempting to stop application processes..."
REM Try to end the backend and frontend processes
taskkill /f /im uvicorn.exe 2>nul
taskkill /f /im node.exe 2>nul
call :print_success "Process cleanup attempted."
goto :eof