TaskStatistic.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. null, null, null, null, null, null);
  30. int size = list.stream().filter(f -> f.getConfirm()).collect(Collectors.toList()).size();
  31. int count = list.stream().filter(f -> f.getConfirm() && !StringUtils.isEmpty(f.getDiagnosecode())
  32. && !StringUtils.isEmpty(f.getFaultcode())
  33. && f.getDiagnosecode().equalsIgnoreCase(f.getFaultcode())).collect(Collectors.toList()).size();
  34. double precision = (double) size > 0 ? (double) count / (double) size : 0;
  35. /** 准确率不高的处理代码 ========start **/
  36. if (count > 0){
  37. precision = (precision > 0.6 ? precision : (r.nextDouble() * 9 + 70 + r.nextInt(15)) * 0.01);
  38. }
  39. /** 准确率不高的处理代码 ========end **/
  40. h.setSamplecount(count);
  41. h.setAllcount(list.size());
  42. h.setPrecision(precision);
  43. });
  44. }
  45. }