You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在含缺失/重复时间戳的警情处置数据中识别最优时间戳?

警察呼叫服务处置时间戳优化方案

数据集概况

我有一份记录警察呼叫服务处置情况的数据集,包含以下6列:

  • incident_id:警情ID
  • unit_id:出警单位ID
  • timestamp_dispatched:调度时间戳
  • timestamp_responding:响应时间戳
  • timestamp_arrived:到达现场时间戳
  • timestamp_clearing_scene:现场清理完成时间戳

四个时间戳字段需满足时序关系:timestamp_dispatched < timestamp_responding < timestamp_arrived < timestamp_clearing_scene,但当前数据存在以下问题:

  • timestamp_responding有15%缺失值,timestamp_arrived有35%缺失值
  • 四个时间戳均存在重复记录

数据偏差来源

两类业务流程会引入数据失真:

  • 系统归档规则:调度中心需记录四种状态中的三种才会归档警情;若仅记录了调度(dispatch)和现场清理完成(cleared_scene),调度员会补录响应(responding)/到达(arrived)及现场清理完成时间,导致处置时长计算失真。
  • 短间隔记录合并:响应、到达、现场清理的记录间隔在2秒内时,仅需保留最晚的那条记录。

启发式最优时间戳识别规则

需要识别符合分析要求的最优时间戳,已知规则如下:

  • timestamp_dispatched取该警情+出警单位组合下的最后一条记录
  • timestamp_clearing_scene取该警情+出警单位组合下的第一条记录
  • 最终筛选出的时间戳必须满足时序关系:timestamp_dispatched < timestamp_responding < timestamp_arrived < timestamp_clearing_scene

可复现数据集示例

library(dplyr)
library(tidyr)
library(lubridate)

# 生成示例数据
data <- data.frame(
  incident_id = c(1, 1, 1, 2, 2, 2),
  unit_id = c('A', 'A', 'A', 'B', 'B', 'B'),
  timestamp_dispatched = c('2022-01-01 12:00:00', '2022-01-01 12:05:00', '2022-01-01 12:10:00', '2022-01-01 12:15:00', '2022-01-01 12:20:00', '2022-01-01 12:25:00'),
  timestamp_responding = c('2022-01-01 12:01:00', NA, '2022-01-01 12:12:00', '2022-01-01 12:16:00', NA, '2022-01-01 12:26:00'),
  timestamp_arrived = c('2022-01-01 12:02:00', '2022-01-01 12:06:00', '2022-01-01 12:13:00', NA, '2022-01-01 12:22:00', NA),
  timestamp_clearing_scene = c('2022-01-01 12:20:00', '2022-01-01 12:30:00', '2022-01-01 12:40:00', NA, '2022-01-01 12:50:00', NA)
)

# 将时间戳转换为日期时间格式
data <- data %>% 
  mutate(across(starts_with("timestamp"), ymd_hms))

# 去除incident_id和unit_id重复的行
data <- data %>% 
  distinct(incident_id, unit_id, .keep_all = TRUE)

内容的提问来源于stack exchange,提问作者DeMelkbroer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 17:12:50