<?php
require_once "../../../config/settings.inc.php";
require_once "../../../include/myview.php";
require_once "../../../include/forms.php";

$t = new MyView();
$t->title = "B548 Agronomy Time Series";

$year = get_int404("year", date("Y"));
$month = get_int404("month", date("m"));
$day = get_int404("day", date("d"));
$ts = mktime(0, 0, 0, $month, $day, $year);

$battery = "";
if ($ts < mktime(0, 0, 0, 7, 9, 2006)) {
    $battery = <<<EOM
  <img src="battery.php?year={$year}&month={$month}&day={$day}" ALT="Time Series">
EOM;
}

$ys = yearSelect(2003, $year, "year");
$ms = monthSelect($month, "month");
$ds = daySelect($day, "day");

$url = sprintf(
    "1min_ot.php?year=%s&month=%s&day=%s",
    date("Y", $ts),
    date("m", $ts),
    date("d", $ts)
);
$n = sprintf(
    "ot_10min.phtml?year=%s&month=%s&day=%s",
    date("Y", $ts + 86400),
    date("m", $ts + 86400),
    date("d", $ts + 86400)
);
$p = sprintf(
    "ot_10min.phtml?year=%s&month=%s&day=%s",
    date("Y", $ts - 86400),
    date("m", $ts - 86400),
    date("d", $ts - 86400)
);

