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() {