From bce762bf4eb8436593dc47320750b6f21a53dfc7 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 1 Sep 2018 16:57:15 +0200 Subject: [PATCH] now calculating avg of best two --- src/app/app.component.scss | 3 ++ src/app/content/poule/poule.component.html | 15 ++++-- src/app/content/poule/poule.component.scss | 12 +++++ src/app/content/poule/poule.component.ts | 59 +++++++++++++++++++--- src/app/content/tier/tier.component.scss | 4 ++ src/app/content/tier/tier.component.ts | 1 + 6 files changed, 81 insertions(+), 13 deletions(-) diff --git a/src/app/app.component.scss b/src/app/app.component.scss index 06a5c24..5127cfd 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -20,6 +20,9 @@ app-topmenu { #routerContent { grid-area: content; overflow: auto !important; + + grid-template-columns: 1fr 1fr; + grid-auto-flow: column; } diff --git a/src/app/content/poule/poule.component.html b/src/app/content/poule/poule.component.html index 18de236..9a421e1 100644 --- a/src/app/content/poule/poule.component.html +++ b/src/app/content/poule/poule.component.html @@ -8,15 +8,20 @@ - + + + - - + + + +
TeamRace {{x+1}}Race {{x+1}} Gem. beste 2
{{team.name}} - {{time/1000}}s - Gem. beste 2 +

{{time/1000| number:'1.2-2'}}s

+

{{getRaceTime(x, team.idteam)/1000 | number:'1.2-2'}}s

+
{{getAvgOfBestTwo(team.idteam)/1000 | number:'1.2-2'}}
diff --git a/src/app/content/poule/poule.component.scss b/src/app/content/poule/poule.component.scss index 9f745cb..c6b5463 100644 --- a/src/app/content/poule/poule.component.scss +++ b/src/app/content/poule/poule.component.scss @@ -3,3 +3,15 @@ margin: 2px; } +.penaltycell { + transform: rotate(-90deg); +} +.penaltycell:after { + content: " s"; + font-size: 80%; +} + +.racetimetotal { + border-top: 1px solid black; + margin: 2px; +} diff --git a/src/app/content/poule/poule.component.ts b/src/app/content/poule/poule.component.ts index 181fcdc..91a216c 100644 --- a/src/app/content/poule/poule.component.ts +++ b/src/app/content/poule/poule.component.ts @@ -44,8 +44,6 @@ export class PouleComponent implements OnInit { }); 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 = {}; @@ -56,8 +54,6 @@ export class PouleComponent implements OnInit { this.timesIndexed[t.idteam].push({laptimesms: t.laptimesms, penaltysum: t.penaltysum}); }); - console.log('preprocessed'); - console.log(this.timesIndexed); }); } @@ -75,17 +71,64 @@ export class PouleComponent implements OnInit { return penaltysum; } - getTime(lapNr: number, idTeam: number):number[] { + getAvgOfBestTwo(idTeam: number) { + if (!this.timesIndexed) { + return null; + } + // first take all the values... calculate the averages + // each time is the total of a race + const teamTimes = this.timesIndexed[idTeam]; + + + if (!teamTimes || teamTimes.length < 2) { + return null; + } + + const totalTimes: number[] = []; + for(let raceNr = 0; raceNr < this.maxRaces; raceNr++) { + const raceTime = this.getRaceTime(raceNr, idTeam); + if(raceTime) { + totalTimes.push(raceTime); + } + } + + // averages are calculated... sort them + totalTimes.sort((a, b) => { + if (a < b) { + return -1; + } else if (a === b) { + return 0; + } else { + return 1; + } + } + ); + + // take the two lowest + return (totalTimes[0] + totalTimes[1]) / 2; + } + + getRaceTime(raceNr: number, idTeam: number): number { + const time = this.getLapTimes(raceNr, idTeam); + if (!time) { + return null; + } + return time.reduce((previousValue, currentValue) => { + return currentValue + previousValue; + }); + } + + getLapTimes(raceNr: number, idTeam: number): 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) { + || !this.timesIndexed[idTeam][raceNr] + || !this.timesIndexed[idTeam][raceNr].laptimesms) { return null; } - return this.timesIndexed[idTeam][lapNr].laptimesms; + return this.timesIndexed[idTeam][raceNr].laptimesms; } } diff --git a/src/app/content/tier/tier.component.scss b/src/app/content/tier/tier.component.scss index e69de29..73eba0a 100644 --- a/src/app/content/tier/tier.component.scss +++ b/src/app/content/tier/tier.component.scss @@ -0,0 +1,4 @@ +app-poule { + background-color: yellowgreen; + margin: 10px; +} diff --git a/src/app/content/tier/tier.component.ts b/src/app/content/tier/tier.component.ts index 24a7007..1fd1233 100644 --- a/src/app/content/tier/tier.component.ts +++ b/src/app/content/tier/tier.component.ts @@ -26,6 +26,7 @@ export class TierComponent implements OnInit { if (tier && idChampionship) { this.tier = tier; this.idChampionship = idChampionship; + console.log('refreshing tier/championship combo: '+this.tier+' '+this.idChampionship); // ... load the corresponding poules this.championshipService.getPoules(tier, idChampionship).subscribe(poules => { this.poules = poules;