commit 3d59c0a6836c821242a9040e3b3c1a4cae612daa
parent 67588dd20794bfed3035677e0cd64efd2a9bbe03
Author: Kninteman <[email protected]>
Date: Sun, 11 Jun 2023 15:52:21 +0200
Data
Diffstat:
5 files changed, 53 insertions(+), 83 deletions(-)
diff --git a/Lollipop/Session.php b/Lollipop/Session.php
@@ -1,10 +0,0 @@
-<?php
-Class Session{
- if (!isset($_SESSION['CREATED'])) {
- $_SESSION['CREATED'] = time();
-} else if (time() - $_SESSION['CREATED'] > 1800) {
- // session started more than 30 minutes ago
- session_regenerate_id(true); // change session ID for the current session and invalidate old session ID
- $_SESSION['CREATED'] = time(); // update creation time
-}
-}
-\ No newline at end of file
diff --git a/Model/Key.php b/Model/Key.php
@@ -1,64 +1,41 @@
<?php
Class Key{
function myfunction($key){
- if ($key['data'] != '3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'){
- echo("no");
+ 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 temperature, dew_point, wind_speed
- FROM weather_data wd
- JOIN station s ON wd.station_name = s.name
- JOIN contract_station cs ON cs.station_name = s.name
- JOIN contract c ON cs.contract_id = c.contract_id
- WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
- LIMIT 5";
+ FROM weather_data wd
+ JOIN station s ON wd.station_name = s.name
+ JOIN contract_station cs ON cs.station_name = s.name
+ 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();
-// $table = "<table";
-// $data = ["tabel" => $table];
- while ($row = $data->fetch_assoc()) {
- $weather_data[] = $row;
- }
- if ($weather_data != null) {?>
- <table class="table table-striped">
- <thead>
- <tr>
- <th> Temperature </th>
- <th> Dewpoint </th>
- <th> Wind speed </th>
- <th> Wind chill corrected temp </th>
- <th> Humidity </th>
- <th> Warning </th>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach($weather_data as $data) {
- echo "<tr>";
- echo "<td>" . $data["temperature"] . "</td>";
- echo "<td>" . $data['dew_point'] . "</td>";
- echo "<td>" . $data['wind_speed'] . "</td>";
- echo "<td>" . windchill($data["temperature"], $data['wind_speed']) . "</td>";
- echo "<td>" . humid($data["temperature"], $data['dew_point']) . "</td>";
- echo "<td>" . checkHumid($data["temperature"], $data['dew_point']) . "</td>";
- echo "</tr>";
+
+ while ($row = $data->fetch_assoc()) {
+ $wind_chill = windchill($row["temperature"], $row["wind_speed"]);
+ $humidity = humid($row["temperature"], $row["dew_point"]);
+ $weather_data[] = [
+ 'windchill' => $wind_chill,
+ 'humidity' => $humidity
+ ];
}
- ?>
- </tbody>
- </table>
-<?php
- return json_encode($weather_data);
+ header('Content-Type: application/json');
+ echo json_encode($weather_data);
+ }
}
}
-}
-}
function windchill($temp, $wind): float
{
- return 13.12 + 0.6215*$temp - 11.37 * ($wind^0.16) + 0.3965* $temp * ($wind^0.16);
+ $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
@@ -66,29 +43,16 @@ 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 ($specific_humidity / $saturation_point) * 100;
+ return round(($specific_humidity / $saturation_point) * 100, 2);
}
function checkHumid($temp, $dewp): string
{
- $specific_humidity = exp((17.625*$dewp)/(243.04+$dewp));
- $saturation_point = exp((17.625*$temp)/(243.04+$temp));
- $humidity = ($specific_humidity / $saturation_point) * 100;
+ $humidity = humid($temp, $dewp);
if ($humidity<50){
return "warning";
} else {
return "dontchu worry";
}
}
-?>
-
-
-
-
-
-<!--//SELECT *-->
-<!--//FROM weather_data wd-->
-<!--//JOIN station s ON wd.station_name = s.name-->
-<!--//JOIN contract_station cs ON cs.station_name = s.name-->
-<!--//JOIN contract c ON cs.contract_id = c.contract_id-->
-<!--//WHERE c.token = "3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk"-->
-\ No newline at end of file
+?>
+\ No newline at end of file
diff --git a/img/logo.png b/img/logo.png
Binary files differ.
diff --git a/js/panda.js b/js/panda.js
@@ -0,0 +1,24 @@
+let token = ':3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk';
+
+fetch(`http://localhost:8080/api/${token}`)
+ .then(response => response.clone().json())
+ .then(data => {
+ let weatherList = document.getElementById('weather-list');
+ data.forEach(item => {
+ let listItem = document.createElement('li');
+ listItem.textContent = item['windchill'] + ' ' + item['humidity'];
+ weatherList.appendChild(listItem);
+ });
+ });
+
+
+function jsonSorter(key) {
+ return function(a, b) {
+ if (a[key] > b[key]) {
+ return 1;
+ } else if (a[key] < b[key]) {
+ return -1;
+ }
+ return 0;
+ }
+}
+\ No newline at end of file
diff --git a/views/panda.html b/views/panda.html
@@ -56,21 +56,14 @@
<!--<IMG class="gif" SRC="/img/panda.gif">-->
</div>
<h1>Welcome to Panda Breeding Facilities</h1>
-<p class="inlog">Je bent ingelogd als "Rapper Sjors"</p>
+<p class="inlog">Je bent ingelogd als "Kars"</p>
<div class="block1">
<div class="content">
- <ul class="fancy-list">
- <li>Item 1</li>
- <li>Item 2</li>
- <li>Item 3</li>
- <li>Item 4</li>
- </ul>
+ <ol class="fancy-list" id="weather-list"></ol>
</div>
<div class="content1">
- <p>Sate met rijst</p>
- <p>€3</p>
</div>
</div>
@@ -82,7 +75,6 @@
<div class="bar" style="height: 160px; left: 260px;"></div>
</div>
</div>
-
</body>
-</html>
+<script src="../js/panda.js"></script>
</html>
\ No newline at end of file