Skip to content

Commit

Permalink
cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 20, 2024
1 parent b01de10 commit aa283db
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 119 deletions.
1 change: 1 addition & 0 deletions server/json_databases/DCUUIA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"timestamp": "2024-05-20T05:46:01.705067", "dcu": {"eva1": {"batt": false, "oxy": true, "comm": false, "fan": true, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": true, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": false, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": false, "eva2_water_waste": false, "oxy_vent": false, "depress": false}}
2 changes: 1 addition & 1 deletion server/json_databases/geojson/nav_path.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-95.08141793795379, 29.564580908696907], [-95.0814563954045, 29.56467675123534], [-95.0814797733473, 29.56480640650252], [-95.08157335667411, 29.564815758720055], [-95.08157234926806, 29.56492419510491], [-95.08157315565839, 29.564959141875754]]}, "properties": {"name": "Rover Path"}}]}
{}
2 changes: 1 addition & 1 deletion server/json_databases/geojson/user_pins.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"Name": "hey"}, "geometry": {"coordinates": [-95.08133613847313, 29.56504641409886], "type": "Point"}, "id": 102}]}
{"type": "FeatureCollection", "features": []}
50 changes: 44 additions & 6 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Data
DATA_FILE = './server/json_databases/tss_data.json'
ROCK_LUT = './server/json_databases/ROCK_DATA_FINAL.json'
DCU_UIA_FILE = './server/json_databases/DCUUIA.json'
# GEOJson Files for mapping
BOUNDARY_LINES_FILE = './server/json_databases/geojson/boundary_lines.json'
DEFAULT_PINS_FILE = './server/json_databases/geojson/default_pins.json'
Expand Down Expand Up @@ -66,24 +67,38 @@ async def fetch_json(url: str):
return None
return response.json()

def initialize_files():
# Create DATA_FILE if it does not exist
if not os.path.exists(DATA_FILE):
with open(DATA_FILE, 'w') as f:
json.dump({}, f)
# Create DCU_UIA_FILE if it does not exist
if not os.path.exists(DCU_UIA_FILE):
with open(DCU_UIA_FILE, 'w') as f:
json.dump({}, f)


@app.on_event("startup")
async def startup_event():
initialize_database_files()
task = asyncio.create_task(periodic_fetch_and_store())
await asyncio.sleep(1)
initialize_files() # Ensure files are created if they do not exist
scheduler = AsyncIOScheduler()
scheduler.add_job(fetch_and_update_positions, 'interval', seconds=3)
scheduler.add_job(periodic_fetch_and_store, 'interval', seconds=10) # Adjust the interval as needed
scheduler.start()

async def periodic_fetch_and_store():
global team_number
team_number = config_data.get("EV1_TEAM_ID")
while team_number is None:
await asyncio.sleep(1)

eva_url = f"http://{tss_ip}/json_data/teams/{team_number}/EVA.json"
telemetry_url = f"http://{tss_ip}/json_data/teams/{team_number}/TELEMETRY.json"
dcu_url = f"http://{tss_ip}/json_data/DCU.json"
uia_url = f"http://{tss_ip}/json_data/UIA.json"

while True:
try:
# Fetch EVA and telemetry data
eva_data = await fetch_json(eva_url)
telemetry_data = await fetch_json(telemetry_url)
if eva_data and telemetry_data:
Expand All @@ -94,10 +109,33 @@ async def periodic_fetch_and_store():
}
with open(DATA_FILE, 'w') as f:
json.dump(combined_data, f)

# Fetch DCU and UIA data
dcu_data = await fetch_json(dcu_url)
uia_data = await fetch_json(uia_url)
if dcu_data and uia_data:
combined_dcu_uia_data = {
"timestamp": datetime.now().isoformat(),
"dcu": dcu_data["dcu"],
"uia": uia_data["uia"]
}
with open(DCU_UIA_FILE, 'w') as f:
json.dump(combined_dcu_uia_data, f)

except Exception as e:
pass
await asyncio.sleep(1)
print(f"Error fetching or saving data: {e}")

await asyncio.sleep(1) # Adjust the sleep interval as needed

@app.get("/dcu_uia")
async def get_dcu_uia():
if os.path.exists(DCU_UIA_FILE):
with open(DCU_UIA_FILE, 'r') as f:
data = json.load(f)
return data
else:
raise HTTPException(status_code=404, detail="DCUUIA.json not found")

