Rename history windows to Today/Yesterday/Week/Month, tighten header spacing

This commit is contained in:
Justin Oro
2026-08-18 11:40:02 -07:00
parent c0b161a932
commit 56eb1547f8
+22 -15
View File
@@ -264,16 +264,21 @@ class Sampler:
def windowed_history(self, window): def windowed_history(self, window):
from . import tune from . import tune
window_seconds = {"1d": 86400, "7d": 7 * 86400, "30d": 30 * 86400}.get( now = time.time()
window, 86400 window_bounds = {
) "today": (now - 86400, now),
"yesterday": (now - 2 * 86400, now - 86400 - 0.001),
"week": (now - 7 * 86400, now),
"month": (now - 30 * 86400, now),
}
since_epoch, until_epoch = window_bounds.get(window, window_bounds["today"])
serial, name = self._live_anker_serial() serial, name = self._live_anker_serial()
if not serial: if not serial:
return {"points": [], "grid": None, "serial": None, "name": None} return {"points": [], "grid": None, "serial": None, "name": None}
since_epoch = time.time() - window_seconds
records = tune.load_telemetry(serial, since_epoch=since_epoch) records = tune.load_telemetry(serial, since_epoch=since_epoch)
records = [r for r in records if r[0] <= until_epoch]
max_points = 600 max_points = 600
step = max(1, len(records) // max_points) step = max(1, len(records) // max_points)
@@ -1122,9 +1127,10 @@ PAGE = """<!doctype html>
<span><i class="swatch sw-batt"></i>battery</span> <span><i class="swatch sw-batt"></i>battery</span>
</div> </div>
<span class="theme" role="group" aria-label="Time window"> <span class="theme" role="group" aria-label="Time window">
<button type="button" id="window1d" aria-pressed="true">1 DAY</button> <button type="button" id="windowtoday" aria-pressed="true">TODAY</button>
<button type="button" id="window7d" aria-pressed="false">7 DAYS</button> <button type="button" id="windowyesterday" aria-pressed="false">YESTERDAY</button>
<button type="button" id="window30d" aria-pressed="false">30 DAYS</button> <button type="button" id="windowweek" aria-pressed="false">WEEK</button>
<button type="button" id="windowmonth" aria-pressed="false">MONTH</button>
</span> </span>
</div> </div>
<canvas id="chart"></canvas> <canvas id="chart"></canvas>
@@ -1731,7 +1737,7 @@ function clearChartCrosshair() {
let latest = null; let latest = null;
let paused = false; let paused = false;
let currentHistory = { points: [], grid: null, serial: null, name: null }; let currentHistory = { points: [], grid: null, serial: null, name: null };
let currentWindow = '1d'; let currentWindow = 'today';
const PANEL_KEY = 'solixauto-collapsed'; const PANEL_KEY = 'solixauto-collapsed';
@@ -1926,7 +1932,7 @@ function renderGridUsage(grid) {
async function loadHistory(win) { async function loadHistory(win) {
currentWindow = win; currentWindow = win;
['1d', '7d', '30d'].forEach(w => { ['today', 'yesterday', 'week', 'month'].forEach(w => {
const button = document.getElementById('window' + w); const button = document.getElementById('window' + w);
if (button) button.setAttribute('aria-pressed', w === win ? 'true' : 'false'); if (button) button.setAttribute('aria-pressed', w === win ? 'true' : 'false');
}); });
@@ -1947,9 +1953,10 @@ async function loadHistory(win) {
refitIfEnabled(); refitIfEnabled();
} }
document.getElementById('window1d').addEventListener('click', () => loadHistory('1d')); document.getElementById('windowtoday').addEventListener('click', () => loadHistory('today'));
document.getElementById('window7d').addEventListener('click', () => loadHistory('7d')); document.getElementById('windowyesterday').addEventListener('click', () => loadHistory('yesterday'));
document.getElementById('window30d').addEventListener('click', () => loadHistory('30d')); document.getElementById('windowweek').addEventListener('click', () => loadHistory('week'));
document.getElementById('windowmonth').addEventListener('click', () => loadHistory('month'));
refresh(); refresh();
loadHistory(currentWindow); loadHistory(currentWindow);
@@ -1998,9 +2005,9 @@ class Handler(BaseHTTPRequestHandler):
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
query = parse_qs(urlparse(self.path).query) query = parse_qs(urlparse(self.path).query)
window = (query.get("window") or ["1d"])[0] window = (query.get("window") or ["today"])[0]
if window not in ("1d", "7d", "30d"): if window not in ("today", "yesterday", "week", "month"):
window = "1d" window = "today"
result = Handler.sampler.windowed_history(window) result = Handler.sampler.windowed_history(window)
self._send(200, json.dumps(result), "application/json") self._send(200, json.dumps(result), "application/json")
return return