Codex commited on
Commit ·
1d0d5f6
1
Parent(s): 7e0a701
Constrain Circa home run section parsing
Browse files- src/market-scanner.js +51 -0
src/market-scanner.js
CHANGED
|
@@ -645,6 +645,48 @@ function detectCircaSection(line) {
|
|
| 645 |
return null;
|
| 646 |
}
|
| 647 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
function normalizeOcrOddsToken(token) {
|
| 649 |
if (!token) {
|
| 650 |
return null;
|
|
@@ -1014,7 +1056,16 @@ export function parseCircaOcrText(text) {
|
|
| 1014 |
continue;
|
| 1015 |
}
|
| 1016 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1017 |
if (currentSection?.mode === 'binary_yes_no') {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
const binaryEntries = extractBinaryYesNoEntriesV3(line, currentSection);
|
| 1019 |
if (binaryEntries.length > 0) {
|
| 1020 |
entries.push(...binaryEntries);
|
|
|
|
| 645 |
return null;
|
| 646 |
}
|
| 647 |
|
| 648 |
+
function isLikelySectionBoundary(line) {
|
| 649 |
+
const normalized = normalizeWhitespace(line).toUpperCase();
|
| 650 |
+
if (!normalized) {
|
| 651 |
+
return false;
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
return (
|
| 655 |
+
normalized.includes('WILL [PLAYER]')
|
| 656 |
+
|| normalized.includes('TOTAL BASES')
|
| 657 |
+
|| normalized.includes('HITS + RUNS + RBIS')
|
| 658 |
+
|| normalized.includes('HITS RUNS RBIS')
|
| 659 |
+
|| normalized.includes('PITCHER STRIKEOUTS')
|
| 660 |
+
|| normalized.includes('STRIKEOUTS')
|
| 661 |
+
|| normalized.includes('RECORD A HIT')
|
| 662 |
+
|| normalized.includes('RECORD AN RBI')
|
| 663 |
+
|| normalized.includes('RECORD A RBI')
|
| 664 |
+
|| normalized.includes('SCORE A RUN')
|
| 665 |
+
);
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
function isLikelyHomeRunBinaryLine(line) {
|
| 669 |
+
const normalized = normalizeWhitespace(line).toUpperCase();
|
| 670 |
+
if (!normalized.includes('(')) {
|
| 671 |
+
return false;
|
| 672 |
+
}
|
| 673 |
+
|
| 674 |
+
const priceTokens = [...normalized.matchAll(/[+\-~]?[0-9BOSI]{2,4}/g)].map((match) => match[0]);
|
| 675 |
+
const positivePrices = priceTokens
|
| 676 |
+
.map((token) => normalizeOcrOddsTokenForSide(token, 'yes'))
|
| 677 |
+
.filter(Boolean)
|
| 678 |
+
.map((token) => Number(token))
|
| 679 |
+
.filter(Number.isFinite)
|
| 680 |
+
.filter((value) => value > 0);
|
| 681 |
+
|
| 682 |
+
if (positivePrices.length === 0) {
|
| 683 |
+
return false;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
const hrLikeCount = positivePrices.filter((value) => value >= 180).length;
|
| 687 |
+
return hrLikeCount >= Math.max(1, Math.ceil(positivePrices.length / 2));
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
function normalizeOcrOddsToken(token) {
|
| 691 |
if (!token) {
|
| 692 |
return null;
|
|
|
|
| 1056 |
continue;
|
| 1057 |
}
|
| 1058 |
|
| 1059 |
+
if (currentSection?.type === 'home_runs' && isLikelySectionBoundary(line)) {
|
| 1060 |
+
currentSection = null;
|
| 1061 |
+
continue;
|
| 1062 |
+
}
|
| 1063 |
+
|
| 1064 |
if (currentSection?.mode === 'binary_yes_no') {
|
| 1065 |
+
if (currentSection.type === 'home_runs' && !isLikelyHomeRunBinaryLine(line)) {
|
| 1066 |
+
continue;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
const binaryEntries = extractBinaryYesNoEntriesV3(line, currentSection);
|
| 1070 |
if (binaryEntries.length > 0) {
|
| 1071 |
entries.push(...binaryEntries);
|