Example #1
0
 function calc()
 {
     $conn = new MySQLiWrapper();
     //Maakt een instantie van MySQLiWrapper aan
     $result = $conn->getHumdity();
     //Pak alle resultaten uit de database
     $data = array();
     //Maak de array data aan
     while ($row = mysql_fetch_assoc($result)) {
         //Bereken de humidity op basis van termperature een dauw punt.
         $humidty = $this->calcSingle($row["temp"], $row["dewp"]);
         if (!isset($data[$row["country"]])) {
             //Dit controleert of records van een bepaald land bestaan.
             $data[$row["country"]]["humid"] = $humidty;
             //Voegt de data in de array
             $data[$row["country"]]["stn"] = $row["name"];
             //Voegt de station naam in de array
             $data[$row["country"]]["country"] = $row["country"];
             //Geeft het land mee aan de array. Dit is omdat het later apart moet worden uitgelezen.
         } else {
             if ($data[$row["country"]] < $humidty) {
                 //Controleer of het de hoogst instantie van humidity is voor een bepaald land
                 $data[$row["country"]]["humid"] = $humidty;
                 //Voegt de data in de array
                 $data[$row["country"]]["stn"] = $row["name"];
                 //Voegt de station naam in de array
                 $data[$row["country"]]["country"] = $row["country"];
                 //Geeft het land mee aan de array. Dit is omdat het later apart moet worden uitgelezen.
             }
         }
     }
     rsort($data);
     //sorteer het op basis van hoog naar laag
     $conn->insertTopHumidity($data);
     //Insert de data in top humidity.
 }
Example #2
0
<?php

require_once "./MySQLiWrapper.php";
require_once "./CalcHumidity.php";
require_once "./Export.php";
include "../class/user.php";
session_start();
if (!isset($_SESSION['user'])) {
    header("Location: login.php");
}
$conn = new MySQLiWrapper();
$calculator = new CalcHumidity();
$temperature = $conn->getTop10Temperature();
$now = new DateTime();
//Datetime met huidige datum + tijd
$time = $conn->getLastestTopHumidity();
//Query om de tijd dat tophumidity voor het laatst is geuplade te acherhalen.
$OldestTime = mysql_fetch_assoc($time);
//Stop de tijd in een variable
$lastCalcMoment = new DateTime($OldestTime["datetime"]);
//Omdat mysql_query het terug stuurt als een string moet het convert worden naar een datetime
// get difference between the two dates
$difference = $now->diff($lastCalcMoment);
//Berekend het verschil
if ($difference->h >= 1) {
    // ->i zijn de minuten. Dit betekent dat elke 30 min de top 10 humidity wordt geupdate
    $calculator->calc();
    //Roep de Calchumidity klasse aan en bereken de top 10 humdiity.
}
$humidity = $conn->getTop10Humdity();
//Query de top 10 humidity.
<?php

require_once "./MySQLiWrapper.php";
require_once "./CalcHumidity.php";
$calc = new CalcHumidity();
// Connect to the database
$db_wrapper = new MySQLiWrapper("localhost", "root", "", "unwdmi");
// Select rows from stations
$result = $db_wrapper->query("SELECT stn, name, country, latitude, longitude \n\t\t\t\t\t\t\t      FROM stations \n\t\t\t\t\t\t\t      WHERE stn={$_GET['stn']}");
$row = mysql_fetch_row($result);
echo "\n\t<tr>\n\t\t<td>\n\t\t\t<table id='station-info'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>STN</th>\n\t\t\t\t\t<th>Name</th>\n\t\t\t\t\t<th>Country</th>\n\t\t\t\t\t<th>Latitude</th>\n\t\t\t\t\t<th>Longitude</th>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>{$row[0]}</td>\n\t\t\t\t\t<td>{$row[1]}</td>\n\t\t\t\t\t<td>{$row[2]}</td>\n\t\t\t\t\t<td>{$row[3]}</td>\n\t\t\t\t\t<td>{$row[4]}</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t</tr>";
$result = $db_wrapper->query("SELECT datetime, TEMP, DEWP\n\t\t\t\t\t\t\t      FROM measurements\n\t\t\t\t\t\t\t      WHERE STN={$_GET['stn']}\n\t\t\t\t\t\t\t      ORDER BY datetime DESC\n\t\t\t\t\t\t\t      LIMIT 30");
echo "\n\t<tr>\n\t\t<td>\n\t\t\t<table id='measurements'>\n\t\t\t\t<tr>\n\t\t\t\t\t<th>Datetime</th>\n\t\t\t\t\t<th>Tempatureā„ƒ</th>\n\t\t\t\t\t<th>Humidity%</th>\n\t\t\t\t</tr>";
while ($row = mysql_fetch_assoc($result)) {
    echo "<tr>";
    echo "<td>{$row['datetime']}</td>";
    echo "<td>{$row['TEMP']}</td>";
    echo "<td>" . $calc->calcSingle($row['TEMP'], $row['DEWP']) . "</td>";
    echo "</tr>";
}
echo "\n\t\t\t</table>\n\t\t</td>\n\t</tr>";
Example #4
0
<?php

include "../class/MySQLiWrapper.php";
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Connect to the database
$db_wrapper = new MySQLiWrapper("localhost", "root", "", "unwdmi");
// Select rows from stations
$result = $db_wrapper->query("SELECT stn, latitude, longitude FROM stations");
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = mysqli_fetch_assoc($result)) {
    // ADD TO XML DOCUMENT NODE
    $node = $dom->createElement("marker");
    $newnode = $parnode->appendChild($node);
    $newnode->setAttribute("stn", $row['stn']);
    $newnode->setAttribute("latitude", $row['latitude']);
    $newnode->setAttribute("longitude", $row['longitude']);
}
echo $dom->saveXML();