def utm_to_latlon(easting, northing, zone_number=15, zone_letter='R'):
return utm.to_latlon(easting, northing, zone_number, zone_letter)

Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function App() {
<Route path="/egress" element={<Egress />} />
<Route path="/nav" element={<Nav />} />
<Route path="/equipment" element={<Equipment />} />
<Route path="/rocks" element={<Rocks />} />
{/* <Route path="/rocks" element={<Rocks />} /> */}
<Route path="/rover" element={<Rover />} />
<Route path="/ingress" element={<Ingress />} />
</Routes>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const Navbar = () => {
<Link className="NavLink" to="/Equipment" activeStyle={{ color: '#69b3e7' }}>
Equipment
</Link>
<Link className="NavLink" to="/Rocks" activeStyle={{ color: '#69b3e7' }}>
{/* <Link className="NavLink" to="/Rocks" activeStyle={{ color: '#69b3e7' }}>
Rocks
</Link>
</Link> */}
<Link className="NavLink" to="/Rover" activeStyle={{ color: '#69b3e7' }}>
Rover
</Link>
Expand Down
80 changes: 80 additions & 0 deletions src/pages/constant/DCUUIA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { useState, useEffect } from 'react';
import "./constant.css";
import "./dcuuia.css";

const DCUUIA = () => {
const [data, setData] = useState(null);
const [hasError, setHasError] = useState(false);

useEffect(() => {
const fetchData = () => {
fetch('http://localhost:8000/dcu_uia')
.then(response => response.json())
.then(data => {
setData(data);
setHasError(false);
})
.catch(error => {
console.error('Error fetching DCU/UIA data:', error);
setHasError(true);
});
};

fetchData();
const interval = setInterval(fetchData, 10000); // Adjust the interval as needed
return () => clearInterval(interval);
}, []);

if (hasError) {
return <div>Error fetching DCU/UIA data</div>;
}

if (!data) {
return <div>Loading...</div>;
}

const renderStatus = (status) => (
<span id={status ? 'status-indicator-green' : 'status-indicator-red'}>
{status ? 'Online' : 'Offline'}
</span>
);

return (
<div id="dcu-uia-container">
<div id="status-section">
<h3>DCU Status</h3>
<div id="status-grid">
<div id="status-item">EVA1 Battery: {renderStatus(data.dcu.eva1.batt)}</div>
<div id="status-item">EVA1 Oxygen: {renderStatus(data.dcu.eva1.oxy)}</div>
<div id="status-item">EVA1 Comm: {renderStatus(data.dcu.eva1.comm)}</div>
<div id="status-item">EVA1 Fan: {renderStatus(data.dcu.eva1.fan)}</div>
<div id="status-item">EVA1 Pump: {renderStatus(data.dcu.eva1.pump)}</div>
<div id="status-item">EVA1 CO2: {renderStatus(data.dcu.eva1.co2)}</div>
<div id="status-item">EVA2 Battery: {renderStatus(data.dcu.eva2.batt)}</div>
<div id="status-item">EVA2 Oxygen: {renderStatus(data.dcu.eva2.oxy)}</div>
<div id="status-item">EVA2 Comm: {renderStatus(data.dcu.eva2.comm)}</div>
<div id="status-item">EVA2 Fan: {renderStatus(data.dcu.eva2.fan)}</div>
<div id="status-item">EVA2 Pump: {renderStatus(data.dcu.eva2.pump)}</div>
<div id="status-item">EVA2 CO2: {renderStatus(data.dcu.eva2.co2)}</div>
</div>
</div>
<div id="status-section">
<h3>UIA Status</h3>
<div id="status-grid">
<div id="status-item">EVA1 Power: {renderStatus(data.uia.eva1_power)}</div>
<div id="status-item">EVA1 Oxygen: {renderStatus(data.uia.eva1_oxy)}</div>
<div id="status-item">EVA1 Water Supply: {renderStatus(data.uia.eva1_water_supply)}</div>
<div id="status-item">EVA1 Water Waste: {renderStatus(data.uia.eva1_water_waste)}</div>
<div id="status-item">EVA2 Power: {renderStatus(data.uia.eva2_power)}</div>
<div id="status-item">EVA2 Oxygen: {renderStatus(data.uia.eva2_oxy)}</div>
<div id="status-item">EVA2 Water Supply: {renderStatus(data.uia.eva2_water_supply)}</div>
<div id="status-item">EVA2 Water Waste: {renderStatus(data.uia.eva2_water_waste)}</div>
<div id="status-item">Oxygen Vent: {renderStatus(data.uia.oxy_vent)}</div>
<div id="status-item">Depress: {renderStatus(data.uia.depress)}</div>
</div>
</div>
</div>
);
};

export default DCUUIA;
2 changes: 2 additions & 0 deletions src/pages/constant/constant.css
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@
}

.modal-content {
align-items: center;
justify-content: center;
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/constant/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MapboxComponent from '../../components/Map.js'; // Ensure this path is co
import Modal from './Modal';
import MapModal from './MapModal';
import TopBar from './Topbar';
import DCUUIA from './DCUUIA'; // Import the new component

function Constant() {
const [telemetryData, setTelemetryData] = useState(null);
Expand Down Expand Up @@ -127,7 +128,7 @@ function Constant() {
<div className="bottom-half">
<div id="EV"><EVData evNumber={selectedEV} /></div>
<div id="ConstantMap"><MapboxComponent zoom={18} /></div>
<div id="UIADCU">UIA DCU DATA</div>
<div id="UIADCU"><DCUUIA /></div> {/* Include the new component */}
</div>
<Modal
isVisible={isAlertModalVisible}
Expand Down
68 changes: 68 additions & 0 deletions src/pages/constant/dcuuia.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#dcu-uia-container {
padding: 20px;
background-color: #f5f5f5;
border-radius: 12px; /* Softer rounded edges */
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
height: 100%;
}

h2 {
text-align: center;
margin-bottom: 20px;
font-size: 1.25rem; /* Slightly smaller font */
}

#status-section {
margin-bottom: 20px;
padding: 0;
}

#status-section h3 {
margin-bottom: 5px; /* Adjusted for smaller spacing */
margin-top: 0;
color: #333;
font-size: 1rem; /* Slightly smaller font */
}

#status-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 5px;
}

#status-item {
display: flex;
height: 35px; /* Slightly shorter height */
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 5px; /* Slightly smaller padding */
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px; /* Softer rounded edges */
font-size: 0.9rem; /* Slightly smaller font */
}

#status-indicator {
height: 20px;
width: 50px;
padding: 3px 10px;
border-radius: 8px; /* Softer rounded edges */
color: white;
border: 1px solid #ddd;
font-weight: bold;
font-size: 0.9rem; /* Slightly smaller font */
}

#status-indicator-green {
background-color: #4caf50;
padding: 5px;
border-radius: 8px; /* Softer rounded edges */
}

#status-indicator-red {
background-color: #f44336;
padding: 5px;
border-radius: 8px; /* Softer rounded edges */
}

Loading

0 comments on commit aa283db

Please sign in to comment.