fix: support tdengine gb32960 raw queries
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -25,7 +25,7 @@ SHANGHAI = dt.timezone(dt.timedelta(hours=8))
|
||||
DEFAULT_SAMPLE = (
|
||||
"modules/protocols/protocol-gb32960/src/test/resources/samples/gb32960/realtime_001.hex"
|
||||
)
|
||||
DEFAULT_FIELD_KEYS = "speed_kmh,total_mileage_km,longitude,latitude"
|
||||
DEFAULT_FIELD_KEYS = "VEHICLE.speedKmh,VEHICLE.totalMileageKm,POSITION_V2016.longitude,POSITION_V2016.latitude"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -104,7 +104,6 @@ def wait_for_records(
|
||||
) -> list[dict[str, Any]]:
|
||||
deadline = time.monotonic() + timeout_seconds
|
||||
params = {
|
||||
"protocol": "GB32960",
|
||||
"vin": vin,
|
||||
"dateFrom": date_from,
|
||||
"dateTo": date_to,
|
||||
@@ -113,7 +112,7 @@ def wait_for_records(
|
||||
}
|
||||
last_items: list[dict[str, Any]] = []
|
||||
while time.monotonic() < deadline:
|
||||
response = query_json(history_base_url, "/api/event-history/records", params, request_timeout)
|
||||
response = query_json(history_base_url, "/api/event-history/gb32960/snapshots", params, request_timeout)
|
||||
last_items = response if isinstance(response, list) else []
|
||||
if len(last_items) >= minimum:
|
||||
return last_items
|
||||
@@ -132,9 +131,8 @@ def wait_for_fields(
|
||||
) -> list[dict[str, Any]]:
|
||||
deadline = time.monotonic() + timeout_seconds
|
||||
params = {
|
||||
"protocol": "GB32960",
|
||||
"vin": vin,
|
||||
"fieldKey": field_key,
|
||||
"fields": field_key,
|
||||
"dateFrom": date_from,
|
||||
"dateTo": date_to,
|
||||
"limit": 10,
|
||||
@@ -142,9 +140,9 @@ def wait_for_fields(
|
||||
}
|
||||
last_items: list[dict[str, Any]] = []
|
||||
while time.monotonic() < deadline:
|
||||
response = query_json(history_base_url, "/api/event-history/telemetry/fields", params, request_timeout)
|
||||
last_items = response.get("items") if isinstance(response, dict) else []
|
||||
if last_items:
|
||||
response = query_json(history_base_url, "/api/event-history/gb32960/snapshots/fields", params, request_timeout)
|
||||
last_items = response if isinstance(response, list) else []
|
||||
if any((item.get("fields") or {}).get(field_key) is not None for item in last_items):
|
||||
return last_items
|
||||
time.sleep(1)
|
||||
return last_items
|
||||
@@ -183,9 +181,8 @@ def archive_path(root: pathlib.Path, uri: str) -> pathlib.Path:
|
||||
def check_archive(root: pathlib.Path, records: list[dict[str, Any]], limit: int) -> int:
|
||||
checked = 0
|
||||
seen: set[str] = set()
|
||||
for record in records:
|
||||
uri = record.get("rawArchiveUri") or ""
|
||||
if not uri or uri in seen:
|
||||
for uri in raw_uris(records):
|
||||
if uri in seen:
|
||||
continue
|
||||
seen.add(uri)
|
||||
path = archive_path(root, uri)
|
||||
@@ -207,9 +204,8 @@ def raw_frame_count_sql(info: FrameInfo, records: list[dict[str, Any]]) -> str:
|
||||
def raw_frame_count_sqls(info: FrameInfo, records: list[dict[str, Any]]) -> list[str]:
|
||||
seen: set[str] = set()
|
||||
sqls: list[str] = []
|
||||
for record in records:
|
||||
uri = record.get("rawArchiveUri") or ""
|
||||
if not uri or uri in seen:
|
||||
for uri in raw_uris(records):
|
||||
if uri in seen:
|
||||
continue
|
||||
seen.add(uri)
|
||||
sqls.append(tdengine_smoke.raw_frame_count_sql(
|
||||
@@ -244,7 +240,8 @@ def verify_tdengine_raw_frames(
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
frame = read_hex_frame(pathlib.Path(args.frame_hex_file))
|
||||
info = parse_frame_info(frame)
|
||||
date_from, date_to = query_range(info.event_time, args.window_minutes)
|
||||
query_center = dt.datetime.now(tz=SHANGHAI)
|
||||
date_from, date_to = query_range(query_center, args.window_minutes)
|
||||
|
||||
ack = send_frame(args.tcp_host, args.tcp_port, frame, args.tcp_timeout)
|
||||
if args.require_ack and not valid_ack(ack):
|
||||
@@ -298,6 +295,9 @@ def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
"vin": info.vin,
|
||||
"command": f"0x{info.command:02x}",
|
||||
"eventTime": info.event_time.isoformat() if info.event_time else None,
|
||||
"queryTimeSource": "received",
|
||||
"queryDateFrom": date_from,
|
||||
"queryDateTo": date_to,
|
||||
"ackBytesHex": ack.hex(),
|
||||
"records": len(records),
|
||||
"fieldCounts": field_counts,
|
||||
@@ -308,11 +308,23 @@ def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
|
||||
|
||||
def first_raw_uri(records: list[dict[str, Any]]) -> str | None:
|
||||
uris = raw_uris(records)
|
||||
if uris:
|
||||
return uris[0]
|
||||
return None
|
||||
|
||||
|
||||
def raw_uris(records: list[dict[str, Any]]) -> list[str]:
|
||||
out: list[str] = []
|
||||
for record in records:
|
||||
uri = record.get("rawArchiveUri")
|
||||
if uri:
|
||||
return uri
|
||||
return None
|
||||
if isinstance(uri, str) and uri:
|
||||
out.append(uri)
|
||||
for frame in record.get("sourceFrames") or []:
|
||||
frame_uri = frame.get("rawArchiveUri") if isinstance(frame, dict) else ""
|
||||
if frame_uri:
|
||||
out.append(frame_uri)
|
||||
return out
|
||||
|
||||
|
||||
def parser() -> argparse.ArgumentParser:
|
||||
|
||||
Reference in New Issue
Block a user