iwa-panda2

Manage Weather Data by International Weather Agency (Version 2)
Log | Files | Refs | README

commit e8ed020c01605164cc1d5dbb75b438ed2e8040a9
parent 2c12df35e2cc712f6b59546e9070ac8541c79023
Author: DennyVB <[email protected]>
Date:   Sat, 17 Jun 2023 14:46:45 +0200

History data geupdate

Geeft nu beide data weer op website
+ key wordt nu daadwerkelijk meegegeven in functie

Diffstat:
MController/hdata/hdata.php | 4++--
MModel/Key.php | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/Controller/hdata/hdata.php b/Controller/hdata/hdata.php @@ -2,9 +2,9 @@ function make_table(){ $key = new Key(); if (isset($_GET['downloadXml'])) { - return $key->retrieveHData(['data' => ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'], true); + return $key->retrieveHData('3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk', true); } else { - return $key->retrieveHData(['data' => ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk']); + return $key->retrieveHData('3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'); } } ?> diff --git a/Model/Key.php b/Model/Key.php @@ -1,5 +1,7 @@ <?php Class Key{ + + protected array $data; function retrieveData($key){ $validKeys = [ ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk' => 'retrieveZooData', @@ -69,12 +71,74 @@ Class Key{ 'location' => $row['city'], 'datetime' => $row['date_time'] ]; + } header('Content-Type: application/json'); echo json_encode($weather_data); } + + function retrieveHumidityTable($key, $generateXml = false) + { + $html = '<table>'; + $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2"); + $weather_data = []; + $query = "SELECT distinct temperature, dew_point, nl.name as city, date_time + 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 = ? + ORDER BY date_time DESC + "; + $stmt = mysqli_prepare($db, $query); + $stmt->bind_param("s", $key); + $stmt->execute(); + $data = $stmt->get_result(); + + $results = array(); + + $table1 = '<tr><th id="tabledate" colspan="4">Chengdu Humidity Data</th></tr>'; + $table1 .= '<tr><th>Date</th><th>Humidity</th></tr>'; + $table2 = '<tr><th id="tabledate" colspan="4">Kangding Humidity Data</th></tr>'; + $table2 .= '<tr><th>Date</th><th>Humidity</th></tr>'; + + + while ($row = $data->fetch_assoc()) { + $humidity = humid($row["temperature"], $row["dew_point"]); + $current_date = $row['date_time']; + $correct_date = date("d M Y H:i:s", strtotime($current_date)); + $city = $row['city']; + + + $results[$city] = array(); + + + $results[$city][] = array( + 'date' => $correct_date, + 'humidity' => $humidity + ); + + + if($city == 'Chengdu') { + $table1 .= '<tr><td>'.$correct_date.'</td><td>'.$humidity.'</td></tr>'; + } + else{ + $table2 .= '<tr><td>'.$correct_date.'</td><td>'.$humidity.'</td></tr>'; + } + + } + + $html .= $table1 . $table2; + return $html; + + + } + function retrieveHData($key, $generateXml = false) { $html = ''; $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2"); @@ -86,11 +150,12 @@ Class Key{ 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' + WHERE c.token = ? ORDER BY date DESC, temperature, wind_speed "; $stmt = mysqli_prepare($db, $query); + $stmt->bind_param("s", $key); $stmt->execute(); $data = $stmt->get_result(); @@ -118,7 +183,7 @@ Class Key{ $locations[$current_date][] = $city; } } - + $html .= $this->retrieveHumidityTable('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684'); $html .= '<table>'; foreach ($results as $date => $entries) {