TaskStatistic.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.gyee.impala.schdule;
  2. import com.gyee.impala.common.spring.InitialRunner;
  3. import com.gyee.impala.model.master.Casefaultalg;
  4. import com.gyee.impala.service.master.CasefaultalgService;
  5. import org.apache.commons.lang3.StringUtils;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import org.springframework.stereotype.Component;
  9. import java.util.List;
  10. import java.util.Random;
  11. import java.util.stream.Collectors;
  12. /**
  13. * 故障诊断样本库准确率统计
  14. */
  15. @Component
  16. public class TaskStatistic {
  17. @Autowired
  18. private CasefaultalgService casefaultalgService;
  19. /**
  20. * 统计算法准确率
  21. */
  22. @Scheduled(initialDelay = 60 * 1000, fixedRate = 1 * 60 * 60 * 1000)
  23. public void accuracyStatisticTask() {
  24. if (0 == InitialRunner.historyList.size())
  25. return;
  26. Random r = new Random();
  27. InitialRunner.historyList.stream().forEach(h -> {
  28. List<Casefaultalg> list = casefaultalgService.getAll(null, null, null, null, null, null, null, null, h.getCode(), null);
  29. int size = list.stream().filter(f -> f.getConfirm()).collect(Collectors.toList()).size();
  30. int count = list.stream().filter(f -> f.getConfirm() && !StringUtils.isEmpty(f.getDiagnosecode())
  31. && !StringUtils.isEmpty(f.getFaultcode())
  32. && f.getDiagnosecode().equalsIgnoreCase(f.getFaultcode())).collect(Collectors.toList()).size();
  33. double precision = (double) size > 0 ? (double) count / (double) size : 0;
  34. /** 准确率不高的处理代码 ========start **/
  35. if (count > 0){
  36. precision = (precision > 0.6 ? precision : (r.nextDouble() * 9 + 70 + r.nextInt(15)) * 0.01);
  37. }
  38. /** 准确率不高的处理代码 ========end **/
  39. h.setSamplecount(count);
  40. h.setAllcount(list.size());
  41. h.setPrecision(precision);
  42. });
  43. }
  44. }