如何在Sink块中分别获取TypeA与TypeB代理的平均时间?
分类型统计代理平均停留时间的解决方案
方法一:自定义属性+独立统计变量
- 在你的代理类型中添加double类型属性,命名为
entryTime - 在代理进入流程的首个块(如Source或起始处理块)的
on enter动作中,写入代码:entryTime = time(); - 新增两个
Statistics > Mean类型变量,命名为avgStayTime_TypeA和avgStayTime_TypeB - 在Sink块的
on enter动作中,按类型计算并更新统计:double stayDuration = time() - entryTime; if (this.type.equals("TypeA")) { // 替换为你实际判断TypeA的逻辑 avgStayTime_TypeA.add(stayDuration); } else if (this.type.equals("TypeB")) { avgStayTime_TypeB.add(stayDuration); } - 后续可通过
avgStayTime_TypeA.getMean()或avgStayTime_TypeB.getMean()直接获取对应类型的平均停留时间
方法二:按类型绑定Time Measure组件
- 添加两个
Time Measure组件,分别命名为timeMeasure_TypeA和timeMeasure_TypeB - 在代理进入流程起点的
on enter动作中,按类型启动对应计时:if (this.type.equals("TypeA")) { timeMeasure_TypeA.start(this); } else if (this.type.equals("TypeB")) { timeMeasure_TypeB.start(this); } - 在Sink块的
on enter动作中,按类型结束对应计时:if (this.type.equals("TypeA")) { timeMeasure_TypeA.end(this); } else if (this.type.equals("TypeB")) { timeMeasure_TypeB.end(this); } - 每个Time Measure组件的
mean属性即为对应类型代理的平均停留时间
注意事项
- 确保代理类型的判断逻辑与你实际的代理字段匹配(比如是枚举、字符串还是其他标识)
- 若代理存在流程分流,需保证每个代理的计时启动与结束操作对应同一个Time Measure组件
内容的提问来源于stack exchange,提问作者Rob
相关产品推荐
相关产品推荐

