commit a807dc745f34e4384cc0c1ed4d21868ab14d05fe
parent beb5e0b50d95130125250bdec568a942629fb89c
Author: Kninteman <[email protected]>
Date: Mon, 3 Apr 2023 14:44:13 +0200
Dutch -> English
Diffstat:
2 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/datainserter.php b/datainserter.php
@@ -67,8 +67,8 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$valid = validate_temperature($stn, $temp, $redis);
// Prepare SQL INSERT-statement
- $sql = "INSERT INTO weerdata (station_name,datum_tijd,gevalideerd,temp,dauwpunt,ldrk_znv,ldrk_station,zichtbaarheid,
- windsnelheid,neerslag,sneeuwdpt,gebeurtenissen, vorst,regen,sneeuw,hagel,onweer,tornado, bewolking,windrichting)
+ $sql = "INSERT INTO weather_data (station_name,date_time,validated,temperature,dew_point,pressure_sea,pressure_station,visibility,
+ wind_speed,precipitation,snow_depth,events,frost_boolean,rain_boolean,snow_boolean,hail_boolean,thunder_boolean,tornado_boolean,cloud_count,wind_direction)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
// Create prepared statement with the SQL statement
@@ -78,15 +78,15 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$datetime = $date . " " . $time;
// Extract the boolean values from $frshtt
- $vorst = (int)substr($frshtt, 0, 1);
- $regen = (int)substr($frshtt, 1, 1);
- $sneeuw = (int)substr($frshtt, 2, 1);
- $hagel = (int)substr($frshtt, 3, 1);
- $onweer = (int)substr($frshtt, 4, 1);
+ $frost = (int)substr($frshtt, 0, 1);
+ $rain = (int)substr($frshtt, 1, 1);
+ $snow = (int)substr($frshtt, 2, 1);
+ $hail = (int)substr($frshtt, 3, 1);
+ $thunder = (int)substr($frshtt, 4, 1);
$tornado = (int)substr($frshtt, 5, 1);
// Bind parameters to prepared statement
- mysqli_stmt_bind_param($stmt, "isiddddddddsiiiiiidi", $stn, $datetime, $valid, $temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $vorst, $regen, $sneeuw, $hagel, $onweer, $tornado, $cldc, $wnddir);
+ mysqli_stmt_bind_param($stmt, "isiddddddddsiiiiiidi", $stn, $datetime, $valid, $temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $frost, $rain, $snow, $hail, $thunder, $tornado, $cldc, $wnddir);
// Execute prepared statement, only if the data is not within the first 30 entries
$result = mysqli_stmt_execute($stmt);
@@ -100,7 +100,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Second Insert for shadow table
if ($valid == -1) {
- $sql2 = "SELECT data_id from weerdata where station_name = ? and datum_tijd = ?";
+ $sql2 = "SELECT data_id from weather_data where station_name = ? and date_time = ?";
$stmt2 = mysqli_prepare($db_connection, $sql2);
mysqli_stmt_bind_param($stmt2, "is", $stn, $datetime);
$stmt2->execute();
@@ -108,12 +108,12 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$row = $result->fetch_assoc();
$data_id = $row['data_id'];
- $sql3 = "INSERT INTO weerdata_gecorrigeerd (station_name, origin_data_id, datum_tijd,temp,dauwpunt,ldrk_znv,ldrk_station,zichtbaarheid,
- windsnelheid,neerslag,sneeuwdpt,gebeurtenissen, vorst,regen,sneeuw,hagel,onweer,tornado, bewolking,windrichting)
+ $sql3 = "INSERT INTO weather_data_corrected (station_name, origin_data_id, date_time,temperature,dew_point,pressure_sea,pressure_station,visibility,
+ wind_speed,precipitation,snow_depth,events,frost_boolean,rain_boolean,snow_boolean,hail_boolean,thunder_boolean,tornado_boolean,cloud_count,wind_direction)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt3 = mysqli_prepare($db_connection, $sql3);
$new_temp = round($redis->lIndex('average'.$stn, 0), 1);
- mysqli_stmt_bind_param($stmt3, "iisddddddddsiiiiiidi", $stn, $data_id, $datetime, $new_temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $vorst, $regen, $sneeuw, $hagel, $onweer, $tornado, $cldc, $wnddir);
+ mysqli_stmt_bind_param($stmt3, "iisddddddddsiiiiiidi", $stn, $data_id, $datetime, $new_temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $frost, $rain, $snow, $hail, $thunder, $tornado, $cldc, $wnddir);
$result = mysqli_stmt_execute($stmt3);
}
diff --git a/datavalidator.php b/datavalidator.php
@@ -5,42 +5,42 @@
* Validates the temperature against the average of the last 30 rows for the given station name.
*
* @param string $station The station name to validate against.
- * @param float $temperatuur The temperature value to validate.
+ * @param float $temperature The temperature value to validate.
* @param Redis $redis The Redis connection object.
* @return float Returns the correct temperature.
*/
-function validate_temperature($station, $temperatuur, $redis) {
+function validate_temperature($station, $temperature, $redis) {
// Return the correct temperature validated with last 30 values.
//Deze checkt of het de eerste value is en maakt 2 queues aan en knalt de waardes erin.
if(!$redis->exists('values'.$station)) {
- $redis->lpush('values'.$station, $temperatuur);
- $redis->lpush('average'.$station, $temperatuur);
+ $redis->lpush('values'.$station, $temperature);
+ $redis->lpush('average'.$station, $temperature);
return 0;
}
//Als het aantal values de 30 nog niet bereikt heeft, berekend hij gewoon het gemiddelde en voegt de value toe aan de queue
else {
if($redis->llen('values'.$station) < 3) {
- $avg = ($redis->rpop('average'.$station) * $redis->llen('values'.$station) + $temperatuur) / ($redis->llen('values'.$station) + 1);
+ $avg = ($redis->rpop('average'.$station) * $redis->llen('values'.$station) + $temperature) / ($redis->llen('values'.$station) + 1);
$redis->lpush('average'.$station, $avg);
- $redis->lpush('values'.$station, $temperatuur);
+ $redis->lpush('values'.$station, $temperature);
return 0;
}
//Bij 30 values zal de volgende value eerst gecheckt worden met het bekende gemiddelde en eventueel aangepast worden.
//Daarna zal deze toegevoegd worden aan de value en average queue. De laatste waarde zal eruit gehaald worden.
else {
$current_avg = $redis->lIndex('average'.$station, 0);
- if(abs(($temperatuur - $current_avg) / $current_avg) > 0.2) {
- $temperatuur = $current_avg;
- $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperatuur) / 3;
+ if(abs(($temperature - $current_avg) / $current_avg) > 0.2) {
+ $temperature = $current_avg;
+ $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperature) / 3;
$redis->lpush('average'.$station, $new_avg);
- $redis->lpush('values'.$station, $temperatuur);
+ $redis->lpush('values'.$station, $temperature);
return -1;
}
else {
- $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperatuur) / 3;
+ $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperature) / 3;
$redis->lpush('average'.$station, $new_avg);
- $redis->lpush('values'.$station, $temperatuur);
+ $redis->lpush('values'.$station, $temperature);
return 1;
}
}