|
|
|
@ -11,6 +11,7 @@ import { RaceEntry } from '../../models/raceEntry.model'; |
|
|
|
import { Season } from '../../models/season.model'; |
|
|
|
import { RacesService } from '../../services/races.service'; |
|
|
|
import { SeasonStanding } from '../../models/season-standing.model'; |
|
|
|
import { ServerSideEventsService } from '../../services/server-side-events.service'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-season-standings', |
|
|
|
@ -36,10 +37,13 @@ export class SeasonStandingsComponent { |
|
|
|
displayedColumns: string[] = ['position', 'name', 'points']; |
|
|
|
sortedStandings!: SeasonStanding[]; |
|
|
|
|
|
|
|
updatedStandingsListener: any; |
|
|
|
|
|
|
|
constructor( |
|
|
|
private racersService: RacersService, |
|
|
|
private raceResultService: RaceResultService, |
|
|
|
private racesService: RacesService, |
|
|
|
private sseService: ServerSideEventsService, |
|
|
|
) {} |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
@ -57,108 +61,39 @@ export class SeasonStandingsComponent { |
|
|
|
console.log(this.sortedStandings); |
|
|
|
console.log("Season Standings - end") |
|
|
|
|
|
|
|
return; |
|
|
|
/* |
|
|
|
for (let race_id of this.season.races) { |
|
|
|
this.racesService.getRace(race_id).subscribe( race => { |
|
|
|
if( race != undefined ){ |
|
|
|
this.races.push(race); |
|
|
|
|
|
|
|
this.seasonRaceResults.set(race.id, []); |
|
|
|
for( let racer_id of race.racers ) { |
|
|
|
if( this.seasonRacers.has(racer_id) == false ) { |
|
|
|
this.racersService.getRacer(racer_id).subscribe( data => { |
|
|
|
if(data != undefined) { |
|
|
|
this.seasonRacers.set(racer_id, data); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
let thisRaceResults = this.seasonRaceResults.get(race.id); |
|
|
|
this.raceResultService.getRaceResultsForRacerInRace(racer_id, race.id).subscribe( data => { |
|
|
|
if(data != undefined) { |
|
|
|
let bestResult = this.getBestTime(data); |
|
|
|
|
|
|
|
if(thisRaceResults != undefined) { |
|
|
|
thisRaceResults.push(bestResult); |
|
|
|
} |
|
|
|
|
|
|
|
this.calculateSeasonPoints(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
}*/ |
|
|
|
this.updatedStandingsListener = this.sseService.registerEventHandler('season-standings.updated', this.onUpdatedStandings, this); |
|
|
|
} |
|
|
|
|
|
|
|
getRacerName(racer: any): string { |
|
|
|
if( racer != undefined) { |
|
|
|
if( racer.name == undefined || racer.name == "" ) { |
|
|
|
return racer.gameHandle; |
|
|
|
} |
|
|
|
|
|
|
|
return racer.name + " (" + racer.gameHandle + ")" |
|
|
|
} |
|
|
|
|
|
|
|
return "" |
|
|
|
ngOnDestroy() { |
|
|
|
this.sseService.unregisterEventHandler('season-standings.updated', this.updatedStandingsListener); |
|
|
|
} |
|
|
|
|
|
|
|
getBestTime(results: RaceEntry[]): RaceEntry { |
|
|
|
let bestTime: number = 0xFFFFFFFF; |
|
|
|
let bestResult = new RaceEntry(); |
|
|
|
for(let result of results){ |
|
|
|
if(result.time < bestTime) { |
|
|
|
bestTime = result.time |
|
|
|
bestResult = result; |
|
|
|
} |
|
|
|
onUpdatedStandings(data: any) { |
|
|
|
if(this.season != undefined && data.seasonId != this.season.id){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
return bestResult |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
calculateSeasonPoints() { |
|
|
|
|
|
|
|
if(this.races == undefined) { |
|
|
|
return; |
|
|
|
let sorted = [] |
|
|
|
for(let result of data.newStandings){ |
|
|
|
sorted.push(result) |
|
|
|
} |
|
|
|
|
|
|
|
let maxRacePoints = this.seasonRacers.size; |
|
|
|
sorted.sort((a, b) => { |
|
|
|
return a.points - b.points |
|
|
|
}) |
|
|
|
|
|
|
|
this.seasonPoints = new Map<string, SeasonStanding>(); |
|
|
|
this.sortedStandings = [...sorted]; |
|
|
|
} |
|
|
|
|
|
|
|
for( let race of this.races) { |
|
|
|
let availablePoints = maxRacePoints; |
|
|
|
let thisRaceResults = this.seasonRaceResults.get(race.id); |
|
|
|
if(thisRaceResults == undefined) { |
|
|
|
continue |
|
|
|
getRacerName(racer: any): string { |
|
|
|
if( racer != undefined) { |
|
|
|
if( racer.name == undefined || racer.name == "" ) { |
|
|
|
return racer.gameHandle; |
|
|
|
} |
|
|
|
|
|
|
|
thisRaceResults.sort((a,b) =>{ |
|
|
|
return a.time - b.time; |
|
|
|
}) |
|
|
|
|
|
|
|
for (let result of thisRaceResults) { |
|
|
|
if (this.seasonPoints.has(result.racer_id) == false) { |
|
|
|
this.seasonPoints.set(result.racer_id, new SeasonStanding(result.racer_id)); |
|
|
|
} |
|
|
|
|
|
|
|
let currentPoints = this.seasonPoints.get(result.racer_id); |
|
|
|
if( currentPoints == undefined ) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
currentPoints.points+=availablePoints; |
|
|
|
availablePoints -=1; |
|
|
|
} |
|
|
|
return racer.name + " (" + racer.gameHandle + ")" |
|
|
|
} |
|
|
|
|
|
|
|
this.sortedStandings = Array.from(this.seasonPoints.values()).sort((a, b) => { |
|
|
|
return b.points - a.points; |
|
|
|
}) |
|
|
|
|
|
|
|
this.sortedStandings = [...this.sortedStandings] |
|
|
|
return "" |
|
|
|
} |
|
|
|
*/ |
|
|
|
} |
|
|
|
|