hanze/iwa-panda2

Model/Key.php in login
Repositories | Summary | Log | Files | README.md

Key.php (3124B) download


 1<?php
 2Class Key{
 3    function myfunction($key){
 4        if ($key['data'] != '3jvl7yb5sRr80s6lTdeOyxV9VTQZkCPRp7bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'){
 5            echo("no");
 6        } else{
 7        $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
 8        $t = new Lollipop\Template();
 9        $weather_data = [];
10        $query = "SELECT temperature, dew_point, wind_speed 
11            FROM weather_data wd
12            JOIN station s ON wd.station_name = s.name
13            JOIN contract_station cs ON cs.station_name = s.name
14            JOIN contract c ON cs.contract_id = c.contract_id
15            WHERE c.token = '3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk'
16            LIMIT 5";
17        $stmt = mysqli_prepare($db, $query);
18        $stmt->execute();
19        $data = $stmt->get_result();
20//        $table = "<table";
21//        $data = ["tabel" => $table];
22        while ($row = $data->fetch_assoc()) {
23            $weather_data[] = $row;
24            }
25        if ($weather_data != null) {?>
26        <table class="table table-striped">
27            <thead>
28            <tr>
29                <th> Temperature </th>
30                <th> Dewpoint </th>
31                <th> Wind speed </th>
32                <th> Wind chill corrected temp </th>
33                <th> Humidity </th>
34                <th> Warning </th>
35            </tr>
36            </thead>
37            <tbody>
38            <?php
39            foreach($weather_data as $data) {
40                echo "<tr>";
41                echo "<td>" . $data["temperature"] . "</td>";
42                echo "<td>" . $data['dew_point'] . "</td>";
43                echo "<td>" . $data['wind_speed'] . "</td>";
44                echo "<td>" . windchill($data["temperature"], $data['wind_speed']) . "</td>";
45                echo "<td>" . humid($data["temperature"], $data['dew_point']) . "</td>";
46                echo "<td>" . checkHumid($data["temperature"], $data['dew_point']) . "</td>";
47                echo "</tr>";
48            }
49            ?>
50            </tbody>
51        </table>
52<?php
53
54        return json_encode($weather_data);
55    }
56}
57}
58}
59function windchill($temp, $wind): float
60{
61    return 13.12 + 0.6215*$temp - 11.37 * ($wind^0.16) + 0.3965* $temp * ($wind^0.16);
62}
63
64function humid($temp, $dewp): float|int
65{
66    $specific_humidity = exp((17.625*$dewp)/(243.04+$dewp));
67    $saturation_point = exp((17.625*$temp)/(243.04+$temp));
68
69    return ($specific_humidity / $saturation_point) * 100;
70}
71
72function checkHumid($temp, $dewp): string
73{
74    $specific_humidity = exp((17.625*$dewp)/(243.04+$dewp));
75    $saturation_point = exp((17.625*$temp)/(243.04+$temp));
76    $humidity = ($specific_humidity / $saturation_point) * 100;
77    if ($humidity<50){
78        return "warning";
79    } else {
80        return "dontchu worry";
81    }
82}
83?>
84
85
86
87
88
89<!--//SELECT *-->
90<!--//FROM weather_data wd-->
91<!--//JOIN station s ON wd.station_name = s.name-->
92<!--//JOIN contract_station cs ON cs.station_name = s.name-->
93<!--//JOIN contract c ON cs.contract_id = c.contract_id-->
94<!--//WHERE c.token = "3jvl/yb?sRr80s6lTdeOyxV9VTQZkCPRp/bKOWKFWxfL2vhsU4Hhpgcmz9qe0zEk"-->