ModelSpeed.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package cn.com.qmth.am.bean;
  2. import java.util.concurrent.atomic.AtomicInteger;
  3. import org.springframework.stereotype.Component;
  4. import cn.com.qmth.am.utils.Calculator;
  5. @Component
  6. public class ModelSpeed {
  7. private Long ocrStartTime;
  8. private Long markingStartTime;
  9. private AtomicInteger ocrCount = new AtomicInteger(0);
  10. private AtomicInteger markingCount = new AtomicInteger(0);
  11. private Double ocrSpeed;
  12. private Double markingSpeed;
  13. public void addOcrCOunt() {
  14. ocrCount.addAndGet(1);
  15. }
  16. public void addMarkingCount() {
  17. markingCount.addAndGet(1);
  18. }
  19. public void ocrStart() {
  20. this.ocrStartTime = System.currentTimeMillis();
  21. this.ocrSpeed = null;
  22. }
  23. public void ocrEnd() {
  24. this.ocrStartTime = null;
  25. this.ocrCount = new AtomicInteger(0);
  26. }
  27. public void markingStart() {
  28. this.markingStartTime = System.currentTimeMillis();
  29. this.markingSpeed = null;
  30. }
  31. public void markingEnd() {
  32. this.markingStartTime = null;
  33. this.markingCount = new AtomicInteger(0);
  34. }
  35. public String getOcrSpeed() {
  36. String txt = "个/秒";
  37. Long start = this.ocrStartTime;
  38. if (start == null) {
  39. Double speed = this.ocrSpeed;
  40. if (speed != null) {
  41. return speed + txt;
  42. } else {
  43. return "-";
  44. }
  45. } else {
  46. return getSpeed(start, this.ocrCount) + txt;
  47. }
  48. }
  49. public String getMarkingSpeed() {
  50. String txt = "个/秒";
  51. Long start = this.markingStartTime;
  52. if (start == null) {
  53. Double speed = this.markingSpeed;
  54. if (speed != null) {
  55. return speed + txt;
  56. } else {
  57. return "-";
  58. }
  59. } else {
  60. return getSpeed(start, this.markingCount) + txt;
  61. }
  62. }
  63. private Double getSpeed(long startTime, AtomicInteger count) {
  64. long end = System.currentTimeMillis();
  65. if (count.get() == 0) {
  66. return 0.0;
  67. } else {
  68. return Calculator.divide(Calculator.multiply(count.get(), 1000), end - startTime, 2);
  69. }
  70. }
  71. }