fix : last 3 are working properly {JKP,MJP,TRE}
This commit is contained in:
parent
a8a64e064e
commit
5f9afeddef
@ -26,6 +26,7 @@ export class SelectionService {
|
|||||||
|
|
||||||
private runnerCount: number = 12;
|
private runnerCount: number = 12;
|
||||||
private multiLegBaseRaceIdx: number = 0;
|
private multiLegBaseRaceIdx: number = 0;
|
||||||
|
private currentPool: string | null = null; // Track current pool (e.g., 'trb1', 'jkp1')
|
||||||
|
|
||||||
constructor(private sharedStateService: SharedStateService) {
|
constructor(private sharedStateService: SharedStateService) {
|
||||||
this.sharedStateService.runnerCount$.subscribe(count => {
|
this.sharedStateService.runnerCount$.subscribe(count => {
|
||||||
@ -34,6 +35,12 @@ export class SelectionService {
|
|||||||
this.sharedStateService.sharedData$.subscribe(data => {
|
this.sharedStateService.sharedData$.subscribe(data => {
|
||||||
if (data.type === 'selectedRace') {
|
if (data.type === 'selectedRace') {
|
||||||
this.multiLegBaseRaceIdx = data.value;
|
this.multiLegBaseRaceIdx = data.value;
|
||||||
|
} else if (data.type === 'multiLegPoolStart') {
|
||||||
|
this.currentPool = data.value.label;
|
||||||
|
this.multiLegBaseRaceIdx = data.value.baseRaceIdx;
|
||||||
|
} else if (data.type === 'multiLegPoolEnd') {
|
||||||
|
this.currentPool = null;
|
||||||
|
this.multiLegBaseRaceIdx = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -165,14 +172,14 @@ export class SelectionService {
|
|||||||
const legCount = this.getLegCount(label);
|
const legCount = this.getLegCount(label);
|
||||||
const legs = this.splitToLegs(numbers, legCount);
|
const legs = this.splitToLegs(numbers, legCount);
|
||||||
|
|
||||||
// Override for MJP to always start from race 1
|
// Use pool-specific race indices from currentPool
|
||||||
const baseIdx = label === 'MJP' ? 0 : this.multiLegBaseRaceIdx - 1;
|
const baseIdx = this.currentPool === 'mjp1' ? 0 : this.multiLegBaseRaceIdx;
|
||||||
|
|
||||||
const legCounts = legs.map((leg, idx) => {
|
const legCounts = legs.map((leg, idx) => {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (const item of leg) {
|
for (const item of leg) {
|
||||||
if (item === 'F') {
|
if (item === 'F') {
|
||||||
count += this.getRunnerCountForLeg(baseIdx + 1, idx);
|
count += this.getRunnerCountForLeg(baseIdx, idx);
|
||||||
} else if (typeof item === 'number') {
|
} else if (typeof item === 'number') {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
@ -257,12 +264,41 @@ export class SelectionService {
|
|||||||
|
|
||||||
private getRunnerCountForLeg(baseIdx: number, leg: number): number {
|
private getRunnerCountForLeg(baseIdx: number, leg: number): number {
|
||||||
const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
||||||
const raceIdx = Number(baseIdx) - 1 + leg;
|
// Use pool-specific race index mapping
|
||||||
const race = raceCardData?.raceVenueRaces?.races?.[raceIdx] || [];
|
const raceIdx = this.getRaceForLeg(this.currentPool || '', leg) - 1;
|
||||||
return Array.isArray(race) ? race.length : 12;
|
const race = raceCardData?.raceVenueRaces?.races?.[raceIdx];
|
||||||
|
console.log('getRunnerCountForLeg:', { pool: this.currentPool, leg, raceIdx, race }); // Enhanced debugging
|
||||||
|
if (!race) {
|
||||||
|
console.warn(`No race data found for pool ${this.currentPool}, raceIdx ${raceIdx}, defaulting to 12`);
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
if (Array.isArray(race)) {
|
||||||
|
console.log(`Race data is array with length ${race.length}`);
|
||||||
|
return race.length;
|
||||||
|
}
|
||||||
|
if (race.runners && Array.isArray(race.runners)) {
|
||||||
|
console.log(`Race data has runners array with length ${race.runners.length}`);
|
||||||
|
return race.runners.length;
|
||||||
|
}
|
||||||
|
console.warn(`Invalid race data structure for pool ${this.currentPool}, raceIdx ${raceIdx}, defaulting to 12`);
|
||||||
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getRaceForLeg(poolName: string, leg: number): number {
|
||||||
|
const raceCardData = JSON.parse(localStorage.getItem('raceCardData') || '{}');
|
||||||
|
const poolRaces = raceCardData?.raceVenueRaces?.pools?.[poolName] || [];
|
||||||
|
if (poolRaces.length > leg) {
|
||||||
|
return poolRaces[leg];
|
||||||
|
}
|
||||||
|
// Fallback to default race mapping
|
||||||
|
const raceMap: { [key: string]: number[] } = {
|
||||||
|
'mjp1': [1, 2, 3, 4],
|
||||||
|
'jkp1': [3, 4, 5, 6, 7],
|
||||||
|
'trb1': [2, 3, 4],
|
||||||
|
'trb2': [5, 6, 7]
|
||||||
|
};
|
||||||
|
return raceMap[poolName]?.[leg] || (this.multiLegBaseRaceIdx + leg);
|
||||||
|
}
|
||||||
|
|
||||||
private calculateTotal(data: SelectionData): number {
|
private calculateTotal(data: SelectionData): number {
|
||||||
const temp = new BehaviorSubject<SelectionData>(data);
|
const temp = new BehaviorSubject<SelectionData>(data);
|
||||||
@ -274,8 +310,6 @@ export class SelectionService {
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------ADDED THIS---------------------------------------------------//
|
|
||||||
createVirtualRowsFromWSP(): SelectionData[] {
|
createVirtualRowsFromWSP(): SelectionData[] {
|
||||||
const base = this.currentRow.value;
|
const base = this.currentRow.value;
|
||||||
|
|
||||||
@ -303,6 +337,4 @@ getSelections(): SelectionData[] {
|
|||||||
getCurrentRow(): SelectionData {
|
getCurrentRow(): SelectionData {
|
||||||
return this.currentRow.value;
|
return this.currentRow.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user