Files
controls-web/lasuca/inc/east15minavg.php
2026-02-17 09:29:34 -06:00

55 lines
1.4 KiB
PHP

<?php
/**
* Calculates the 15-minute average for east and west total ground values.
* Requires dbinfo.php for database credentials.
*/
require 'dbinfo.php';
$con = mysqli_connect($host, $username, $password, $database);
if (! $con) {
echo '0';
return;
}
$query = "SELECT
(
(
(SELECT easttotground FROM easttotalground ORDER BY id DESC LIMIT 1) -
(SELECT easttotground FROM easttotalground ORDER BY id DESC LIMIT 899, 1)
) * 4
) AS eastavg,
(
(
(SELECT westtotground FROM westtotalground ORDER BY id DESC LIMIT 1) -
(SELECT westtotground FROM westtotalground ORDER BY id DESC LIMIT 899, 1)
) * 4
) AS westavg,
(
(
(SELECT easttotground FROM easttotalground ORDER BY id DESC LIMIT 1) -
(SELECT easttotground FROM easttotalground ORDER BY id DESC LIMIT 899, 1)
) * 4
+
(
(SELECT westtotground FROM westtotalground ORDER BY id DESC LIMIT 1) -
(SELECT westtotground FROM westtotalground ORDER BY id DESC LIMIT 899, 1)
) * 4
) AS totalavg";
$result = mysqli_query($con, $query);
$include4 = ($result !== false)
? mysqli_fetch_array($result, MYSQLI_ASSOC)
: null;
mysqli_close($con);
$eastAverage = is_array($include4) && isset($include4['totalavg'])
? $include4['totalavg']
: 0;
echo round($eastAverage);
?>