Filter runway history by observation time
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from concurrent.futures import ThreadPoolExecutor, TimeoutError
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import sqlite3
|
||||
import threading
|
||||
import time
|
||||
@@ -270,11 +271,12 @@ def test_observation_collector_persists_amsc_runway_history(tmp_path):
|
||||
observation_store=db,
|
||||
)
|
||||
|
||||
observed_at = datetime.now(timezone.utc).replace(microsecond=0).isoformat()
|
||||
record = ObservationRecord(
|
||||
source="amsc_awos",
|
||||
city="chengdu",
|
||||
value=28.4,
|
||||
observed_at="2026-06-15T10:51:00+00:00",
|
||||
observed_at=observed_at,
|
||||
observed_at_local="2026-06-15 18:51:00",
|
||||
station_code="ZUUU",
|
||||
station_name="Chengdu Shuangliu",
|
||||
@@ -313,11 +315,40 @@ def test_observation_collector_persists_amsc_runway_history(tmp_path):
|
||||
rows = db.get_runway_obs_recent("ZUUU", minutes=60)
|
||||
|
||||
assert [row["runway"] for row in rows] == ["02L/20R", "02R/20L"]
|
||||
assert rows[0]["otime_utc"] == "2026-06-15T10:51:00+00:00"
|
||||
assert rows[0]["otime_utc"] == observed_at
|
||||
assert rows[0]["target_runway_max"] == 28.4
|
||||
assert rows[0]["wind_dir"] == 130
|
||||
|
||||
|
||||
def test_runway_obs_recent_filters_by_observation_time_not_insert_time(tmp_path):
|
||||
from src.database.db_manager import DBManager
|
||||
|
||||
db = DBManager(str(tmp_path / "polyweather.db"))
|
||||
now = datetime.now(timezone.utc).replace(microsecond=0)
|
||||
stale_observed_at = (now - timedelta(hours=3)).isoformat()
|
||||
fresh_observed_at = now.isoformat()
|
||||
|
||||
db.append_runway_obs(
|
||||
icao="ZUUU",
|
||||
city="chengdu",
|
||||
runway="02L/20R",
|
||||
target_runway_max=24.0,
|
||||
otime_utc=stale_observed_at,
|
||||
)
|
||||
db.append_runway_obs(
|
||||
icao="ZUUU",
|
||||
city="chengdu",
|
||||
runway="02R/20L",
|
||||
target_runway_max=25.0,
|
||||
otime_utc=fresh_observed_at,
|
||||
)
|
||||
|
||||
rows = db.get_runway_obs_recent("ZUUU", minutes=60)
|
||||
|
||||
assert [row["runway"] for row in rows] == ["02R/20L"]
|
||||
assert rows[0]["otime_utc"] == fresh_observed_at
|
||||
|
||||
|
||||
def test_raw_observation_failure_preserves_last_success_and_increments_errors(tmp_path):
|
||||
from src.database.db_manager import DBManager
|
||||
|
||||
|
||||
Reference in New Issue
Block a user