Folder reorganize 1
This commit is contained in:
62
includes/millingprojeced60min_test.php
Normal file
62
includes/millingprojeced60min_test.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
include '../dbinfo.php';
|
||||
include '../dbinfo2.php';
|
||||
|
||||
$con = mysqli_connect('192.168.0.10', 'corey', '41945549', 'controls');
|
||||
|
||||
// Second connection for west mill data (dbinfo2.php)
|
||||
$con2 = mysqli_connect('192.168.0.9', 'corey', '41945549', 'controls');
|
||||
|
||||
function fetchLatestAndHourAgo(mysqli $con, string $table, string $column): ?array
|
||||
{
|
||||
$sql = "
|
||||
SELECT $column AS value, timestamp
|
||||
FROM $table
|
||||
ORDER BY id DESC
|
||||
LIMIT 3600
|
||||
";
|
||||
$result = mysqli_query($con, $sql);
|
||||
if (!$result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||
if (count($rows) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$latest = $rows[0];
|
||||
$hourAgo = $rows[min(count($rows) - 1, 3599)]; // fall back if fewer than 3600 rows
|
||||
|
||||
return [
|
||||
'latest' => (float) $latest['value'],
|
||||
'hourAgo' => (float) $hourAgo['value'],
|
||||
'elapsedH' => max(
|
||||
1,
|
||||
(strtotime($latest['timestamp']) - strtotime($hourAgo['timestamp'])) / 3600
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
$east = fetchLatestAndHourAgo($con, 'easttotalground', 'easttotground');
|
||||
$west = $con2 ? fetchLatestAndHourAgo($con2, 'westtotalground', 'MODBUSENET_TABLE900_WTOTGROUND_VALUE') : null;
|
||||
|
||||
$totalToday = (float) mysqli_fetch_column(mysqli_query(
|
||||
$con,
|
||||
"SELECT MillTotalGround FROM mill_total_ground ORDER BY id DESC LIMIT 1"
|
||||
));
|
||||
|
||||
mysqli_close($con);
|
||||
if ($con2) {
|
||||
mysqli_close($con2);
|
||||
}
|
||||
|
||||
$hoursSinceFive = (time() < strtotime('5:00'))
|
||||
? (time() + 86400 - strtotime('5:00')) / 3600
|
||||
: (time() - strtotime('5:00')) / 3600;
|
||||
$hoursRemaining = max(0, 24 - $hoursSinceFive);
|
||||
|
||||
$eastProjected = $east ? ($east['latest'] - $east['hourAgo']) / $east['elapsedH'] * $hoursRemaining : 0;
|
||||
$westProjected = $west ? ($west['latest'] - $west['hourAgo']) / $west['elapsedH'] * $hoursRemaining : 0;
|
||||
|
||||
echo number_format($totalToday + $eastProjected + $westProjected, 0);
|
||||
Reference in New Issue
Block a user