commit 3f52ddae4a7441bd9016f9708cb69aba6378387b
parent 793caa0525d4135d4ad19dec4379ab7cee6bd425
Author: Kninteman <[email protected]>
Date: Mon, 12 Jun 2023 14:21:36 +0200
Merge branch 'datatowebsite' of https://github.com/friedelschoen/iwa-panda into datatowebsite
Diffstat:
3 files changed, 40 insertions(+), 42 deletions(-)
diff --git a/Model/Key.php b/Model/Key.php
@@ -4,20 +4,19 @@ Class Key{
if($key['data'] == ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk') {
$key1 = new Key;
$key1->retrieveZooData($key);
- } else if($key['data'] == '?'){
+ } else if($key['data'] == ':ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684'){
$key1 = new Key;
$key1->retrieveRBData($key);
+ } else {
+ echo("You have no access here!");
}
}
function retrieveZooData($key){
- if ($key['data'] != ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'){
- echo 'no';
- } else{
$db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
$t = new Lollipop\Template();
$weather_data = [];
- $query = "SELECT distinct temperature, dew_point, wind_speed, nl.name as city
+ $query = "SELECT distinct temperature, wind_speed, nl.name as city
FROM weather_data wd
JOIN station s ON wd.station_name = s.name
JOIN contract_station cs ON cs.station_name = s.name
@@ -26,8 +25,8 @@ Class Key{
JOIN geolocation geo ON geo.country_code = co.country_code
JOIN contract c ON cs.contract_id = c.contract_id
WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
- GROUP BY nl.name
- LIMIT 5";
+ GROUP BY nl.name";
+
$stmt = mysqli_prepare($db, $query);
$stmt->execute();
$data = $stmt->get_result();
@@ -42,43 +41,40 @@ Class Key{
header('Content-Type: application/json');
echo json_encode($weather_data);
}
- }
- function retrieveRBData($key){
- if ($key['data'] != ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'){
- echo 'no';
- } else{
- $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
- $t = new Lollipop\Template();
- $weather_data = [];
- $query = "SELECT distinct temperature, dew_point, nl.name as city
- FROM weather_data wd
- JOIN station s ON wd.station_name = s.name
- JOIN contract_station cs ON cs.station_name = s.name
- JOIN nearestlocation nl ON nl.station_name = s.name
- JOIN country co ON co.country_code = nl.country_code
- JOIN geolocation geo ON geo.country_code = co.country_code
- JOIN contract c ON cs.contract_id = c.contract_id
- WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
- LIMIT 5";
- $stmt = mysqli_prepare($db, $query);
- $stmt->execute();
- $data = $stmt->get_result();
- while ($row = $data->fetch_assoc()) {
- $humidity = humid($row["temperature"], $row["dew_point"]);
- $weather_data[] = [
- 'humidity' => $humidity,
- 'location' => $row['city']
- ];
- }
+ function retrieveRBData($key){
+ $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
+ $t = new Lollipop\Template();
+ $weather_data = [];
+ $query = "SELECT distinct temperature, dew_point, nl.name as city
+ FROM weather_data wd
+ JOIN station s ON wd.station_name = s.name
+ JOIN contract_station cs ON cs.station_name = s.name
+ JOIN nearestlocation nl ON nl.station_name = s.name
+ JOIN country co ON co.country_code = nl.country_code
+ JOIN geolocation geo ON geo.country_code = co.country_code
+ JOIN contract c ON cs.contract_id = c.contract_id
+ WHERE c.token = 'ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684'
+ group by nl.name";
+ $stmt = mysqli_prepare($db, $query);
+ $stmt->execute();
+ $data = $stmt->get_result();
- header('Content-Type: application/json');
- echo json_encode($weather_data);
+ while ($row = $data->fetch_assoc()) {
+ $humidity = humid($row["temperature"], $row["dew_point"]);
+ $weather_data[] = [
+ 'humidity' => $humidity,
+ 'location' => $row['city']
+ ];
}
+
+ header('Content-Type: application/json');
+ echo json_encode($weather_data);
}
+
}
function windchill($temp, $wind): float
{
diff --git a/js/panda.js b/js/panda.js
@@ -8,10 +8,12 @@ fetch(`http://localhost:8080/api/${token}`)
windchills.push(weatherdata)
})
windchills.sort(jsonSorter('windchill'));
+ let slicedArray = windchills.slice(0, 5);
+
let weatherList = document.getElementById('weather-list');
- windchills.forEach(item => {
+ slicedArray.forEach(item => {
let listItem = document.createElement('li');
- listItem.textContent = item['windchill'] + " degrees Celsius";
+ listItem.textContent = item['windchill'] + " degrees Celsius, Location: " + item['location'];
weatherList.appendChild(listItem);
})
});
@@ -20,9 +22,9 @@ fetch(`http://localhost:8080/api/${token}`)
function jsonSorter(key) {
return function(a, b) {
if (a[key] > b[key]) {
- return -1;
- } else if (a[key] < b[key]) {
return 1;
+ } else if (a[key] < b[key]) {
+ return -1;
}
return 0;
}
diff --git a/views/dashboard.html b/views/dashboard.html
@@ -30,7 +30,7 @@
<div class="content-title">
<h2>Top 5 - Zoo's</h2>
</div>
- <ol class="fancy-list" id="weather-list"></ol>
+ <ol id="weather-list"></ol>
</div>
</div>