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
|
||||
}
|
||||
|
||||
// --- 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)) {
|
||||
// Split by '/' for legs
|
||||
let legs: (number | string)[][] = [];
|
||||
@ -1164,11 +1225,12 @@ const winLabels = allRows.map(row => {
|
||||
}
|
||||
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';
|
||||
// Choose pool name (used only for race->horses lookup)
|
||||
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 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],
|
||||
@ -1176,67 +1238,47 @@ const winLabels = allRows.map(row => {
|
||||
'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 =>
|
||||
// n === 'F'
|
||||
// ? this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString())
|
||||
// : [n]
|
||||
// );
|
||||
// let expanded = leg.flatMap((n, idx) => {
|
||||
// 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) => {
|
||||
// Expand each leg: expand 'F' to actual horse numbers for that leg, normalize numeric tokens to two digits
|
||||
const normalizeToken = (tok: string | number) => {
|
||||
const s = String(tok);
|
||||
return /^\d+$/.test(s) ? s.padStart(2, '0') : s;
|
||||
};
|
||||
|
||||
const expandedLegs: string[] = legs.map((leg, i) => {
|
||||
const raceIdx = raceIndices.length > i ? raceIndices[i] - 1 : (baseRaceIdx - 1 + i);
|
||||
const expanded = leg.flatMap((n) => {
|
||||
if (n === 'F') {
|
||||
// Expand F → horse numbers, no extra dashes
|
||||
return this.getHorseNumbersForRaceIdx(raceIdx).map(num => num.toString());
|
||||
// expand to horse numbers for that race index
|
||||
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
|
||||
return expanded.filter(n => n !== '-' && n !== '#').join(',');
|
||||
});
|
||||
// Join legs with '/' (no extra spaces to match your desired output)
|
||||
const numbersStr = expandedLegs.join('/');
|
||||
|
||||
// Join legs with '/'
|
||||
let numbersStr = expandedLegs.join(' / ');
|
||||
// Label: always show TBP (uppercase) for TBP rows; for MJP/JPP leave as-is
|
||||
const labelForDisplay = row.label === 'TBP' ? 'TBP' : displayLabel;
|
||||
|
||||
const label = displayLabel.padEnd(10);
|
||||
const numbers = numbersStr.padEnd(15);
|
||||
const value = (`*${row.value || 0}`).padEnd(8);
|
||||
return `${label}${numbers} ${value}`;
|
||||
// Value: zero-pad tickets to 3 digits like *007
|
||||
const valueStr = `*${padTicketCountToThree(row.value || 0)}`;
|
||||
|
||||
// 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
|
||||
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) => {
|
||||
if (n === 'F') {
|
||||
// Expand F → horse numbers, no extra dashes
|
||||
|
||||
Loading…
Reference in New Issue
Block a user