fix: GPS缺失下的数据缺失问题

This commit is contained in:
2026-04-18 13:12:54 +08:00
parent 2ca70d556b
commit 5fdb42b5ed
3 changed files with 42 additions and 13 deletions

View File

@@ -91,6 +91,12 @@ USE_TZ = True
STATIC_URL = 'static/' STATIC_URL = 'static/'
CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_ALL_ORIGINS = True
CORS_EXPOSE_HEADERS = [
'X-Blitz-Frame-Seq',
'X-Blitz-Backend-Received-Unix-Ns',
'X-Blitz-Frame-Hash',
'X-Blitz-BSide-Capture-To-Send-Ms',
]
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

View File

@@ -105,13 +105,30 @@ class GpsDataService:
} }
def _build_payload_from_metadata(self, metadata: FrameTrailerMetadata) -> dict[str, Any]: def _build_payload_from_metadata(self, metadata: FrameTrailerMetadata) -> dict[str, Any]:
timestamp_seconds = metadata.timestamp_ns / 1_000_000_000
updated_at = _utc_from_epoch(metadata.received_at) or "" updated_at = _utc_from_epoch(metadata.received_at) or ""
if not metadata.has_gps_fix:
return {
"has_fix": False,
"utc_time": "--:--:--",
"latitude": None,
"longitude": None,
"raw_latitude_hex": f"0x{metadata.raw_latitude_hex}",
"raw_longitude_hex": f"0x{metadata.raw_longitude_hex}",
"satellites": None,
"altitude_m": None,
"coordinate_system": "WGS84",
"source_sentence": "VIDEO_TRAILER",
"raw_coordinate_format": VIDEO_TRAILER_COORDINATE_FORMAT,
"source_mode": "video-frame-trailer-no-fix",
"updated_at": updated_at,
}
timestamp_seconds = metadata.timestamp_ns / 1_000_000_000
return { return {
"has_fix": True, "has_fix": True,
"utc_time": datetime.fromtimestamp(timestamp_seconds, timezone.utc).strftime("%H:%M:%S"), "utc_time": datetime.fromtimestamp(timestamp_seconds, timezone.utc).strftime("%H:%M:%S"),
"latitude": round(metadata.latitude, 6), "latitude": round(metadata.latitude, 6) if metadata.latitude is not None else None,
"longitude": round(metadata.longitude, 6), "longitude": round(metadata.longitude, 6) if metadata.longitude is not None else None,
"raw_latitude_hex": f"0x{metadata.raw_latitude_hex}", "raw_latitude_hex": f"0x{metadata.raw_latitude_hex}",
"raw_longitude_hex": f"0x{metadata.raw_longitude_hex}", "raw_longitude_hex": f"0x{metadata.raw_longitude_hex}",
"satellites": None, "satellites": None,

View File

@@ -103,13 +103,17 @@ class VideoDisplayProbeStore:
@dataclass(frozen=True) @dataclass(frozen=True)
class FrameTrailerMetadata: class FrameTrailerMetadata:
timestamp_ns: int timestamp_ns: int
latitude: float latitude: float | None
longitude: float longitude: float | None
capture_to_send_ms: int capture_to_send_ms: int
raw_latitude_hex: str raw_latitude_hex: str
raw_longitude_hex: str raw_longitude_hex: str
received_at: float received_at: float
@property
def has_gps_fix(self) -> bool:
return self.latitude is not None and self.longitude is not None
@dataclass(frozen=True) @dataclass(frozen=True)
class VideoDisplayProbeStatus: class VideoDisplayProbeStatus:
@@ -271,21 +275,23 @@ class OmniSocketVideoReceiver:
if timestamp_ms <= 0: if timestamp_ms <= 0:
return None return None
if not math.isfinite(latitude) or not math.isfinite(longitude):
return None
if not (-90.0 <= latitude <= 90.0) or not (-180.0 <= longitude <= 180.0):
return None
if abs(latitude) < 1e-9 and abs(longitude) < 1e-9:
return None
timestamp_ns = timestamp_ms * VIDEO_TRAILER_TIMESTAMP_MULTIPLIER_NS timestamp_ns = timestamp_ms * VIDEO_TRAILER_TIMESTAMP_MULTIPLIER_NS
if abs(time.time_ns() - timestamp_ns) > VIDEO_TRAILER_TIMESTAMP_MAX_SKEW_NS: if abs(time.time_ns() - timestamp_ns) > VIDEO_TRAILER_TIMESTAMP_MAX_SKEW_NS:
return None return None
gps_fix_available = (
math.isfinite(latitude)
and math.isfinite(longitude)
and (-90.0 <= latitude <= 90.0)
and (-180.0 <= longitude <= 180.0)
and not (abs(latitude) < 1e-9 and abs(longitude) < 1e-9)
)
return FrameTrailerMetadata( return FrameTrailerMetadata(
timestamp_ns=timestamp_ns, timestamp_ns=timestamp_ns,
latitude=latitude, latitude=latitude if gps_fix_available else None,
longitude=longitude, longitude=longitude if gps_fix_available else None,
capture_to_send_ms=int(capture_to_send_ms), capture_to_send_ms=int(capture_to_send_ms),
raw_latitude_hex=trailer[8:16].hex(), raw_latitude_hex=trailer[8:16].hex(),
raw_longitude_hex=trailer[16:24].hex(), raw_longitude_hex=trailer[16:24].hex(),