Skip to content

Commit

Permalink
config and shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 14, 2024
1 parent 2c09ce9 commit a4bde9f
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 171 deletions.
Binary file modified __pycache__/server.cpython-312.pyc
Binary file not shown.
27 changes: 13 additions & 14 deletions run_lmcc_mac.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
#!/bin/bash

# Get the directory of the current script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Function to check and install Python
install_python() {
if ! command -v python3 &> /dev/null
then
if ! command -v python3 &> /dev/null; then
echo "Python3 could not be found. Installing Python3..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt update
sudo apt install -y python3 python3-pip
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Check if Homebrew is installed, install if not
if ! command -v brew &> /dev/null
then
if ! command -v brew &> /dev/null; then
echo "Homebrew could not be found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install python3
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
echo "Cygwin environment detected. Please install Python3 manually."
exit 1
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
echo "MSYS environment detected. Please install Python3 manually."
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then
echo "Please install Python3 manually on this OS."
exit 1
else
echo "Unknown OS type. Please install Python3 manually."
Expand All @@ -45,14 +41,17 @@ install_python
# Install Python dependencies
install_python_dependencies

# Installing npm dependencies
# Clone Repo
clone_tss

# Install npm dependencies
echo "Installing npm dependencies..."
npm install

# Starting the server
# Start the server
echo "Starting the server with npm start..."
npm start &

# Starting the FastAPI server
# Start the FastAPI server
echo "Starting the FastAPI server with uvicorn..."
uvicorn server:app --host 0.0.0.0 --port 8000 --reload
71 changes: 44 additions & 27 deletions run_lmcc_windows.ps1
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
# Check and install Python if not installed
# Function to check and install Python
function Install-Python {
if (-not (Get-Command python3 -ErrorAction SilentlyContinue)) {
Write-Output "Python3 could not be found. Installing Python3..."
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe" -OutFile "python-installer.exe"
Start-Process -FilePath "python-installer.exe" -ArgumentList "/quiet InstallAllUsers=1 PrependPath=1" -Wait
Remove-Item -Path "python-installer.exe" -Force

# Verify installation
if (-not (Get-Command python3 -ErrorAction SilentlyContinue)) {
Write-Output "Python3 installation failed. Please install Python3 manually."
exit 1
}
Invoke-WebRequest -Uri https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe -OutFile python-installer.exe
Start-Process -FilePath python-installer.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait
Remove-Item python-installer.exe
} else {
Write-Output "Python3 is already installed."
}
}

# Install Python dependencies
# Function to install Python dependencies
function Install-PythonDependencies {
Write-Output "Installing Python dependencies..."
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
pip3 install -r requirements.txt
}

# Install npm dependencies
function Install-NpmDependencies {
Write-Output "Installing npm dependencies..."
npm install
# Function to check and install Docker
function Install-Docker {
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Output "Docker could not be found. Installing Docker..."
Invoke-WebRequest -Uri https://desktop.docker.com/win/stable/Docker%20Desktop%20Installer.exe -OutFile docker-installer.exe
Start-Process -FilePath docker-installer.exe -ArgumentList '/quiet' -Wait
Remove-Item docker-installer.exe
} else {
Write-Output "Docker is already installed."
}
}

# Start the servers
function Start-Servers {
Write-Output "Starting the server with npm start..."
Start-Process -NoNewWindow -FilePath "npm" -ArgumentList "start"

Write-Output "Starting the FastAPI server with uvicorn..."
Start-Process -NoNewWindow -FilePath "python" -ArgumentList "-m uvicorn server:app --host 0.0.0.0 --port 8000 --reload"
# Function to run Docker container
function Run-DockerContainer {
Write-Output "Running Docker container..."
docker build -t tss_2024 .
docker run -it -p 14141:14141 --name tss_2024 tss_2024
}

# Execute functions
# Check and install Python
Install-Python

# Install Python dependencies
Install-PythonDependencies
Install-NpmDependencies
Start-Servers

# Check and install Docker
Install-Docker

# Run Docker container
Start-Job -ScriptBlock {
Run-DockerContainer
}

# Installing npm dependencies
Write-Output "Installing npm dependencies..."
npm install

# Starting the server
Write-Output "Starting the server with npm start..."
Start-Process -NoNewWindow npm start

# Starting the FastAPI server
Write-Output "Starting the FastAPI server with uvicorn..."
Start-Process -NoNewWindow uvicorn server:app --host 0.0.0.0 --port 8000 --reload
35 changes: 24 additions & 11 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@
logger = logging.getLogger(__name__)
app = FastAPI()

tss_ip = 'localhost:14141'
DATA_FILE = 'tss_data.json'
CONFIG_FILE = 'config_keys.json'

# Load config to get TSS_IP
if os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, 'r') as f:
config_data = json.load(f)
tss_ip = config_data.get("TSS_IP", 'localhost:14141')
else:
tss_ip = 'localhost:14141'

# Configure CORS
app.add_middleware(
CORSMiddleware,
Expand Down Expand Up @@ -84,16 +91,22 @@ async def periodic_fetch_and_store():
eva_url = f"http://{tss_ip}/json_data/teams/0/EVA.json"
telemetry_url = f"http://{tss_ip}/json_data/teams/0/TELEMETRY.json"
while True:
eva_data = await fetch_json(eva_url)
telemetry_data = await fetch_json(telemetry_url)
if eva_data and telemetry_data: # Ensure both data sets are fetched successfully
combined_data = {
"timestamp": datetime.now().isoformat(),
"eva": eva_data,
"telemetry": telemetry_data
}
with open(DATA_FILE, 'w') as f:
json.dump(combined_data, f)
try:
eva_data = await fetch_json(eva_url)
telemetry_data = await fetch_json(telemetry_url)
if eva_data and telemetry_data: # Ensure both data sets are fetched successfully
combined_data = {
"timestamp": datetime.now().isoformat(),
"eva": eva_data,
"telemetry": telemetry_data
}
with open(DATA_FILE, 'w') as f:
json.dump(combined_data, f)
logger.info("Data fetched and stored successfully.")
else:
logger.warning("One or both data sets were not fetched successfully.")
except Exception as e:
logger.error(f"An error occurred during periodic fetch: {e}")
await asyncio.sleep(1) # Sleep for a second before the next fetch

@app.get("/data")
Expand Down
17 changes: 17 additions & 0 deletions src/pages/constant/Modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import './constant.css';

const Modal = ({ isVisible, hideModal, content }) => {
if (!isVisible) return null;

return (
<div className="modal" style={{ display: 'flex' }}>
<div className="modal-content">
<span className="close" onClick={hideModal}>&times;</span>
{content}
</div>
</div>
);
};

export default Modal;
Loading

0 comments on commit a4bde9f

Please sign in to comment.