Integrate market audit with shared calibration and catalog
This commit is contained in:
+22
-6
@@ -16,6 +16,17 @@ export function resolveFieldRect(anchorPosition, field) {
|
||||
};
|
||||
}
|
||||
|
||||
export function combineRects(first, second) {
|
||||
const x = Math.min(first.x, second.x);
|
||||
const y = Math.min(first.y, second.y);
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
width: Math.max(first.x + first.width, second.x + second.width) - x,
|
||||
height: Math.max(first.y + first.height, second.y + second.height) - y,
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeOcrText(text) {
|
||||
return text.replace(/\s+/g, " ").trim();
|
||||
}
|
||||
@@ -54,7 +65,7 @@ export function parseTooltipText(text) {
|
||||
const priceIndex = lines.findIndex(
|
||||
(line) =>
|
||||
/\d[\d\s,.'`]*\s*adena/i.test(line) ||
|
||||
/pr[i1l]ce\s*[:;]?/i.test(line) ||
|
||||
/pr[i1l]ce\s*[:;]?\s*\d/i.test(line) ||
|
||||
/^\s*\d[\d\s,.'`]*\s*$/.test(line),
|
||||
);
|
||||
|
||||
@@ -67,7 +78,7 @@ export function parseTooltipText(text) {
|
||||
priceLine.match(/^\s*([\d][\d\s,.'`]*)\s*$/)?.[1] ??
|
||||
"";
|
||||
const digits = priceText.replace(/\D/g, "");
|
||||
let name = lines[priceIndex - 1] ?? "";
|
||||
let name = lines.slice(0, priceIndex).find((line) => !/^pr[i1l]ce\s*[:;]?$/i.test(line)) ?? "";
|
||||
|
||||
if (!name) {
|
||||
name = priceLine.slice(0, priceLine.search(/pr[i1l]ce/i)).trim();
|
||||
@@ -75,13 +86,18 @@ export function parseTooltipText(text) {
|
||||
|
||||
if (!name || !digits) return null;
|
||||
|
||||
const quantityMatch = name.match(/^(.*?)\s*\(([\d][\d\s,.]*)\)\s*$/);
|
||||
const quantityText = quantityMatch?.[2].replace(/\D/g, "") ?? "";
|
||||
if (quantityMatch) name = quantityMatch[1].trim();
|
||||
const quantityMatches = [...name.matchAll(/\(([\d][\d\s,.]*)\)/g)];
|
||||
const quantityMatch = quantityMatches.at(-1);
|
||||
const quantityText = quantityMatch?.[1].replace(/\D/g, "") ?? "";
|
||||
if (quantityMatch) {
|
||||
name = `${name.slice(0, quantityMatch.index)} ${name.slice(quantityMatch.index + quantityMatch[0].length)}`
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
return {
|
||||
name,
|
||||
quantity: quantityText ? Number(quantityText) : null,
|
||||
quantity: quantityText ? Number(quantityText) : 1,
|
||||
priceAdena: Number(digits),
|
||||
rawText: lines.join("\n"),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user