From 59b15ac310e68df6635fede68b6c2e008def9419 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 8 Sep 2018 19:16:29 +0200 Subject: [PATCH] working on getting times right --- src/app/content/poule/poule.component.scss | 3 +++ src/app/content/poule/poule.component.ts | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/content/poule/poule.component.scss b/src/app/content/poule/poule.component.scss index e41453b..86914ec 100644 --- a/src/app/content/poule/poule.component.scss +++ b/src/app/content/poule/poule.component.scss @@ -40,3 +40,6 @@ .resultcell { font-size: 120%; } +.best { + background-color: forestgreen; +} diff --git a/src/app/content/poule/poule.component.ts b/src/app/content/poule/poule.component.ts index f50a702..0221610 100644 --- a/src/app/content/poule/poule.component.ts +++ b/src/app/content/poule/poule.component.ts @@ -14,8 +14,11 @@ export class PouleComponent implements OnInit { protected teams: any[] = []; protected times: any[] = []; + protected maxRaces = 0; private timesIndexed: {}; + // these are the best two times for each team, indexed by their id + protected bestTwo: {}; protected maxLaps = 0; constructor(private championshipService: ChampionshipService, private route: ActivatedRoute, private topmenuService: TopmenuService) { @@ -48,6 +51,7 @@ export class PouleComponent implements OnInit { private loadData() { this.teams = []; this.times = []; + this.bestTwo = {}; console.log('loading data.'); @@ -79,6 +83,9 @@ export class PouleComponent implements OnInit { if (t.laptimesms.length > this.maxLaps) { this.maxLaps = t.laptimesms.length; } + + // calculate the best two + this.bestTwo[t.idteam] = this.getBestTwo(t.idteam); }); }); @@ -102,7 +109,7 @@ export class PouleComponent implements OnInit { * Get the best two racetimes (including penalties) * @param idTeam */ - getBestTwo(idTeam: number): number[] { + private getBestTwo(idTeam: number): number[] { if (!this.timesIndexed) { return null; } @@ -146,10 +153,8 @@ export class PouleComponent implements OnInit { * @param idTeam */ getAvgOfBestTwo(idTeam: number) { - const bestTwo = this.getBestTwo(idTeam); - console.log(idTeam+' '+bestTwo); - if (bestTwo && bestTwo.length === 2) { - return (bestTwo[0] + bestTwo[1]) / 2; + if (this.bestTwo && this.bestTwo[idTeam] && this.bestTwo[idTeam].length === 2) { + return (this.bestTwo[idTeam][0] + this.bestTwo[idTeam][1]) / 2; } else { return null; } @@ -195,4 +200,5 @@ export class PouleComponent implements OnInit { return null; } } + }