From 2e9ae2fdfe2e7de73248ab1577f9225d5289281e Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 1 Sep 2018 15:31:26 +0200 Subject: [PATCH] getting times into the frontend --- src/app/championship.service.ts | 30 ++++++++++ src/app/content/poule/poule.component.html | 18 +++--- src/app/content/poule/poule.component.ts | 70 +++++++++++++++++++++- src/app/content/tier/tier.component.ts | 1 + 4 files changed, 108 insertions(+), 11 deletions(-) diff --git a/src/app/championship.service.ts b/src/app/championship.service.ts index c6ee9f1..0d3300e 100644 --- a/src/app/championship.service.ts +++ b/src/app/championship.service.ts @@ -102,4 +102,34 @@ export class ChampionshipService implements OnInit { getPoules(tier: number, idChampionship: any): Observable { return this.http.get(`${this.baseUrl}championship/${idChampionship}/tier/${tier}/poules`, this.httpOptions); } + + /** + * Get all the data for this poule. + * @param idChampionship + * @param tier + * @param poule + */ + getPoule(idChampionship: number, tier: number, poule: number) { + + } + + /** + * Get all the teams in a specific poule. + * @param idChampionship + * @param tier + * @param poule + */ + getTeamsInPoule(idChampionship: number, tier: number, poule: number) { + return this.http.get(`${this.baseUrl}championship/${idChampionship}/tier/${tier}/poule/${poule}/teams`, this.httpOptions); + } + + /** + * Get all publishes times in a poule. + * @param idChampionship + * @param tier + * @param poule + */ + getTimesInPoule(idChampionship: number, tier: number, poule: number) { + return this.http.get(`${this.baseUrl}championship/${idChampionship}/tier/${tier}/poule/${poule}/times`, this.httpOptions); + } } diff --git a/src/app/content/poule/poule.component.html b/src/app/content/poule/poule.component.html index f6f6969..b93718e 100644 --- a/src/app/content/poule/poule.component.html +++ b/src/app/content/poule/poule.component.html @@ -1,24 +1,22 @@ - Poule {{poule}} {{tier}} {{idChampionship}} + Poule {{poule}} - - - + - - - - - - + + + +
TeamRonde 1Ronde 2Ronde 3Race {{x+1}} Gem. beste 2
Jos en Frank2 mins2 mins2 mins2 mins
{{team.name}} + {{getTime(x, team.idteam)}} + Gem. beste 2
diff --git a/src/app/content/poule/poule.component.ts b/src/app/content/poule/poule.component.ts index 0c364fd..5562954 100644 --- a/src/app/content/poule/poule.component.ts +++ b/src/app/content/poule/poule.component.ts @@ -1,4 +1,5 @@ import {Component, Input, OnInit} from '@angular/core'; +import {ChampionshipService} from '../../championship.service'; @Component({ selector: 'app-poule', @@ -16,10 +17,77 @@ export class PouleComponent implements OnInit { @Input() tier: number; - constructor() { + protected teams: any[] = []; + protected times: any[] = []; + protected maxRaces = 0; + private timesIndexed: {}; + + constructor(private championshipService: ChampionshipService) { } ngOnInit() { + console.log('POULE COMP: ' + this.poule + ' ' + this.idChampionship + ' ' + this.tier); + // fetch the poule data + this.championshipService.getTeamsInPoule(this.idChampionship, this.tier, this.poule).subscribe(val => { + this.teams = val; + console.log('teams in poule'); + console.log(val); + + // calculate the maximum of the racecounts... this influences the amount of columns in the table + let maxRaces = 0; + this.teams.forEach(t => { + if (t.racecount > maxRaces) { + maxRaces = t.racecount; + } + }); + this.maxRaces = maxRaces; + }); + this.championshipService.getTimesInPoule(this.idChampionship, this.tier, this.poule).subscribe(val => { + this.times = val; + console.log('times'); + console.log(val); + + // preprocess this array -> map idteam on the laptime array so we can index it using 0..n-1 + this.timesIndexed = {}; + this.times.forEach(t => { + if (!this.timesIndexed[t.idteam]) { + this.timesIndexed[t.idteam] = []; + } + this.timesIndexed[t.idteam].push({laptimesms: t.laptimesms, penaltysum: t.penaltysum}); + }); + + console.log('preprocessed'); + console.log(this.timesIndexed); + }); + } + + /** + * Get an array of laps: + * [{ lap: 1, time: xxxx}, {lap : 2, time: yyyy}] + */ + getTimesForRace(raceNr: number, idTeam: number) { + // what is the 'raceNr'd idrace? first get the unique idraces, they're already sorted, then take the 'raceNr'd one. + // const anies = this.times.filter(t => t.idteam === idTeam); + // if (anies && anies.length >= raceNr) { + // console.log('anies'); + // console.log(anies); + // return anies[raceNr - 1]; + // } else { + // return []; + // } + } + + getTime(lapNr: number, idTeam: number) { + // console.log('lapnr/idteam' + lapNr + ' ' + idTeam); + // console.log(this.timesIndexed); + // console.log(this.timesIndexed[idTeam][lapNr]); + if (!this.timesIndexed + || !this.timesIndexed[idTeam] + || !this.timesIndexed[idTeam][lapNr] + || !this.timesIndexed[idTeam][lapNr].laptimesms) { + return null; + } + return this.timesIndexed[idTeam][lapNr].laptimesms; } } diff --git a/src/app/content/tier/tier.component.ts b/src/app/content/tier/tier.component.ts index 6477672..24a7007 100644 --- a/src/app/content/tier/tier.component.ts +++ b/src/app/content/tier/tier.component.ts @@ -29,6 +29,7 @@ export class TierComponent implements OnInit { // ... load the corresponding poules this.championshipService.getPoules(tier, idChampionship).subscribe(poules => { this.poules = poules; + console.log(this.poules); }); } });