# KPI и тревоги

## 1. Scope и версия

- `industry_code`: `swine`
- `profile_id`: `swine-kpi-alarm-v1`
- `version`: `1.0.0`
- `owner`: `platform-product`
- `updated_at`: `2026-03-06`

## 2. KPI baseline

| kpi_id | title | key_entity | primary_unit | window | owner_module | source_modules | targets |
| --- | --- | --- | --- | --- | --- | --- | --- |
| `barn_temp_compliance_pct` | Температурный комплаенс | `barn_climate_profile` | `%` | `1h` | `industry.swine.climate` | `["industry.swine.climate"]` | `warn < 92`, `critical < 85` |
| `barn_humidity_compliance_pct` | Комплаенс влажности | `barn_climate_profile` | `%` | `1h` | `industry.swine.climate` | `["industry.swine.climate"]` | `warn < 90`, `critical < 82` |
| `co2_peak_ppm` | Пик CO2 | `barn_climate_profile` | `ppm` | `1h` | `industry.swine.climate` | `["industry.swine.climate"]` | `warn > 2800`, `critical > 3200` |
| `feed_intake_g_head_day` | Потребление корма на голову | `feeding_plan_snapshot` | `g/head/day` | `24h` | `industry.swine.feeding` | `["industry.swine.feeding"]` | `warn deviation >= 8%`, `critical deviation >= 12%` |
| `water_intake_l_head_day` | Потребление воды на голову | `water_consumption_snapshot` | `L/head/day` | `24h` | `industry.swine.water` | `["industry.swine.water"]` | `warn deviation >= 10%`, `critical deviation >= 15%` |
| `feed_water_ratio` | Соотношение feed/water | `production_batch_kpi` | `ratio` | `24h` | `industry.swine.production` | `["industry.swine.feeding","industry.swine.water","industry.swine.production"]` | `warn outside 0.9..1.4`, `critical outside 0.8..1.6` |
| `adg_g_day` | Среднесуточный привес (ADG) | `production_batch_kpi` | `g/day` | `cycle` | `industry.swine.production` | `["industry.swine.production"]` | `warn < 750`, `critical < 680` |
| `mortality_pct_cycle` | Падеж по циклу | `production_batch_kpi` | `%` | `cycle` | `industry.swine.production` | `["industry.swine.production","industry.swine.biosecurity"]` | `warn > 2.0`, `critical > 3.0` |
| `biosecurity_incidents_24h` | Инциденты биобезопасности | `biosecurity_event` | `count/24h` | `24h` | `industry.swine.biosecurity` | `["industry.swine.biosecurity"]` | `warn >= 1`, `critical >= 2` |

## 3. Alarm baseline

| alarm_code | source_kpi | condition | severity | priority | debounce | dedup_key | escalation_policy | status_bridge | correlation_fields |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| `swine_temp_high` | `barn_temp_compliance_pct` | `temp_c > profile.temp_max_c` | `critical` | `P1` | `120s` | `site_id+house_id+alarm_code` | `operator(5m)->engineer(15m)` | `true` | `tenant_id,industry_code,site_id,house_id,batch_id` |
| `swine_temp_low` | `barn_temp_compliance_pct` | `temp_c < profile.temp_min_c` | `critical` | `P1` | `120s` | `site_id+house_id+alarm_code` | `operator(5m)->engineer(15m)` | `true` | `tenant_id,industry_code,site_id,house_id,batch_id` |
| `swine_co2_high` | `co2_peak_ppm` | `co2_ppm > 3200` | `high` | `P1` | `180s` | `site_id+house_id+alarm_code` | `operator(10m)->engineer(30m)` | `true` | `tenant_id,industry_code,site_id,house_id,batch_id` |
| `swine_water_anomaly` | `water_intake_l_head_day` | `abs(water_deviation_pct) >= 15` | `high` | `P2` | `300s` | `site_id+house_id+alarm_code` | `operator(15m)->supervisor(60m)` | `true` | `tenant_id,industry_code,site_id,house_id,batch_id` |
| `swine_feed_anomaly` | `feed_intake_g_head_day` | `abs(feed_deviation_pct) >= 12` | `medium` | `P2` | `300s` | `site_id+house_id+alarm_code` | `operator(20m)->supervisor(90m)` | `false` | `tenant_id,industry_code,site_id,house_id,batch_id` |
| `swine_mortality_spike` | `mortality_pct_cycle` | `mortality_pct_cycle > 3.0` | `critical` | `P1` | `60s` | `site_id+batch_id+alarm_code` | `operator(5m)->veterinary(20m)` | `true` | `tenant_id,industry_code,site_id,batch_id` |
| `swine_biosecurity_breach` | `biosecurity_incidents_24h` | `biosecurity_incidents_24h >= 2` | `high` | `P1` | `60s` | `site_id+zone_id+alarm_code` | `operator(10m)->security(30m)` | `true` | `tenant_id,industry_code,site_id,zone_id` |

## 4. Правила консистентности

- Source-of-truth KPI:
  - климат: `industry.swine.climate`,
  - корм: `industry.swine.feeding`,
  - вода: `industry.swine.water`,
  - KPI цикла: `industry.swine.production`,
  - биобезопасность: `industry.swine.biosecurity`.
- Для composite KPI (`feed_water_ratio`, `mortality_pct_cycle`) приоритет источников:
  1. `production`,
  2. `feeding`/`water`/`biosecurity` как обогащение.
- Все `critical/high` alarms публикуются в `status` с тем же `correlation_id`.
- Для каждого alarm обязательны `tenant_id`, `industry_code=swine`, `site_id`.
