跳转至

WiFi-Mat 领域模型

领域驱动设计规范

通用语言

术语 定义
幸存者 在扫描区域内检测到的人类,可能被困
生命体征 可检测的生命指标:呼吸、心跳、运动
扫描区域 正在被主动监测的已定义地理区域
检测事件 检测到生命体征的一次发生
分诊状态 医疗优先级分类(Immediate/Delayed/Minor/Deceased)
置信度分数 检测的统计确定性(0.0-1.0)
穿透深度 穿过碎片到达幸存者的估计距离
碎片场 传感器与幸存者之间的材料集合

限界上下文

1. 检测上下文

职责:分析 CSI 数据以检测并分类人类生命体征

┌─────────────────────────────────────────────────────────┐
│                  Detection Context                       │
├─────────────────────────────────────────────────────────┤
│                                                          │
│  ┌──────────────┐    ┌──────────────┐                   │
│  │   Breathing  │    │  Heartbeat   │                   │
│  │   Detector   │    │  Detector    │                   │
│  └──────┬───────┘    └──────┬───────┘                   │
│         │                   │                            │
│         └─────────┬─────────┘                           │
│                   ▼                                      │
│         ┌─────────────────┐                             │
│         │    Movement     │                             │
│         │   Classifier    │                             │
│         └────────┬────────┘                             │
│                  ▼                                       │
│         ┌─────────────────┐                             │
│         │    Ensemble     │──▶ VitalSignsReading        │
│         │   Classifier    │                             │
│         └─────────────────┘                             │
│                                                          │
└─────────────────────────────────────────────────────────┘

聚合: - VitalSignsReading(聚合根)

值对象: - BreathingPattern - HeartbeatSignature - MovementProfile - ConfidenceScore

2. 定位上下文

职责:估计碎片场中幸存者的位置

┌─────────────────────────────────────────────────────────┐
│                 Localization Context                     │
├─────────────────────────────────────────────────────────┤
│                                                          │
│  ┌──────────────┐    ┌──────────────┐                   │
│  │Triangulation │    │Fingerprinting│                   │
│  │   Engine     │    │   Matcher    │                   │
│  └──────┬───────┘    └──────┬───────┘                   │
│         │                   │                            │
│         └─────────┬─────────┘                           │
│                   ▼                                      │
│         ┌─────────────────┐                             │
│         │     Depth       │                             │
│         │   Estimator     │                             │
│         └────────┬────────┘                             │
│                  ▼                                       │
│         ┌─────────────────┐                             │
│         │   Position      │──▶ SurvivorLocation         │
│         │    Fuser        │                             │
│         └─────────────────┘                             │
│                                                          │
└─────────────────────────────────────────────────────────┘

聚合: - SurvivorLocation(聚合根)

值对象: - Coordinates3D - DepthEstimate - LocationUncertainty - DebrisProfile

3. 告警上下文

职责:基于检测结果生成并分发告警

┌─────────────────────────────────────────────────────────┐
│                   Alerting Context                       │
├─────────────────────────────────────────────────────────┤
│                                                          │
│  ┌──────────────┐    ┌──────────────┐                   │
│  │   Triage     │    │   Alert      │                   │
│  │  Calculator  │    │  Generator   │                   │
│  └──────┬───────┘    └──────┬───────┘                   │
│         │                   │                            │
│         └─────────┬─────────┘                           │
│                   ▼                                      │
│         ┌─────────────────┐                             │
│         │   Dispatcher    │──▶ Alert                    │
│         └─────────────────┘                             │
│                                                          │
└─────────────────────────────────────────────────────────┘

聚合: - Alert(聚合根)

值对象: - TriageStatus - Priority - AlertPayload


核心领域实体

Survivor(实体)

pub struct Survivor {
    id: SurvivorId,
    detection_time: DateTime<Utc>,
    location: Option<SurvivorLocation>,
    vital_signs: VitalSignsHistory,
    triage_status: TriageStatus,
    confidence: ConfidenceScore,
    metadata: SurvivorMetadata,
}

不变量: - 必须至少有一次生命体征检测才能存在 - 每次生命体征更新时必须重新计算分诊状态 - 置信度必须 >= 0.3 才被视为有效检测

DisasterEvent(聚合根)

pub struct DisasterEvent {
    id: DisasterEventId,
    event_type: DisasterType,
    start_time: DateTime<Utc>,
    location: GeoLocation,
    scan_zones: Vec<ScanZone>,
    survivors: Vec<Survivor>,
    status: EventStatus,
}

