283 lines
11 KiB
HTML
283 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Air Quality Dashboard</title>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
|
|
<script src="https://kit.fontawesome.com/34a5e0cdf4.js" crossorigin="anonymous"></script>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
|
|
<script src="//code.iconify.design/1/1.0.6/iconify.min.js"></script>
|
|
<style>
|
|
body {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
font-family: "Roboto", sans-serif;
|
|
}
|
|
|
|
.card_frame {
|
|
display: grid;
|
|
width: 750px;
|
|
height: 260px;
|
|
border-radius: 30px;
|
|
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.title_frame {
|
|
width: 750px;
|
|
height: 50px;
|
|
background-color: #ffffff;
|
|
border-top-right-radius: 30px;
|
|
border-top-left-radius: 30px;
|
|
}
|
|
|
|
.title_text {
|
|
font-size: 20px;
|
|
padding-top: 5px;
|
|
padding-bottom: 5px;
|
|
text-align: center;
|
|
color: rgb(57, 57, 57);
|
|
font-family: "Roboto", sans-serif;
|
|
align-self: center;
|
|
margin: 0;
|
|
}
|
|
|
|
.top_element {
|
|
display: grid;
|
|
grid-template-columns: 1fr 2fr 2fr;
|
|
background-color: #767676;
|
|
height: 190px;
|
|
}
|
|
|
|
.bottom_element {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
background-color: #ffffff;
|
|
border-bottom-right-radius: 30px;
|
|
border-bottom-left-radius: 30px;
|
|
height: 40px;
|
|
}
|
|
|
|
.buttom_left_frame {
|
|
display: flex;
|
|
grid-template-columns: 1fr 1fr;
|
|
justify-content: center;
|
|
justify-items: center;
|
|
align-items: center;
|
|
background-color: #ffffff;
|
|
border-bottom-left-radius: 30px;
|
|
height: 40px;
|
|
border-right: 1px solid #828282;
|
|
}
|
|
|
|
.buttom_right_frame {
|
|
display: flex;
|
|
grid-template-columns: 1fr 1fr;
|
|
justify-content: center;
|
|
justify-items: center;
|
|
align-items: center;
|
|
background-color: #ffffff;
|
|
border-bottom-right-radius: 30px;
|
|
height: 40px;
|
|
border-left: 1px solid #828282;
|
|
}
|
|
|
|
.buttom_text {
|
|
font-size: 20px;
|
|
font-weight: 500;
|
|
color: #000000;
|
|
margin-left: 10px;
|
|
font-family: "Roboto", sans-serif;
|
|
}
|
|
|
|
.health_icon_frame {
|
|
padding-top: 10px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
justify-items: center;
|
|
align-items: center;
|
|
background-color: #474747;
|
|
|
|
font-size: 100px;
|
|
color: #fff;
|
|
}
|
|
|
|
.health_text {
|
|
font-size: 20px;
|
|
font-weight: 500;
|
|
color: #ffffff;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.top_frame_element_frame {
|
|
display: flex;
|
|
;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
justify-items: center;
|
|
align-items: center;
|
|
background-color: #ffffff;
|
|
border-radius: 30px;
|
|
font-size: 100px;
|
|
margin-bottom: 7px;
|
|
margin-left: 7px;
|
|
width: 270px;
|
|
color: #939393;
|
|
align-self: flex-end;
|
|
}
|
|
|
|
.top_frame_value_text {
|
|
font-weight: 400;
|
|
color: #7a7a7a;
|
|
margin-left: 0px;
|
|
text-align: center;
|
|
font-size: 110px;
|
|
margin-top: 7px;
|
|
margin-bottom: 7px;
|
|
|
|
}
|
|
|
|
.top_frame_label_text {
|
|
font-size: 20px;
|
|
font-weight: 400;
|
|
color: #000000;
|
|
margin-left: 10px;
|
|
margin-top: 7px;
|
|
margin-bottom: 7px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<div class="card_frame">
|
|
<div class="title_frame">
|
|
<p class="title_text" id="title">Loading . . .</p>
|
|
<div class="top_element" id="top_element">
|
|
<div class="health_icon_frame" id="health_icon_frame">
|
|
<span class="iconify" data-icon="mdi-close" id="health_icon"></span>
|
|
<p class="health_text" , id="health_text">Loading</p>
|
|
</div>
|
|
<div class="top_frame_label_block">
|
|
<p class="top_frame_value_text" , id="outdoor-aqi">N/A</p>
|
|
<div class="top_frame_element_frame">
|
|
<p class="top_frame_label_text">Air Quality Index (US)</p>
|
|
</div>
|
|
</div>
|
|
<div class="top_frame_label_block">
|
|
<p class="top_frame_value_text" , id="outdoor-pm25">N/A</p>
|
|
<div class="top_frame_element_frame">
|
|
<p class="top_frame_label_text">PM2.5 (μg/m³)</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="bottom_element">
|
|
<div class="buttom_left_frame">
|
|
<i class="fa fa-thermometer-half" aria-hidden="true"></i>
|
|
<p class="buttom_text" id="outdoor-temp">Temperature: N/A</p>
|
|
</div>
|
|
<div class="buttom_right_frame">
|
|
<i class="fa fa-tint" aria-hidden="true"></i>
|
|
<p class="buttom_text" id="outdoor-humid">Humidity: N/A</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script>
|
|
$(document).ready(function () {
|
|
// Fetch data from API
|
|
function fetchData() {
|
|
var current_path = window.location.pathname;
|
|
// If current path end with index.html, remove it
|
|
|
|
// The API endpoint will have parameters like this:
|
|
// /card.html?location="satitm/satite"
|
|
// We will use that location parameter to fetch data from the correct API endpoint
|
|
api_prefix = "";
|
|
// Get the location parameter from the URL
|
|
var urlParams = new URLSearchParams(window.location.search);
|
|
var location = urlParams.get('location');
|
|
if (location != null) {
|
|
api_prefix = location + "/";
|
|
// Get the root domain of the current URL
|
|
var root_domain = window.location.protocol + "//" + window.location.host + "/";
|
|
// append the API prefix to the root domain
|
|
var api_url = root_domain + api_prefix + "get_data";
|
|
|
|
$.get(api_url, function (data) {
|
|
console.log(data);
|
|
|
|
// Set Title Location String
|
|
// The location is the location key in the JSON response
|
|
// It must also be appended with the timestamp
|
|
var update_time = data.time_outdoor
|
|
// Data is in format YYYY-MM-DD hh:mm:ss
|
|
// We only want hh:mm
|
|
var update_time = update_time.substring(11, 16);
|
|
$("#title").text(data.location+" @ "+update_time);
|
|
|
|
// Update outdoor AQI and PM2.5 values
|
|
$("#outdoor-aqi").text(data.aqi_outdoor);
|
|
$("#outdoor-pm25").text(data.pm25_outdoor.toFixed(1));
|
|
|
|
// Update outdoor temperature and humidity values
|
|
$("#outdoor-temp").text("Temperature: " + data.temperature_outdoor.toFixed(1) + "°C");
|
|
$("#outdoor-humid").text("Humidity: " + data.humidity_outdoor.toFixed(1) + "%");
|
|
|
|
// Is outdoor AQI healthy?
|
|
// If AQI is less than 50, it is healthy
|
|
// If AQI is between 50 and 100, it is unhealthy
|
|
// If AQI is more than 100, it is very unhealthy
|
|
var oldIcon = document.getElementById("health_icon");
|
|
oldIcon.parentNode.removeChild(oldIcon);
|
|
var newIcon = document.createElement("span");
|
|
newIcon.setAttribute("class", "iconify");
|
|
|
|
newIcon.setAttribute("data-inline", "false");
|
|
newIcon.id = "health_icon";
|
|
if (data.aqi_outdoor < 50) {
|
|
newIcon.setAttribute("data-icon", "mdi-heart");
|
|
Iconify.scanDOM();
|
|
$("#health_text").text("Healthy");
|
|
$("#top_element").css("background-color", "#97FF55");
|
|
$("#health_icon_frame").css("background-color", "#7bdb3f");
|
|
} else if (data.aqi_outdoor >= 50 && data.aqi_outdoor < 100) {
|
|
newIcon.setAttribute("data-icon", "mdi-smog");
|
|
Iconify.scanDOM();
|
|
$("#health_text").text("Moderate");
|
|
$("#top_element").css("background-color", "#FFD300");
|
|
$("#health_icon_frame").css("background-color", "#f9c300");
|
|
} else {
|
|
newIcon.setAttribute("data-icon", "mdi-skull-crossbones");
|
|
Iconify.scanDOM();
|
|
$("#health_text").text("Unhealthy");
|
|
$("#top_element").css("background-color", "#FF6969");
|
|
$("#health_icon_frame").css("background-color", "#A54444");
|
|
}
|
|
|
|
document.getElementById("health_icon_frame").appendChild(newIcon);
|
|
Iconify.scanDOM();
|
|
});
|
|
}
|
|
else {
|
|
$("#title").text("Please specify location in URL (?location=...)");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
fetchData(); // Fetch data immediately when the page loads
|
|
setInterval(fetchData, 10000); // Fetch data every 10 seconds
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |