Skip to content

Commit

Permalink
new api
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 22, 2024
1 parent 776b999 commit 79ca551
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/json_databases/DCUUIA.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"timestamp": "2024-05-22T02:15:24.677766", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}}
{"timestamp": "2024-05-22T02:37:43.559983", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}}
16 changes: 14 additions & 2 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async def periodic_fetch_and_store():
dcu_url = f"http://{tss_ip}/json_data/DCU.json"
uia_url = f"http://{tss_ip}/json_data/UIA.json"
warnings_url = f'http://{tss_ip}/json_data/ERROR.json'
spec_url = f'http://{tss_ip}/json_data/SPEC.json'

while True:
print('running')
Expand All @@ -104,13 +105,15 @@ async def periodic_fetch_and_store():
eva_data = await fetch_json(eva_url)
telemetry_data = await fetch_json(telemetry_url)
warnings_data = await fetch_json(warnings_url)
spec_data = await fetch_json(spec_url)

if eva_data and telemetry_data and warnings_data:
combined_data = {
"timestamp": datetime.now().isoformat(),
"eva": eva_data,
"telemetry": telemetry_data,
"warnings": warnings_data
"warnings": warnings_data,
"spec": spec_data
}
with open(DATA_FILE, 'w') as f:
json.dump(combined_data, f)
Expand Down Expand Up @@ -148,7 +151,16 @@ async def get_warnings():
data = json.load(f)
return data['warnings']
else:
raise HTTPException(status_code=404, detail="DCUUIA.json not found")
raise HTTPException(status_code=404, detail="DATA.json not found")

@app.get("/spec_scans")
async def get_warnings():
if os.path.exists(DATA_FILE):
with open(DATA_FILE, 'r') as f:
data = json.load(f)
return data['spec']
else:
raise HTTPException(status_code=404, detail="DATA.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
28 changes: 25 additions & 3 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Navbar = () => {
const [showModal, setShowModal] = useState(false);
const [isVisible, setIsVisible] = useState(false);
const [warnings, setWarnings] = useState([]);
const [acknowledgedWarnings, setAcknowledgedWarnings] = useState({});

useEffect(() => {
const fetchWarnings = async () => {
Expand All @@ -16,10 +17,25 @@ const Navbar = () => {
.filter(([key, value]) => value)
.map(([key]) => key);

if (activeWarnings.length > 0) {
setWarnings(activeWarnings);
// Reset acknowledgment if a warning changes from false to true
const newAcknowledgedWarnings = { ...acknowledgedWarnings };
Object.entries(data.error).forEach(([key, value]) => {
if (!value) {
newAcknowledgedWarnings[key] = false;
}
});

setAcknowledgedWarnings(newAcknowledgedWarnings);

// Set warnings to be displayed
const warningsToDisplay = activeWarnings.filter(warning => !newAcknowledgedWarnings[warning]);
setWarnings(warningsToDisplay);

if (warningsToDisplay.length > 0) {
setShowModal(true);
setIsVisible(true);
} else {
setShowModal(false);
}
} catch (error) {
console.error('Error fetching warnings:', error);
Expand All @@ -28,9 +44,15 @@ const Navbar = () => {

const interval = setInterval(fetchWarnings, 3000); // Fetch warnings every 3 seconds
return () => clearInterval(interval);
}, []);
}, [acknowledgedWarnings]);

const closeModal = () => {
const newAcknowledgedWarnings = { ...acknowledgedWarnings };
warnings.forEach(warning => {
newAcknowledgedWarnings[warning] = true;
});

setAcknowledgedWarnings(newAcknowledgedWarnings);
setIsVisible(false);
setTimeout(() => setShowModal(false), 500); // Wait for the fade-out transition to complete
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages-style/rover.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.page-container {
display: grid;
grid-template-rows: auto 1fr;
height: 90vh;
width: 100vw;
}


.header-rover {
text-align: center;
padding: 20px;
Expand Down
7 changes: 6 additions & 1 deletion src/pages/constant/constant.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
width: 33.333%;
}

#UIADCU {
height: 90%;
margin-left: 10px;
}

#topbar {
height: 100%;
width: 100%;
Expand Down Expand Up @@ -115,7 +120,7 @@
flex-direction: row;
width: 100%;
height: 30vh;
margin-bottom: 20px;
margin-bottom: 40px;
}

.bottom-half {
Expand Down

0 comments on commit 79ca551

Please sign in to comment.