不变量: - 必须至少有一个扫描区域 - 所有幸存者必须位于扫描区域内 - 事件关闭后不能添加幸存者

ScanZone(实体)

pub struct ScanZone {
    id: ScanZoneId,
    bounds: ZoneBounds,
    sensor_positions: Vec<SensorPosition>,
    scan_parameters: ScanParameters,
    status: ZoneStatus,
    last_scan: DateTime<Utc>,
}

值对象

VitalSignsReading

pub struct VitalSignsReading {
    breathing: Option<BreathingPattern>,
    heartbeat: Option<HeartbeatSignature>,
    movement: MovementProfile,
    timestamp: DateTime<Utc>,
    confidence: ConfidenceScore,
}

TriageStatus(枚举)

pub enum TriageStatus {
    /// Immediate - Life-threatening, requires immediate intervention
    Immediate,  // Red tag

    /// Delayed - Serious but can wait for treatment
    Delayed,    // Yellow tag

    /// Minor - Walking wounded, minimal treatment needed
    Minor,      // Green tag

    /// Deceased - No vital signs detected over threshold period
    Deceased,   // Black tag

    /// Unknown - Insufficient data for classification
    Unknown,
}

BreathingPattern

pub struct BreathingPattern {
    rate_bpm: f32,           // Breaths per minute (normal: 12-20)
    amplitude: f32,          // Signal strength
    regularity: f32,         // 0.0-1.0, consistency of pattern
    pattern_type: BreathingType,
}

pub enum BreathingType {
    Normal,
    Shallow,
    Labored,
    Irregular,
    Agonal,
}

HeartbeatSignature

pub struct HeartbeatSignature {
    rate_bpm: f32,           // Beats per minute (normal: 60-100)
    variability: f32,        // Heart rate variability
    strength: SignalStrength,
}

Coordinates3D

pub struct Coordinates3D {
    x: f64,  // East-West offset from reference (meters)
    y: f64,  // North-South offset from reference (meters)
    z: f64,  // Depth below surface (meters, negative = below)
    uncertainty: LocationUncertainty,
}

pub struct LocationUncertainty {
    horizontal_error: f64,  // meters (95% confidence)
    vertical_error: f64,    // meters (95% confidence)
}

领域事件

检测事件

pub enum DetectionEvent {
    /// New survivor detected
    SurvivorDetected {
        survivor_id: SurvivorId,
        zone_id: ScanZoneId,
        vital_signs: VitalSignsReading,
        location: Option<Coordinates3D>,
        timestamp: DateTime<Utc>,
    },

    /// Survivor vital signs updated
    VitalsUpdated {
        survivor_id: SurvivorId,
        previous: VitalSignsReading,
        current: VitalSignsReading,
        timestamp: DateTime<Utc>,
    },

    /// Survivor triage status changed
    TriageStatusChanged {
        survivor_id: SurvivorId,
        previous: TriageStatus,
        current: TriageStatus,
        reason: String,
        timestamp: DateTime<Utc>,
    },

    /// Survivor location refined
    LocationRefined {
        survivor_id: SurvivorId,
        previous: Coordinates3D,
        current: Coordinates3D,
        timestamp: DateTime<Utc>,
    },

    /// Survivor no longer detected (may have been rescued or false positive)
    SurvivorLost {
        survivor_id: SurvivorId,
        last_detection: DateTime<Utc>,
        reason: LostReason,
    },
}

pub enum LostReason {
    Rescued,
    FalsePositive,
    SignalLost,
    ZoneDeactivated,
}

告警事件

pub enum AlertEvent {
    /// New alert generated
    AlertGenerated {
        alert_id: AlertId,
        survivor_id: SurvivorId,
        priority: Priority,
        payload: AlertPayload,
    },

    /// Alert acknowledged by rescue team
    AlertAcknowledged {
        alert_id: AlertId,
        acknowledged_by: TeamId,
        timestamp: DateTime<Utc>,
    },

    /// Alert resolved
    AlertResolved {
        alert_id: AlertId,
        resolution: AlertResolution,
        timestamp: DateTime<Utc>,
    },
}

领域服务

TriageService

使用 START 协议根据生命体征计算分诊状态:

pub trait TriageService {
    fn calculate_triage(&self, vitals: &VitalSignsReading) -> TriageStatus;
    fn should_upgrade_priority(&self, history: &VitalSignsHistory) -> bool;
}

