fix : multileg pool totaly fixed for ticket issue
This commit is contained in:
parent
ed83f86c91
commit
bd4f1e21d0
@ -1149,7 +1149,68 @@ const winLabels = allRows.map(row => {
|
|||||||
displayLabel = this.currentPool; // Use trb1 or trb2
|
displayLabel = this.currentPool; // Use trb1 or trb2
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Multi-leg pools: Expand 'F' for each leg ---
|
// // --- Multi-leg pools: Expand 'F' for each leg ---
|
||||||
|
// if (['TBP', 'MJP', 'JPP'].includes(row.label)) {
|
||||||
|
// // Split by '/' for legs
|
||||||
|
// let legs: (number | string)[][] = [];
|
||||||
|
// let currentLeg: (number | string)[] = [];
|
||||||
|
// for (const n of displayNumbers) {
|
||||||
|
// if (n === '/') {
|
||||||
|
// legs.push(currentLeg);
|
||||||
|
// currentLeg = [];
|
||||||
|
// } else {
|
||||||
|
// currentLeg.push(n);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (currentLeg.length) legs.push(currentLeg);
|
||||||
|
|
||||||
|
// // For each leg, expand 'F' to correct horse numbers for that leg
|
||||||
|
// const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JPP' ? 'jkp1' : this.currentPool || 'trb1';
|
||||||
|
// const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
||||||
|
// const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || [];
|
||||||
|
// // Fallback to hardcoded mapping if needed
|
||||||
|
// const raceMap: { [key: string]: number[] } = {
|
||||||
|
// 'mjp1': [1, 2, 3, 4],
|
||||||
|
// 'jkp1': [3, 4, 5, 6, 7],
|
||||||
|
// 'trb1': [2, 3, 4],
|
||||||
|
// 'trb2': [5, 6, 7]
|
||||||
|
// };
|
||||||
|
// const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []);
|
||||||
|
// // If no mapping, fallback to consecutive races from 1
|
||||||
|
// const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1;
|
||||||
|
|
||||||
|
// let expandedLegs: string[] = legs.map((leg, i) => {
|
||||||
|
// // Find race index for this leg
|
||||||
|
// let raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i);
|
||||||
|
|
||||||
|
// let expanded = leg.flatMap((n) => {
|
||||||
|
// if (n === 'F') {
|
||||||
|
// // Expand F → horse numbers, no extra dashes
|
||||||
|
// return this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString());
|
||||||
|
// }
|
||||||
|
// return [n]; // Keep original (including '-') if user entered
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // Remove '-' and '#' for display
|
||||||
|
// return expanded.filter(n => n !== '-' && n !== '#').join(',');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // Join legs with '/'
|
||||||
|
// let numbersStr = expandedLegs.join(' / ');
|
||||||
|
|
||||||
|
// const label = displayLabel.padEnd(10);
|
||||||
|
// const numbers = numbersStr.padEnd(15);
|
||||||
|
// const value = (`*${row.value || 0}`).padEnd(8);
|
||||||
|
// return `${label}${numbers} ${value}`;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Helper to pad ticket count to 3 digits (if you don't already have it elsewhere)
|
||||||
|
function padTicketCountToThree(n: number) {
|
||||||
|
const num = Number.isFinite(n) && n >= 0 ? Math.floor(n) : 0;
|
||||||
|
return String(num).padStart(3, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the existing TBP / MJP / JPP block with this:
|
||||||
if (['TBP', 'MJP', 'JPP'].includes(row.label)) {
|
if (['TBP', 'MJP', 'JPP'].includes(row.label)) {
|
||||||
// Split by '/' for legs
|
// Split by '/' for legs
|
||||||
let legs: (number | string)[][] = [];
|
let legs: (number | string)[][] = [];
|
||||||
@ -1164,11 +1225,12 @@ const winLabels = allRows.map(row => {
|
|||||||
}
|
}
|
||||||
if (currentLeg.length) legs.push(currentLeg);
|
if (currentLeg.length) legs.push(currentLeg);
|
||||||
|
|
||||||
// For each leg, expand 'F' to correct horse numbers for that leg
|
// Choose pool name (used only for race->horses lookup)
|
||||||
const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JPP' ? 'jkp1' : this.currentPool || 'trb1';
|
const poolName = row.label === 'MJP' ? 'mjp1' : row.label === 'JPP' ? 'jkp1' : (this.currentPool || 'trb1');
|
||||||
|
|
||||||
|
// Get pool races from cached raceCardData; fallback to hard-coded map
|
||||||
const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
||||||
const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || [];
|
const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || [];
|
||||||
// Fallback to hardcoded mapping if needed
|
|
||||||
const raceMap: { [key: string]: number[] } = {
|
const raceMap: { [key: string]: number[] } = {
|
||||||
'mjp1': [1, 2, 3, 4],
|
'mjp1': [1, 2, 3, 4],
|
||||||
'jkp1': [3, 4, 5, 6, 7],
|
'jkp1': [3, 4, 5, 6, 7],
|
||||||
@ -1176,67 +1238,47 @@ const winLabels = allRows.map(row => {
|
|||||||
'trb2': [5, 6, 7]
|
'trb2': [5, 6, 7]
|
||||||
};
|
};
|
||||||
const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []);
|
const raceIndices: number[] = poolRaces.length > 0 ? poolRaces : (raceMap[poolName] || []);
|
||||||
// If no mapping, fallback to consecutive races from 1
|
|
||||||
const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1;
|
const baseRaceIdx = raceIndices.length > 0 ? raceIndices[0] : 1;
|
||||||
|
|
||||||
let expandedLegs: string[] = legs.map((leg, i) => {
|
// Expand each leg: expand 'F' to actual horse numbers for that leg, normalize numeric tokens to two digits
|
||||||
// Find race index for this leg
|
const normalizeToken = (tok: string | number) => {
|
||||||
let raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i);
|
const s = String(tok);
|
||||||
// let expanded = leg.flatMap(n =>
|
return /^\d+$/.test(s) ? s.padStart(2, '0') : s;
|
||||||
// n === 'F'
|
};
|
||||||
// ? this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString())
|
|
||||||
// : [n]
|
const expandedLegs: string[] = legs.map((leg, i) => {
|
||||||
// );
|
const raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i);
|
||||||
// let expanded = leg.flatMap((n, idx) => {
|
const expanded = leg.flatMap((n) => {
|
||||||
// if (n === 'F') {
|
|
||||||
// const horses = this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString()).join(',');
|
|
||||||
// const isFirst = idx === 0;
|
|
||||||
// const isLast = idx === leg.length - 1;
|
|
||||||
// if (isFirst && !isLast) return [`${horses}-`];
|
|
||||||
// if (!isFirst && isLast) return [`-${horses}`];
|
|
||||||
// if (isFirst && isLast) return [horses]; // only F in the leg
|
|
||||||
// return [`-${horses}-`];
|
|
||||||
// }
|
|
||||||
// return [n];
|
|
||||||
// });
|
|
||||||
let expanded = leg.flatMap((n) => {
|
|
||||||
if (n === 'F') {
|
if (n === 'F') {
|
||||||
// Expand F → horse numbers, no extra dashes
|
// expand to horse numbers for that race index
|
||||||
return this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString());
|
return this.getHorseNumbersForRaceIdx(raceIdx).map(num => String(num));
|
||||||
}
|
}
|
||||||
return [n]; // Keep original (including '-') if user entered
|
return [n];
|
||||||
|
});
|
||||||
|
// remove any stray '-' and '#', normalize numeric tokens to two digits, then join by ','
|
||||||
|
return expanded
|
||||||
|
.filter(n => n !== '-' && n !== '#')
|
||||||
|
.map(normalizeToken)
|
||||||
|
.join(',');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove '-' and '#' for display
|
// Join legs with '/' (no extra spaces to match your desired output)
|
||||||
return expanded.filter(n => n !== '-' && n !== '#').join(',');
|
const numbersStr = expandedLegs.join('/');
|
||||||
});
|
|
||||||
|
|
||||||
// Join legs with '/'
|
// Label: always show TBP (uppercase) for TBP rows; for MJP/JPP leave as-is
|
||||||
let numbersStr = expandedLegs.join(' / ');
|
const labelForDisplay = row.label === 'TBP' ? 'TBP' : displayLabel;
|
||||||
|
|
||||||
const label = displayLabel.padEnd(10);
|
// Value: zero-pad tickets to 3 digits like *007
|
||||||
const numbers = numbersStr.padEnd(15);
|
const valueStr = `*${padTicketCountToThree(row.value || 0)}`;
|
||||||
const value = (`*${row.value || 0}`).padEnd(8);
|
|
||||||
return `${label}${numbers} ${value}`;
|
// Build line: e.g. "TBP 01,02/02,03/02,03*007"
|
||||||
|
return `${labelForDisplay} ${numbersStr}${valueStr}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 🐎 Expand 'F' to full horse numbers for other pools
|
// 🐎 Expand 'F' to full horse numbers for other pools
|
||||||
if (displayNumbers.includes('F')) {
|
if (displayNumbers.includes('F')) {
|
||||||
// displayNumbers = displayNumbers.flatMap(n =>
|
|
||||||
// n === 'F' ? this.getHorseNumbersForSelectedRace().map(num => num.toString()) : [n]
|
|
||||||
// );
|
|
||||||
// displayNumbers = displayNumbers.flatMap((n, idx, arr) => {
|
|
||||||
// if (n === 'F') {
|
|
||||||
// const horses = this.getHorseNumbersForSelectedRace().map(num => num.toString()).join(',');
|
|
||||||
// const isFirst = idx === 0;
|
|
||||||
// const isLast = idx === arr.length - 1;
|
|
||||||
// if (isFirst && !isLast) return [`${horses}-`];
|
|
||||||
// if (!isFirst && isLast) return [`-${horses}`];
|
|
||||||
// if (isFirst && isLast) return [horses]; // only F
|
|
||||||
// return [`-${horses}-`];
|
|
||||||
// }
|
|
||||||
// return [n];
|
|
||||||
// });
|
|
||||||
displayNumbers = displayNumbers.flatMap((n) => {
|
displayNumbers = displayNumbers.flatMap((n) => {
|
||||||
if (n === 'F') {
|
if (n === 'F') {
|
||||||
// Expand F → horse numbers, no extra dashes
|
// Expand F → horse numbers, no extra dashes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user