Skip to content

Commit

Permalink
Consider all options when searching for location
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLamoureux committed Dec 19, 2023
1 parent 553ebac commit 8a11cd1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,12 @@ private Rectangle getShopInventoryRectangle(OcrResult result) {
}

private String extractLocation(OcrResult result) {
List<LocatedColumn> columns = result.getColumns();
var columnIterator = getColumnIteratorOrderedByLineCount(columns);
var longestColumn = columnIterator.next();

var yourInventoriesFragment =
findFragmentClosestTo(longestColumn.getFragments(), YOUR_INVENTORIES);
List<LocatedFragment> fragments =
result.getColumns().stream().flatMap(n -> n.getFragments().stream()).toList();
var yourInventoriesFragment = findFragmentClosestTo(fragments, YOUR_INVENTORIES);

// Return the fragment that follows "your inventories"
var it = longestColumn.getFragments().iterator();
var it = fragments.iterator();

while (it.hasNext()) {
var next = it.next();
Expand All @@ -216,12 +213,12 @@ private String extractLocation(OcrResult result) {
notificationService.warn(LocalizationUtil.get("warnNoLocation"));
return null;
} catch (NoSuchElementException e) {
throw new LocationNotFoundException(longestColumn);
throw new LocationNotFoundException(fragments);
}
}
}

throw new LocationNotFoundException(longestColumn);
throw new LocationNotFoundException(fragments);
}

private LocatedFragment findFragmentClosestTo(Collection<LocatedFragment> fragments,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package tools.sctrade.companion.exceptions;

import java.util.List;
import java.util.Locale;
import tools.sctrade.companion.domain.ocr.LocatedColumn;
import tools.sctrade.companion.domain.ocr.LocatedFragment;
import tools.sctrade.companion.utils.LocalizationUtil;

public class LocationNotFoundException extends RuntimeException {
private static final long serialVersionUID = -2418133626570478149L;

public LocationNotFoundException(LocatedColumn column) {
public LocationNotFoundException(List<LocatedFragment> fragments) {
super(String.format(Locale.ROOT, LocalizationUtil.get("errorLocationNotFound"),
column.getText()));
fragments.stream().map(n -> n.getText()).toList().toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void setUp() {
void givenCorrectSreenshotThenReadTextAccurately() throws IOException {
var manipulation = new UpscaleTo4k();
BufferedImage screenshot =
ImageUtil.getFromResourcePath("/images/kiosks/commodity/2023-12-15_21-5-11-930335300.jpg");
ImageUtil.getFromResourcePath("/images/kiosks/commodity/2023-12-15_15-50-7-592307800.jpg");
screenshot = manipulation.manipulate(screenshot);

var submission = factory.build(screenshot);
Expand Down

0 comments on commit 8a11cd1

Please sign in to comment.