Frontend now displays environment temperature. Moved from using '-1' and an 'invalid' indicator to nulls, which in hindsight is what it should've been before. Old habits die hard.

This commit is contained in:
Innovation 2024-03-30 13:28:29 -05:00
parent 4e43c799f7
commit f579dd4c16
2 changed files with 49 additions and 17 deletions

View file

@ -4,9 +4,9 @@ import uuid
app = Flask(__name__)
# Vitals
vitalsHeartrate = -1
vitalsOxygen = -1
vitalsBodytemp = -1.0
vitalsHeartrate = None
vitalsOxygen = None
vitalsBodytemp = None
@app.route('/api/vitals/heartrate')
def getVitalsHeartrate():
@ -89,7 +89,7 @@ def setVitals():
return 'Information set successfully', 204
# Fitness
fitnessSteps = -1
fitnessSteps = None
@app.route('/api/fitness/steps')
def getSteps():
@ -220,8 +220,8 @@ def resetCyberwareMalfunction():
return 'Not Implemented', 501
# Environment data
environmentTemperature = -1
environmentHumidity = -1
environmentTemperature = None
environmentHumidity = None
@app.route('/api/environment')
def getEnvironment():

View file

@ -65,6 +65,10 @@
border: 1px solid #F00; /* TODO: Remove this later */
}
#environmentTemperature {
text-align: right;
}
/* Below are all Map styling */
#map {
margin-right: 2px;
@ -183,7 +187,7 @@
</div>
<div id="projectName">
<p>K.A.T.I.E.</p>
<p style="text-align: right;">0&deg;C</p>
<div id="environmentTemperature"><p>&zwnj;</p></div>
</div>
</div>
<div id="mapProper">
@ -215,6 +219,7 @@
// TODO: Make baseUrl be set by Flask
var baseUrl = "http://localhost:5000";
var vitalsUrl = baseUrl + "/api/vitals";
var environmentUrl = baseUrl + "/api/environment";
// Malfunction Messages (human-friendly)
malfunctionMessage = [ "API Malfunction" ]
@ -226,7 +231,6 @@
}
function setVitals(vitalsData) {
//var data = JSON.parse(vitalsData)
heartrate = vitalsData["0"]["heartrate"];
oxygen = vitalsData["0"]["oxygen"];
bodytemp = vitalsData["0"]["bodytemp"];
@ -237,29 +241,49 @@
}
function setVitalsHeartrate(heartrate) {
if(heartrate > 0) {
document.getElementById("heartrate").innerHTML = "<p>Heartrate: " + heartrate + " BPM</p>";
} else {
if(heartrate === null) {
document.getElementById("heartrate").innerHTML = "";
} else {
document.getElementById("heartrate").innerHTML = "<p>Heartrate: " + heartrate + " BPM</p>";
}
}
function setVitalsOxygen(oxygen) {
if(oxygen > 0) {
document.getElementById("oxygen").innerHTML = "<p>Oxygen: " + oxygen + "% O2</p>";
} else {
if(oxygen === null) {
document.getElementById("oxygen").innerHTML = "";
} else {
document.getElementById("oxygen").innerHTML = "<p>Oxygen: " + oxygen + "% O2</p>";
}
}
function setVitalsBodytemp(bodytemp) {
if(bodytemp > 0) {
document.getElementById("bodyTemperature").innerHTML = "<p>Body Temp: " + bodytemp + "°C</p>";
} else {
if(bodytemp === null) {
document.getElementById("bodyTemperature").innerHTML = "";
} else {
document.getElementById("bodyTemperature").innerHTML = "<p>Body Temp: " + bodytemp + "°C</p>";
}
}
function setEnvironment(environmentData) {
temperature = environmentData["0"]["temperature"];
humidity = environmentData["0"]["humidity"];
setEnvironmentTemperature(temperature);
setEnvironmentHumidity(humidity);
}
function setEnvironmentTemperature(temperature) {
if(temperature === null) {
document.getElementById("environmentTemperature").innerHTML = "<p>&zwnj;</p>";
} else {
document.getElementById("environmentTemperature").innerHTML = "<p>" + temperature + "°C";
}
}
function setEnvironmentHumidity(humidity) {
}
function updateAll() {
$.get(vitalsUrl, (data, status) => {
if(status == "success") {
@ -268,6 +292,14 @@
displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status);
}
});
$.get(environmentUrl, (data, status) => {
if(status == "success") {
setEnvironment(data);
} else {
displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status);
}
});
//stopInterval(t)
}
var t=setInterval(updateAll, 1000)