277 lines
8.5 KiB
PHP
277 lines
8.5 KiB
PHP
<?php // phpcs:ignoreFile
|
|
|
|
require __DIR__ . '/../../session.php';
|
|
require __DIR__ . '/../../userAccess.php';
|
|
require __DIR__ . '/../../items.php';
|
|
|
|
$pageTitle = 'Daily Total Target';
|
|
$pageSubtitle = 'See how hard we need to push to hit today\'s goal';
|
|
$pageDescription = 'Calculate the tons-per-hour needed to reach the daily tonnage goal before the 5 a.m. reset.';
|
|
$assetBasePath = '../../';
|
|
$layoutWithoutSidebar = true;
|
|
$layoutReturnUrl = '../../overview.php';
|
|
$layoutReturnLabel = 'Back to overview';
|
|
|
|
$appTimeZone = new DateTimeZone('America/Chicago');
|
|
$dailyResetHour = 5;
|
|
|
|
function sanitizeFloat($value, float $default = 0.0): float
|
|
{
|
|
if ($value === null || $value === '') {
|
|
return $default;
|
|
}
|
|
|
|
$filtered = filter_var($value, FILTER_VALIDATE_FLOAT);
|
|
|
|
return $filtered === false ? $default : (float) $filtered;
|
|
}
|
|
|
|
function sanitizeTarget($value): float
|
|
{
|
|
$target = sanitizeFloat($value, 22000.0);
|
|
|
|
return max(0.0, $target);
|
|
}
|
|
|
|
function calculateWindow(DateTimeZone $tz, int $resetHour): array
|
|
{
|
|
$now = new DateTimeImmutable('now', $tz);
|
|
$todayReset = $now->setTime($resetHour, 0, 0);
|
|
|
|
if ($now < $todayReset) {
|
|
$start = $todayReset->modify('-1 day');
|
|
$end = $todayReset;
|
|
} else {
|
|
$start = $todayReset;
|
|
$end = $todayReset->modify('+1 day');
|
|
}
|
|
|
|
$secondsTotal = max(1, $end->getTimestamp() - $start->getTimestamp());
|
|
$secondsElapsed = max(
|
|
0,
|
|
min($secondsTotal, $now->getTimestamp() - $start->getTimestamp())
|
|
);
|
|
$secondsRemaining = $secondsTotal - $secondsElapsed;
|
|
|
|
return [
|
|
'now' => $now,
|
|
'start' => $start,
|
|
'end' => $end,
|
|
'secondsElapsed' => $secondsElapsed,
|
|
'secondsRemaining' => $secondsRemaining,
|
|
'hoursElapsed' => $secondsElapsed / 3600,
|
|
'hoursRemaining' => $secondsRemaining / 3600,
|
|
'hoursTotal' => $secondsTotal / 3600,
|
|
];
|
|
}
|
|
|
|
function buildResult(
|
|
float $targetTons,
|
|
float $alreadyGround,
|
|
float $projectedRest,
|
|
float $hoursRemaining
|
|
): array {
|
|
$neededTonnage = max(0.0, $targetTons - $alreadyGround);
|
|
$requiredRate = $hoursRemaining > 0 ? $neededTonnage / $hoursRemaining : 0.0;
|
|
$projectedRest = max(0.0, $projectedRest);
|
|
$projectedRate = $hoursRemaining > 0 ? $projectedRest / $hoursRemaining : 0.0;
|
|
|
|
$projectedTotal = $alreadyGround + $projectedRest;
|
|
$projectedShortfall = max(0.0, $targetTons - $projectedTotal);
|
|
$deltaRate = max(0.0, $requiredRate - $projectedRate);
|
|
|
|
return [
|
|
'targetTons' => $targetTons,
|
|
'alreadyGround' => $alreadyGround,
|
|
'projectedRest' => $projectedRest,
|
|
'hoursRemaining' => $hoursRemaining,
|
|
'neededTonnage' => $neededTonnage,
|
|
'projectedTotal' => $projectedTotal,
|
|
'projectedShortfall' => $projectedShortfall,
|
|
'requiredRate' => $requiredRate,
|
|
'projectedRate' => $projectedRate,
|
|
'deltaRate' => $deltaRate,
|
|
];
|
|
}
|
|
|
|
$liveGroundTons = null;
|
|
if (isset($value['CANETOT'], $value['W TONS GROUND'])) {
|
|
$liveGroundTons = (float) $value['CANETOT'] + (float) $value['W TONS GROUND'];
|
|
}
|
|
|
|
$defaultGround = $liveGroundTons ?? 0.0;
|
|
|
|
$projectedTotal = null;
|
|
$projectedIncludePath = __DIR__ . '/../../includes/millprojected60min.php';
|
|
if (is_file($projectedIncludePath)) {
|
|
// Reuse the existing include by buffering its echoed total and keeping its relative paths intact.
|
|
$previousCwd = getcwd();
|
|
$includeDir = dirname($projectedIncludePath);
|
|
|
|
if ($includeDir !== false && is_dir($includeDir)) {
|
|
chdir($includeDir);
|
|
}
|
|
|
|
ob_start();
|
|
include $projectedIncludePath;
|
|
$projectedRaw = trim(ob_get_clean());
|
|
|
|
if ($previousCwd !== false && is_dir($previousCwd)) {
|
|
chdir($previousCwd);
|
|
}
|
|
|
|
if ($projectedRaw !== '' && is_numeric($projectedRaw)) {
|
|
$projectedTotal = (float) $projectedRaw;
|
|
}
|
|
}
|
|
|
|
$defaultProjectedCarry = 0.0;
|
|
if ($projectedTotal !== null) {
|
|
$alreadyGroundForCarry = $liveGroundTons ?? 0.0;
|
|
$defaultProjectedCarry = max(0.0, $projectedTotal - $alreadyGroundForCarry);
|
|
}
|
|
|
|
$formInput = [
|
|
'target' => sanitizeTarget($_POST['target'] ?? 22000),
|
|
'ground' => sanitizeFloat(
|
|
array_key_exists('ground', $_POST) ? $_POST['ground'] : $defaultGround,
|
|
$defaultGround
|
|
),
|
|
'projected' => sanitizeFloat(
|
|
array_key_exists('projected', $_POST) ? $_POST['projected'] : $defaultProjectedCarry,
|
|
$defaultProjectedCarry
|
|
),
|
|
];
|
|
|
|
$window = calculateWindow($appTimeZone, $dailyResetHour);
|
|
$result = buildResult(
|
|
$formInput['target'],
|
|
$formInput['ground'],
|
|
$formInput['projected'],
|
|
$window['hoursRemaining']
|
|
);
|
|
|
|
$targetDeadlineLabel = $window['end']->format('g:i A T');
|
|
|
|
require __DIR__ . '/../../includes/layout/header.php';
|
|
?>
|
|
|
|
<div class="app-content">
|
|
<section class="data-panel">
|
|
<header class="panel-header">
|
|
<h2>Daily total target checker</h2>
|
|
<p>
|
|
Enter today's ground tonnage, your current projection, and the target
|
|
to see the tons-per-hour required by
|
|
<?php echo htmlspecialchars($targetDeadlineLabel); ?>.
|
|
</p>
|
|
</header>
|
|
|
|
<form method="post" class="target-form">
|
|
<div class="target-grid">
|
|
<label class="target-field">
|
|
<span class="target-label">Target tonnage</span>
|
|
<input
|
|
type="number"
|
|
name="target"
|
|
step="100"
|
|
min="0"
|
|
value="<?php echo htmlspecialchars((string) $formInput['target']); ?>"
|
|
>
|
|
</label>
|
|
|
|
<label class="target-field">
|
|
<span class="target-label">Tons ground so far</span>
|
|
<input
|
|
type="number"
|
|
name="ground"
|
|
step="1"
|
|
min="0"
|
|
value="<?php echo htmlspecialchars((string) $formInput['ground']); ?>"
|
|
>
|
|
</label>
|
|
|
|
<label class="target-field">
|
|
<span class="target-label">Projected tons remaining (current pace)</span>
|
|
<input
|
|
type="number"
|
|
name="projected"
|
|
step="1"
|
|
min="0"
|
|
value="<?php echo htmlspecialchars((string) $formInput['projected']); ?>"
|
|
>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="target-actions">
|
|
<button type="submit" class="button button--success">
|
|
Calculate required rate
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="target-results">
|
|
<div class="target-result-card">
|
|
<span class="target-result-label">Hours remaining</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($window['hoursRemaining'], 2); ?> h
|
|
</span>
|
|
</div>
|
|
|
|
<div class="target-result-card">
|
|
<span class="target-result-label">Target shortfall</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($result['neededTonnage'], 0); ?> tons
|
|
</span>
|
|
</div>
|
|
|
|
<div class="target-result-card">
|
|
<span class="target-result-label">Projected carry</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($result['projectedRest'], 0); ?> tons
|
|
</span>
|
|
</div>
|
|
|
|
<div class="target-result-card">
|
|
<span class="target-result-label">Projected shortfall</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($result['projectedShortfall'], 0); ?> tons
|
|
</span>
|
|
</div>
|
|
|
|
<div class="target-result-card">
|
|
<span class="target-result-label">Current pace</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($result['projectedRate'], 2); ?> tph
|
|
</span>
|
|
</div>
|
|
|
|
<div class="target-result-card target-result-card--primary">
|
|
<span class="target-result-label">Required rate</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($result['requiredRate'], 2); ?> tph
|
|
</span>
|
|
</div>
|
|
|
|
<div class="target-result-card target-result-card--delta">
|
|
<span class="target-result-label">Additional rate needed</span>
|
|
<span class="target-result-value">
|
|
<?php echo number_format($result['deltaRate'], 2); ?> tph
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="target-footnote">
|
|
<p>
|
|
Calculations assume the 24-hour window resets at 5:00 a.m. Central.
|
|
Required rate uses the remaining hours
|
|
(<?php echo number_format($window['hoursRemaining'], 2); ?> h).
|
|
Projected shortfall compares the target against the current ground
|
|
tonnage plus the forecast carry at today's pace.
|
|
</p>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<?php require __DIR__ . '/../../includes/layout/footer.php'; ?>
|