From aa283db5a17cc1f3030a1eaccde28c386fe01136 Mon Sep 17 00:00:00 2001 From: Jonah Aden <151240959+adenjonah@users.noreply.github.com> Date: Mon, 20 May 2024 05:46:02 -0500 Subject: [PATCH] cosmetics --- server/json_databases/DCUUIA.json | 1 + server/json_databases/geojson/nav_path.json | 2 +- server/json_databases/geojson/user_pins.json | 2 +- server/server.py | 50 ++++++++- src/App.js | 2 +- src/components/Navbar.js | 4 +- src/pages/constant/DCUUIA.js | 80 +++++++++++++ src/pages/constant/constant.css | 2 + src/pages/constant/constant.js | 3 +- src/pages/constant/dcuuia.css | 68 +++++++++++ src/pages/focus/nav.js | 112 +------------------ 11 files changed, 207 insertions(+), 119 deletions(-) create mode 100644 server/json_databases/DCUUIA.json create mode 100644 src/pages/constant/DCUUIA.js create mode 100644 src/pages/constant/dcuuia.css diff --git a/server/json_databases/DCUUIA.json b/server/json_databases/DCUUIA.json new file mode 100644 index 0000000..e6b5343 --- /dev/null +++ b/server/json_databases/DCUUIA.json @@ -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}} \ No newline at end of file diff --git a/server/json_databases/geojson/nav_path.json b/server/json_databases/geojson/nav_path.json index bd3349d..9e26dfe 100644 --- a/server/json_databases/geojson/nav_path.json +++ b/server/json_databases/geojson/nav_path.json @@ -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"}}]} \ No newline at end of file +{} \ No newline at end of file diff --git a/server/json_databases/geojson/user_pins.json b/server/json_databases/geojson/user_pins.json index 0107a9d..188bb9e 100644 --- a/server/json_databases/geojson/user_pins.json +++ b/server/json_databases/geojson/user_pins.json @@ -1 +1 @@ -{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"Name": "hey"}, "geometry": {"coordinates": [-95.08133613847313, 29.56504641409886], "type": "Point"}, "id": 102}]} \ No newline at end of file +{"type": "FeatureCollection", "features": []} \ No newline at end of file diff --git a/server/server.py b/server/server.py index 63e23d4..8b0ff19 100644 --- a/server/server.py +++ b/server/server.py @@ -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' @@ -66,13 +67,22 @@ 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(): @@ -80,10 +90,15 @@ async def periodic_fetch_and_store(): 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: @@ -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) diff --git a/src/App.js b/src/App.js index d75ab91..ce40f8f 100644 --- a/src/App.js +++ b/src/App.js @@ -25,7 +25,7 @@ function App() { } /> } /> } /> - } /> + {/* } /> */} } /> } /> diff --git a/src/components/Navbar.js b/src/components/Navbar.js index 4a3d93a..eb95564 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -23,9 +23,9 @@ const Navbar = () => { Equipment - + {/* Rocks - + */} Rover diff --git a/src/pages/constant/DCUUIA.js b/src/pages/constant/DCUUIA.js new file mode 100644 index 0000000..2af7de7 --- /dev/null +++ b/src/pages/constant/DCUUIA.js @@ -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
Error fetching DCU/UIA data
; + } + + if (!data) { + return
Loading...
; + } + + const renderStatus = (status) => ( + + {status ? 'Online' : 'Offline'} + + ); + + return ( +
+
+

DCU Status

+
+
EVA1 Battery: {renderStatus(data.dcu.eva1.batt)}
+
EVA1 Oxygen: {renderStatus(data.dcu.eva1.oxy)}
+
EVA1 Comm: {renderStatus(data.dcu.eva1.comm)}
+
EVA1 Fan: {renderStatus(data.dcu.eva1.fan)}
+
EVA1 Pump: {renderStatus(data.dcu.eva1.pump)}
+
EVA1 CO2: {renderStatus(data.dcu.eva1.co2)}
+
EVA2 Battery: {renderStatus(data.dcu.eva2.batt)}
+
EVA2 Oxygen: {renderStatus(data.dcu.eva2.oxy)}
+
EVA2 Comm: {renderStatus(data.dcu.eva2.comm)}
+
EVA2 Fan: {renderStatus(data.dcu.eva2.fan)}
+
EVA2 Pump: {renderStatus(data.dcu.eva2.pump)}
+
EVA2 CO2: {renderStatus(data.dcu.eva2.co2)}
+
+
+
+

UIA Status

+
+
EVA1 Power: {renderStatus(data.uia.eva1_power)}
+
EVA1 Oxygen: {renderStatus(data.uia.eva1_oxy)}
+
EVA1 Water Supply: {renderStatus(data.uia.eva1_water_supply)}
+
EVA1 Water Waste: {renderStatus(data.uia.eva1_water_waste)}
+
EVA2 Power: {renderStatus(data.uia.eva2_power)}
+
EVA2 Oxygen: {renderStatus(data.uia.eva2_oxy)}
+
EVA2 Water Supply: {renderStatus(data.uia.eva2_water_supply)}
+
EVA2 Water Waste: {renderStatus(data.uia.eva2_water_waste)}
+
Oxygen Vent: {renderStatus(data.uia.oxy_vent)}
+
Depress: {renderStatus(data.uia.depress)}
+
+
+
+ ); +}; + +export default DCUUIA; diff --git a/src/pages/constant/constant.css b/src/pages/constant/constant.css index 1d0211c..af2b0fc 100644 --- a/src/pages/constant/constant.css +++ b/src/pages/constant/constant.css @@ -188,6 +188,8 @@ } .modal-content { + align-items: center; + justify-content: center; background-color: #fefefe; margin: 15% auto; padding: 20px; diff --git a/src/pages/constant/constant.js b/src/pages/constant/constant.js index 149a97b..ab9f16c 100644 --- a/src/pages/constant/constant.js +++ b/src/pages/constant/constant.js @@ -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); @@ -127,7 +128,7 @@ function Constant() {
-
UIA DCU DATA
+
{/* Include the new component */}
{ - fetch('http://localhost:8000/get_geojson') - .then(response => response.json()) - .then(data => { - const validPoints = data.features.filter(point => - point.geometry.type === 'Point' && point.properties.Name - ); - setPoints(validPoints); - }) - .catch(error => console.error('Error fetching points:', error)); - }, []); - - useEffect(() => { - if (startId && endId) { - calculateShortestPath(startId, endId); - intervalRef.current = setInterval(() => { - calculateShortestPath(startId, endId); - }, 3000); - - return () => clearInterval(intervalRef.current); - } - }, [startId, endId]); - - const calculateShortestPath = (startId, endId) => { - const data = { - start_id: startId, - end_id: endId - }; - - fetch('http://localhost:8000/get_shortest_path', { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify(data) - }) - .then(response => response.json()) - .then(data => { - const distance = data.distance; - if (distance < 10) { - clearInterval(intervalRef.current); - } - console.log('Distance:', distance); - }) - .catch((error) => { - console.error('Error:', error); - }); - }; - - const handleFormSubmit = (e) => { - e.preventDefault(); - if (startId && endId) { - clearInterval(intervalRef.current); - calculateShortestPath(startId, endId); - } - }; - +function nav() { return (