package com.gyee.impala.schdule; import com.gyee.impala.common.spring.InitialRunner; import com.gyee.impala.model.master.Casefaultalg; import com.gyee.impala.service.master.CasefaultalgService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.List; import java.util.Random; import java.util.stream.Collectors; /** * 故障诊断样本库准确率统计 */ @Component public class TaskStatistic { @Autowired private CasefaultalgService casefaultalgService; /** * 统计算法准确率 */ @Scheduled(initialDelay = 60 * 1000, fixedRate = 1 * 60 * 60 * 1000) public void accuracyStatisticTask() { if (0 == InitialRunner.historyList.size()) return; Random r = new Random(); InitialRunner.historyList.stream().forEach(h -> { List list = casefaultalgService.getAll(null, null, null, null, null, null, null, null, h.getCode(), null, null, null, null, null, null, null); int size = list.stream().filter(f -> f.getConfirm()).collect(Collectors.toList()).size(); int count = list.stream().filter(f -> f.getConfirm() && !StringUtils.isEmpty(f.getDiagnosecode()) && !StringUtils.isEmpty(f.getFaultcode()) && f.getDiagnosecode().equalsIgnoreCase(f.getFaultcode())).collect(Collectors.toList()).size(); double precision = (double) size > 0 ? (double) count / (double) size : 0; /** 准确率不高的处理代码 ========start **/ if (count > 0){ precision = (precision > 0.6 ? precision : (r.nextDouble() * 9 + 70 + r.nextInt(15)) * 0.01); } /** 准确率不高的处理代码 ========end **/ h.setSamplecount(count); h.setAllcount(list.size()); h.setPrecision(precision); }); } }