1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package cn.com.qmth.am.bean;
- import java.util.concurrent.atomic.AtomicInteger;
- import org.springframework.stereotype.Component;
- import cn.com.qmth.am.utils.Calculator;
- @Component
- public class ModelSpeed {
- private Long ocrStartTime;
- private Long markingStartTime;
- private AtomicInteger ocrCount = new AtomicInteger(0);
- private AtomicInteger markingCount = new AtomicInteger(0);
- private Double ocrSpeed;
- private Double markingSpeed;
- public void addOcrCOunt() {
- ocrCount.addAndGet(1);
- }
- public void addMarkingCount() {
- markingCount.addAndGet(1);
- }
- public void ocrStart() {
- this.ocrStartTime = System.currentTimeMillis();
- this.ocrSpeed = null;
- }
- public void ocrEnd() {
- this.ocrStartTime = null;
- this.ocrCount = new AtomicInteger(0);
- }
- public void markingStart() {
- this.markingStartTime = System.currentTimeMillis();
- this.markingSpeed = null;
- }
- public void markingEnd() {
- this.markingStartTime = null;
- this.markingCount = new AtomicInteger(0);
- }
- public String getOcrSpeed() {
- String txt = "个/秒";
- Long start = this.ocrStartTime;
- if (start == null) {
- Double speed = this.ocrSpeed;
- if (speed != null) {
- return speed + txt;
- } else {
- return "-";
- }
- } else {
- return getSpeed(start, this.ocrCount) + txt;
- }
- }
- public String getMarkingSpeed() {
- String txt = "个/秒";
- Long start = this.markingStartTime;
- if (start == null) {
- Double speed = this.markingSpeed;
- if (speed != null) {
- return speed + txt;
- } else {
- return "-";
- }
- } else {
- return getSpeed(start, this.markingCount) + txt;
- }
- }
- private Double getSpeed(long startTime, AtomicInteger count) {
- long end = System.currentTimeMillis();
- if (count.get() == 0) {
- return 0.0;
- } else {
- return Calculator.divide(Calculator.multiply(count.get(), 1000), end - startTime, 2);
- }
- }
- }
|