now calculating avg of best two

This commit is contained in:
Joachim 2018-09-01 16:57:15 +02:00
parent 19aa6f3a4c
commit bce762bf4e
6 changed files with 81 additions and 13 deletions

View File

@ -20,6 +20,9 @@ app-topmenu {
#routerContent {
grid-area: content;
overflow: auto !important;
grid-template-columns: 1fr 1fr;
grid-auto-flow: column;
}

View File

@ -8,15 +8,20 @@
<table>
<tr>
<td>Team</td>
<td *ngFor="let y of ' '.repeat(maxRaces).split(''), let x = index">Race {{x+1}}</td>
<ng-container *ngFor="let y of ' '.repeat(maxRaces).split(''), let x = index">
<td>Race {{x+1}}</td>
</ng-container>
<td>Gem. beste 2</td>
</tr>
<tr *ngFor="let team of teams">
<td>{{team.name}}</td>
<td class="timetd" *ngFor="let y of ' '.repeat(maxRaces).split(''), let x = index">
<span class="time" *ngFor="let time of getTime(x, team.idteam)">{{time/1000}}s</span>
<ng-container *ngFor="let y of ' '.repeat(maxRaces).split(''), let x = index">
<td class="timetd">
<p class="time" *ngFor="let time of getLapTimes(x, team.idteam)">{{time/1000| number:'1.2-2'}}s</p>
<p class="racetimetotal">{{getRaceTime(x, team.idteam)/1000 | number:'1.2-2'}}s</p>
</td>
<td>Gem. beste 2</td>
</ng-container>
<td>{{getAvgOfBestTwo(team.idteam)/1000 | number:'1.2-2'}}</td>
</tr>
</table>
</mat-card-content>

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -0,0 +1,4 @@
app-poule {
background-color: yellowgreen;
margin: 10px;
}

View File

@ -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;