hanze/iwa-panda2

api noted, cleaning up Key.php (30922967118a7063aef96e6ae83f9683b9b42abb)
Repositories | README.md

commit 30922967118a7063aef96e6ae83f9683b9b42abb
parent ceb1fae1fca397c3d449ed1247ac547dc56e9352
Author: Friedel Schön <[email protected]>
Date:   Tue, 27 Jun 2023 11:01:23 +0200

api noted, cleaning up Key.php

Diffstat:
AModel/Formula.php20++++++++++++++++++++
MModel/Key.php112+++----------------------------------------------------------------------------
MModel/Utils.php8--------
Aapi.sql33+++++++++++++++++++++++++++++++++
Mindex.php5+++--
5 files changed, 60 insertions(+), 118 deletions(-)

diff --git a/Model/Formula.php b/Model/Formula.php @@ -0,0 +1,19 @@ +<?php + +namespace Model { + class Formula { + static function windchill($temp, $wind): float + { + $result = 13.12 + 0.6215 * $temp - 11.37 * pow($wind, 0.16) + 0.3965* $temp * pow($wind, 0.16); + return round($result, 2); + } + + static function humid($temp, $dewp): float|int + { + $specific_humidity = exp((17.625*$dewp)/(243.04+$dewp)); + $saturation_point = exp((17.625*$temp)/(243.04+$temp)); + + return round(($specific_humidity / $saturation_point) * 100, 2); + } + } +} +\ No newline at end of file diff --git a/Model/Key.php b/Model/Key.php @@ -1,84 +1,5 @@ <?php Class Key{ - - protected array $data; - function retrieveData($key){ - $validKeys = [ - ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk' => 'retrieveZooData', - ':ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684' => 'retrieveRBData', - ]; - if (array_key_exists($key['data'], $validKeys)) { - $method = $validKeys[$key['data']]; - $this->$method($key); - } else { - echo "You have no access here!"; - } - } - - function retrieveZooData($key){ - $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2"); - $weather_data = []; - $query = "SELECT distinct temperature, wind_speed, nl.name as city, co.country as country - 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' - AND date(wd.date_time) = date(curdate()) - GROUP BY nl.name - "; - - $stmt = mysqli_prepare($db, $query); - $stmt->execute(); - $data = $stmt->get_result(); - - while ($row = $data->fetch_assoc()) { - $wind_chill = windchill($row["temperature"], $row["wind_speed"]); - $weather_data[] = [ - 'windchill' => $wind_chill, - 'location' => $row['city'], - 'country' => $row['country'] - ]; - } - header('Content-Type: application/json'); - echo json_encode($weather_data); - } - - function retrieveRBData($key){ - $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 = 'ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684' - "; - $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'], - '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"); @@ -106,7 +27,7 @@ Class Key{ $xml1 = '<location name="Chengdu">'; $xml2 = '<location name="Kangding">'; while ($row = $data->fetch_assoc()) { - $humidity = humid($row["temperature"], $row["dew_point"]); + $humidity = Model\Formula::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']; @@ -164,7 +85,7 @@ Class Key{ $locations = array(); while ($row = $data->fetch_assoc()) { - $wind_chill = windchill($row["temperature"], $row["wind_speed"]); + $wind_chill = Model\Formula::windchill($row["temperature"], $row["wind_speed"]); $current_date = $row['date']; $city = $row['city']; @@ -210,29 +131,4 @@ Class Key{ } return $html; } -} - -function windchill($temp, $wind): float -{ - $result = 13.12 + 0.6215 * $temp - 11.37 * pow($wind, 0.16) + 0.3965* $temp * pow($wind, 0.16); - return round($result, 2); -} - -function humid($temp, $dewp): float|int -{ - $specific_humidity = exp((17.625*$dewp)/(243.04+$dewp)); - $saturation_point = exp((17.625*$temp)/(243.04+$temp)); - - return round(($specific_humidity / $saturation_point) * 100, 2); -} - -function checkHumid($temp, $dewp): string -{ - $humidity = humid($temp, $dewp); - if ($humidity<50){ - return "warning"; - } else { - return "dontchu worry"; - } -} -?> -\ No newline at end of file +} +\ No newline at end of file diff --git a/Model/Utils.php b/Model/Utils.php @@ -1,13 +1,5 @@ <?php Class Utils{ - static function post_to_array():array{ - $arr = []; - foreach ($_POST as $key => $value) { - $arr[$key] = $value; - } - return $arr; - } - static function missing_fields($post, $not_nullable){ $missing = []; foreach($not_nullable as $column){ diff --git a/api.sql b/api.sql @@ -0,0 +1,32 @@ +/api/data + ?values=temperature,dew_point + ?order=!date,temperature,wind_speed + ?distinct=temperature + + +; humidity data + +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 + +; h data + +SELECT distinct temperature, wind_speed, dew_point, DATE(date_time) AS date, 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 = ? +ORDER BY date DESC, temperature, wind_speed + +\ No newline at end of file diff --git a/index.php b/index.php @@ -49,10 +49,11 @@ if(isset($_SESSION['user_permissions']) && in_array(1,$_SESSION['user_permission $vars["table"] = make_table(); return "views/hdata.html"; }); - $router->addRoute(["GET"], "/api/:data", function($vars) { +/* $router->addRoute(["GET"], "/api/:data", function($vars) { $key = new Key; $key->retrieveData($vars); - }); + });*/ + $router->addRoute(['GET'], '/css/dashboard.css', "css/dashboard.css"); } $router->route(); \ No newline at end of file