Add 'All' history range to the dashboard and pressure tendency chart
Publish Container / publish (push) Successful in 2m45s
Publish Container / publish (push) Successful in 2m45s
- /api/station/history?range=all returns everything on disk, bucketed (cached 60s) - Year-aware axis labels for 1y/2y/3y/All - Pressure tendency widens its change window to the bucket size on long ranges and says so Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fc390b0bb1
commit
00336c6ce1
2 files changed
+40
-9
No files matched your search
+25
-1
@@ -1475,13 +1475,37 @@ function bucketReadings(readings, points) {
|
||||
app.get('/api/station/history', requireDashboardAuth, (req, res) => {
|
||||
const rangeMap = { '1h': 3600000, '6h': 21600000, '24h': 86400000, '2d': 172800000, '7d': 604800000, '30d': 2592000000, '90d': 7776000000, '1y': 31536000000, '2y': 63072000000, '3y': 94608000000 };
|
||||
const range = req.query.range || '24h';
|
||||
const points = parseInt(req.query.points);
|
||||
|
||||
if (range === 'all') {
|
||||
// Everything on disk, always bucketed (default 720 points) so the payload stays small
|
||||
const first = firstStationDay();
|
||||
if (!first) return res.json([]);
|
||||
const rangeAll = Date.now() - Date.parse(first + 'T00:00:00Z') + 2 * 86400000;
|
||||
const pts = points >= 50 ? points : 720;
|
||||
const key = `${first}|${pts}`;
|
||||
if (allHistoryCache.key === key && Date.now() - allHistoryCache.at < 60000) return res.json(allHistoryCache.data);
|
||||
const readingsAll = loadStationReadings(rangeAll);
|
||||
const data = readingsAll.length > pts ? bucketReadings(readingsAll, pts) : readingsAll;
|
||||
allHistoryCache = { key, at: Date.now(), data };
|
||||
return res.json(data);
|
||||
}
|
||||
|
||||
const rangeMs = rangeMap[range] || rangeMap['24h'];
|
||||
const readings = loadStationReadings(rangeMs);
|
||||
const points = parseInt(req.query.points);
|
||||
if (points >= 50 && readings.length > points) return res.json(bucketReadings(readings, points));
|
||||
res.json(readings);
|
||||
});
|
||||
|
||||
// Earliest day with saved readings (YYYY-MM-DD, UTC file name)
|
||||
let allHistoryCache = { key: null, at: 0, data: null };
|
||||
function firstStationDay() {
|
||||
try {
|
||||
const files = fs.readdirSync(STATION_DIR).filter(f => /^\d{4}-\d{2}-\d{2}\.jsonl$/.test(f)).sort();
|
||||
return files.length ? files[0].slice(0, 10) : null;
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
// Latest station reading
|
||||
app.get('/api/station/latest', requireDashboardAuth, async (req, res) => {
|
||||
if (!ambientServerConfig.apiKey || !ambientServerConfig.appKey) {
|
||||
|
||||
Reference in new issue
Block a user