de.niklasfi.rx.ThrottlerBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aocr Show documentation
Show all versions of aocr Show documentation
Swiftly add ocr layers to scanned pdf files.
Unfortunately existing open source ocr solutions (tesseract) pale in comparison with the ones commercially
available. The azure read api provides particularly good results. It is also easy to set up, but while it can
annotate text in images, there is no easy way to upload and ocr a full pdf document.
That is, until now. aocr provides an easy way to ocr full pdf documents.
package de.niklasfi.rx;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.temporal.TemporalAmount;
public class ThrottlerBase {
private final TemporalAmount minInterval;
private OffsetDateTime nextSlot;
public ThrottlerBase(TemporalAmount minInterval) {
this.minInterval = minInterval;
}
protected final long getNextSlotDelay(){
final var now = OffsetDateTime.now();
final long delayMs;
if (nextSlot == null || nextSlot.isBefore(now)) {
nextSlot = now.plus(minInterval);
delayMs = 0;
} else {
delayMs = Duration.between(now, nextSlot).toMillis();
nextSlot = nextSlot.plus(minInterval);
}
//System.out.printf("now: %s, delay: %s, next: %s%n", now, delayMs, nextSlot);
return delayMs;
}
}