$t->content = <<<EOM
<div class="container-fluid">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="/other/">Other Networks</a></li>
            <li class="breadcrumb-item active" aria-current="page">B548 Agronomy Server Room</li>
        </ol>
    </nav>

    <div class="row">
        <div class="col-12">
            <div class="alert alert-info" role="alert">
                <h4 class="alert-heading"><i class="bi bi-thermometer-half"></i> Server Room Climate Monitoring</h4>
                <p>The IEM server resides in a room that is climate controlled by a dedicated heat exchanger. This page presents daily plots of logged temperatures from four one-wire sensors measuring ambient temperature.</p>
                <hr>
                <p class="mb-0"><strong>Note:</strong> The archive begins July 24, 2003.</p>
            </div>
        </div>
    </div>

    <div class="row mb-4">
        <div class="col-lg-6">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-primary text-white">
                    <h5 class="card-title mb-0">
                        <i class="bi bi-calendar-date"></i> Select Date
                    </h5>
                </div>
                <div class="card-body">
                    <form method="GET" action="ot_10min.phtml" class="d-flex flex-column gap-3">
                        <div class="row g-2">
                            <div class="col-4">
                                <label for="year" class="form-label small">Year</label>
                                {$ys}
                            </div>
                            <div class="col-4">
                                <label for="month" class="form-label small">Month</label>
                                {$ms}
                            </div>
                            <div class="col-4">
                                <label for="day" class="form-label small">Day</label>
                                {$ds}
                            </div>
                        </div>
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-graph-up"></i> Generate Plot
                        </button>
                    </form>

                    <hr>

                    <div class="d-flex justify-content-between">
                        <a href="{$p}" class="btn btn-outline-secondary btn-sm">
                            <i class="bi bi-chevron-left"></i> Previous Day
                        </a>
                        <a href="{$n}" class="btn btn-outline-secondary btn-sm">
                            Next Day <i class="bi bi-chevron-right"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-6">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-success text-white">
                    <h5 class="card-title mb-0">
                        <i class="bi bi-cpu"></i> Temperature Sensor Locations
                    </h5>
                </div>
                <div class="card-body">
                    <div class="list-group list-group-flush">
                        <div class="list-group-item border-0 px-0">
                            <div class="d-flex align-items-center">
                                <div class="flex-shrink-0">
                                    <div class="bg-primary bg-opacity-25 rounded-circle p-2">
                                        <i class="bi bi-arrow-down text-primary"></i>
                                    </div>
                                </div>
                                <div class="flex-grow-1 ms-3">
                                    <div class="fw-semibold">In Air Handler</div>
                                    <small class="text-muted">5 feet above floor at heat exchanger intake</small>
                                </div>
                            </div>
                        </div>
                        <div class="list-group-item border-0 px-0">
                            <div class="d-flex align-items-center">
                                <div class="flex-shrink-0">
                                    <div class="bg-info bg-opacity-25 rounded-circle p-2">
                                        <i class="bi bi-arrow-up text-info"></i>
                                    </div>
                                </div>
                                <div class="flex-grow-1 ms-3">
                                    <div class="fw-semibold">Out Air Handler</div>
                                    <small class="text-muted">Below sub floor where cooled air departs</small>
                                </div>
                            </div>
                        </div>
                        <div class="list-group-item border-0 px-0">
                            <div class="d-flex align-items-center">
                                <div class="flex-shrink-0">
                                    <div class="bg-warning bg-opacity-25 rounded-circle p-2">
                                        <i class="bi bi-hdd-rack text-warning"></i>
                                    </div>
                                </div>
                                <div class="flex-grow-1 ms-3">
                                    <div class="fw-semibold">In Rack</div>
                                    <small class="text-muted">Front door of rack at 1 meter height</small>
                                </div>
                            </div>
                        </div>
                        <div class="list-group-item border-0 px-0">
                            <div class="d-flex align-items-center">
                                <div class="flex-shrink-0">
                                    <div class="bg-danger bg-opacity-25 rounded-circle p-2">
                                        <i class="bi bi-hdd-rack-fill text-danger"></i>
                                    </div>
                                </div>
                                <div class="flex-grow-1 ms-3">
                                    <div class="fw-semibold">Out Rack</div>
                                    <small class="text-muted">Back of rack at 1 meter height</small>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row mb-4">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-secondary text-white">
                    <h5 class="card-title mb-0">
                        <i class="bi bi-activity"></i> Temperature Time Series
                    </h5>
                </div>
                <div class="card-body text-center">
                    <img src="{$url}" alt="Temperature Time Series" class="img-fluid rounded shadow-sm">
                    {$battery}
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-warning text-dark">
                    <h5 class="card-title mb-0">
                        <i class="bi bi-exclamation-triangle"></i> Notable Temperature Events
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row g-3">
                        <div class="col-lg-6">
                            <div class="list-group list-group-flush">
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-primary">2008</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2008&month=05&day=16" class="text-decoration-none">16 May 2008</a>
                                            </div>
                                            <small class="text-muted">Agronomy building loses chilled water supply, heat exchanger later gets backed up on local 'cooler' water.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-warning text-dark">2010</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2010&month=06&day=14" class="text-decoration-none">14 Jun 2010</a>
                                            </div>
                                            <small class="text-muted">ISU Campus takes a power bump knocking out various utilities.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-info">2010</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2010&month=08&day=11" class="text-decoration-none">11 Aug 2010</a>
                                            </div>
                                            <small class="text-muted">Flooding impacts ISU campus and the chilled water is shut off for a while.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-success">2013</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2013&month=06&day=24" class="text-decoration-none">24 Jun 2013</a>
                                            </div>
                                            <small class="text-muted">Chilled water is turned off for an hour to check metering.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-secondary">2016</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2016&month=8&day=9" class="text-decoration-none">9 Aug 2016</a>
                                            </div>
                                            <small class="text-muted">Fan bracket is repaired on heat exchanger.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-danger">2019</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2019&month=4&day=10" class="text-decoration-none">10 Apr 2019</a>
                                            </div>
                                            <small class="text-muted">Lightning strike knocks out chilled water and then power surge knocks out a few servers.</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <div class="list-group list-group-flush">
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-warning text-dark">2020</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2020&month=4&day=11" class="text-decoration-none">11 Apr 2020</a>
                                            </div>
                                            <small class="text-muted">ISU FP&M shuts down chilled water supply to do some local construction work.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-primary">2022</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2022&month=3&day=18" class="text-decoration-none">18 Mar 2022</a>
                                            </div>
                                            <small class="text-muted">ISU FP&M shuts down chilled water supply to do some local construction work.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-info">2022</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2022&month=3&day=22" class="text-decoration-none">22 Mar 2022</a>
                                            </div>
                                            <small class="text-muted">ISU FP&M shuts down chilled water supply to do some local construction work.</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-group-item border-0 px-0">
                                    <div class="d-flex align-items-start">
                                        <div class="flex-shrink-0">
                                            <span class="badge bg-danger">2023</span>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <div class="fw-semibold">
                                                <a href="ot_10min.phtml?year=2023&month=8&day=24" class="text-decoration-none">24 Aug 2023</a>
                                            </div>
                                            <small class="text-muted">Fire at ISU FP&M shuts down chilled water supply.</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

EOM;
$t->render('single.phtml');
