commit 3fba5c2168babde150b1a2c697245333448615e7
parent fe6f3de2ea9d4c881f0a01e65fcd50d346ae278f
Author: DennyVB <[email protected]>
Date: Sat, 1 Apr 2023 20:03:00 +0200
redisconnection.php toegevoegd
Dit was ff snel wat ik kon bedenken met 2 queues. joe
Diffstat:
4 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/.idea/php.xml b/.idea/php.xml
@@ -10,6 +10,7 @@
<option name="highlightLevel" value="WARNING" />
<option name="transferred" value="true" />
</component>
+ <component name="PhpProjectSharedConfiguration" php_language_level="8.2" />
<component name="PhpStanOptionsConfiguration">
<option name="transferred" value="true" />
</component>
diff --git a/datavalidator.php b/datavalidator.php
@@ -1,4 +1,9 @@
<?php
+
+$redis = new Redis();
+$redis->connect('86.92.67.21', 3306);
+$redis->auth('hailiwa');
+
/**
* Validates the temperature against the average of the last 30 rows for the given station name.
*
diff --git a/redisconnection.php b/redisconnection.php
@@ -0,0 +1,36 @@
+<?php
+$redis = new Redis();
+$redis->connect('127.0.0.1', 6379);
+
+//$redis->flushAll(); //Dit cleart de hele database :)
+
+$newValue = 28;
+
+if(!$redis->exists('values')) {
+ $redis->lpush('values', $newValue);
+ $redis->lpush('average', $newValue);
+}
+else {
+ if($redis->llen('values') < 30) {
+ $avg = ($redis->rpop('average') * $redis->llen('values') + $newValue) / ($redis->llen('values') + 1);
+ $redis->lpush('average', $avg);
+ $redis->lpush('values', $newValue);
+ }
+ else {
+ $avg = ($redis->rpop('average') * 30 - $redis->rpop('values') + $newValue) / 30;
+ $redis->lpush('average', $avg);
+ $redis->lpush('values', $newValue);
+ }
+}
+
+echo $redis->lIndex('average', 0);
+
+
+
+
+
+
+
+
+
+
diff --git a/weerdata.php b/weerdata.php
@@ -1,7 +1,7 @@
<?php
$servername = "86.92.67.21";
$username = "friedel";
-$password = "koffiemetzuiker";
+$password = "hailiwa";
$dbname = "wap2";
// Create connection