feat: date-range picker on the station history panel; drop PostgreSQL naming
CI/CD Pipeline - Northern Thailand Ping River Monitor / Build Docker Image (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Integration Test with Services (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Staging (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Deploy to Production (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Performance Test (push) Skipped
CI/CD Pipeline - Northern Thailand Ping River Monitor / Code Quality (push) Successful in 14s
Documentation / Validate Documentation (push) Failing after 8s
Documentation / Generate API Documentation (push) Successful in 10s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Test Suite (3.11) (push) Failing after 24s
Documentation / Build Sphinx Documentation (push) Successful in 19s
CI/CD Pipeline - Northern Thailand Ping River Monitor / Cleanup (push) Successful in 0s
Documentation / Documentation Summary (push) Successful in 2s

/measurements/history/{code} accepts optional start/end date params that
override the hours window (end date inclusive). The dashboard history
card gains from/to date inputs beside the quick-range dropdown —
explicit dates win, changing the dropdown clears them. All user-facing
'PostgreSQL history' labels renamed to 'Station history'.
This commit is contained in:
2026-08-11 15:52:40 +07:00
parent d29d49eac7
commit 9516857d44
3 changed files with 43 additions and 14 deletions
+14 -5
View File
@@ -8,7 +8,7 @@ import os
import secrets
import time
from contextlib import asynccontextmanager
from datetime import datetime, timedelta
from datetime import date, datetime, timedelta
from decimal import Decimal
from threading import Lock
from typing import Any, Dict, List, Optional
@@ -609,9 +609,11 @@ async def get_postgres_history(
station_code: str,
hours: int = Query(168, ge=1),
limit: int = Query(50000, ge=1, le=100000),
start: Optional[date] = Query(None, description="First day (overrides hours)"),
end: Optional[date] = Query(None, description="Last day, inclusive"),
):
"""Get historical measurements for a station from the configured database."""
cache_key = f"{station_code}:{hours}:{limit}"
cache_key = f"{station_code}:{hours}:{limit}:{start}:{end}"
now = time.monotonic()
with HISTORY_CACHE_LOCK:
cached = HISTORY_CACHE.get(cache_key)
@@ -619,13 +621,20 @@ async def get_postgres_history(
return cached[1]
try:
db_config = Config.get_database_config()
end_time = datetime.now()
end_time = (
datetime.combine(end, datetime.max.time()) if end else datetime.now()
)
start_time = (
datetime.combine(start, datetime.min.time())
if start
else end_time - timedelta(hours=hours)
)
if db_config["type"] == "postgresql":
history = PostgresHistory(db_config["connection_string"])
data = await asyncio.to_thread(
history.station_history,
station_code,
end_time - timedelta(hours=hours),
start_time,
end_time,
limit,
)
@@ -635,7 +644,7 @@ async def get_postgres_history(
raise RuntimeError("Database not available")
rows = await asyncio.to_thread(
scraper.db_adapter.get_measurements_by_timerange,
end_time - timedelta(hours=hours),
start_time,
end_time,
[station_code],
)