规则: 1. 未检测到呼吸 → 检查活动 2. 有活动但无呼吸 → Immediate(气道问题) 3. 呼吸 > 30 次/分钟 → Immediate 4. 呼吸 < 10 次/分钟 → Immediate 5. 无桡动脉脉搏等效信号(心跳微弱)→ Immediate 6. 无法遵循指令(无响应性活动)→ Immediate 7. 否则 → 根据严重程度为 Delayed 或 Minor

LocalizationService

融合多种定位技术:

pub trait LocalizationService {
    fn estimate_position(
        &self,
        csi_data: &[CsiReading],
        sensor_positions: &[SensorPosition],
    ) -> Result<Coordinates3D, LocalizationError>;

    fn estimate_depth(
        &self,
        signal_attenuation: f64,
        debris_profile: &DebrisProfile,
    ) -> Result<DepthEstimate, LocalizationError>;
}

上下文映射

┌────────────────────────────────────────────────────────────────┐
│                        WiFi-Mat System                          │
├────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────┐         ┌─────────────┐                       │
│  │  Detection  │◄───────►│ Localization│                       │
│  │   Context   │ Partner │   Context   │                       │
│  └──────┬──────┘         └──────┬──────┘                       │
│         │                       │                               │
│         │ Publishes             │ Publishes                     │
│         ▼                       ▼                               │
│  ┌─────────────────────────────────────┐                       │
│  │         Event Bus (Domain Events)    │                       │
│  └─────────────────┬───────────────────┘                       │
│                    │                                            │
│                    │ Subscribes                                 │
│                    ▼                                            │
│            ┌─────────────┐                                      │
│            │  Alerting   │                                      │
│            │   Context   │                                      │
│            └─────────────┘                                      │
│                                                                 │
├─────────────────────────────────────────────────────────────────┤
│                    UPSTREAM (Conformist)                        │
│  ┌───────────────┐  ┌───────────────┐  ┌───────────────┐       │
│  │wifi-densepose │  │wifi-densepose │  │wifi-densepose │       │
│  │    -signal    │  │     -nn       │  │   -hardware   │       │
│  └───────────────┘  └───────────────┘  └───────────────┘       │
└─────────────────────────────────────────────────────────────────┘

关系类型: - Detection ↔ Localization:合作伙伴(紧密协作) - Detection → Alerting:客户/供应商(Detection 发布,Alerting 消费) - WiFi-Mat → 上游 crate:追随者(适配其模型)


防腐层

集成模块提供适配器,用于在上游 crate 模型与 WiFi-Mat 领域之间进行转换:

/// Adapts wifi-densepose-signal types to Detection context
pub struct SignalAdapter {
    processor: CsiProcessor,
    feature_extractor: FeatureExtractor,
}

impl SignalAdapter {
    pub fn extract_vital_features(
        &self,
        raw_csi: &[Complex<f64>],
    ) -> Result<VitalFeatures, AdapterError>;
}

/// Adapts wifi-densepose-nn for specialized detection models
pub struct NeuralAdapter {
    breathing_model: OnnxModel,
    heartbeat_model: OnnxModel,
}

impl NeuralAdapter {
    pub fn classify_breathing(
        &self,
        features: &VitalFeatures,
    ) -> Result<BreathingPattern, AdapterError>;
}

仓储接口

#[async_trait]
pub trait SurvivorRepository {
    async fn save(&self, survivor: &Survivor) -> Result<(), RepositoryError>;
    async fn find_by_id(&self, id: &SurvivorId) -> Result<Option<Survivor>, RepositoryError>;
    async fn find_by_zone(&self, zone_id: &ScanZoneId) -> Result<Vec<Survivor>, RepositoryError>;
    async fn find_active(&self) -> Result<Vec<Survivor>, RepositoryError>;
}

#[async_trait]
pub trait DisasterEventRepository {
    async fn save(&self, event: &DisasterEvent) -> Result<(), RepositoryError>;
    async fn find_active(&self) -> Result<Vec<DisasterEvent>, RepositoryError>;
    async fn find_by_location(&self, location: &GeoLocation, radius_km: f64) -> Result<Vec<DisasterEvent>, RepositoryError>;
}

#[async_trait]
pub trait AlertRepository {
    async fn save(&self, alert: &Alert) -> Result<(), RepositoryError>;
    async fn find_pending(&self) -> Result<Vec<Alert>, RepositoryError>;
    async fn find_by_survivor(&self, survivor_id: &SurvivorId) -> Result<Vec<Alert>, RepositoryError>;
}

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView