now calculating avg of best two
This commit is contained in:
parent
19aa6f3a4c
commit
bce762bf4e
@ -20,6 +20,9 @@ app-topmenu {
|
|||||||
#routerContent {
|
#routerContent {
|
||||||
grid-area: content;
|
grid-area: content;
|
||||||
overflow: auto !important;
|
overflow: auto !important;
|
||||||
|
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
grid-auto-flow: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,15 +8,20 @@
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Team</td>
|
<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>
|
<td>Gem. beste 2</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr *ngFor="let team of teams">
|
<tr *ngFor="let team of teams">
|
||||||
<td>{{team.name}}</td>
|
<td>{{team.name}}</td>
|
||||||
<td class="timetd" *ngFor="let y of ' '.repeat(maxRaces).split(''), let x = index">
|
<ng-container *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>
|
<td class="timetd">
|
||||||
</td>
|
<p class="time" *ngFor="let time of getLapTimes(x, team.idteam)">{{time/1000| number:'1.2-2'}}s</p>
|
||||||
<td>Gem. beste 2</td>
|
<p class="racetimetotal">{{getRaceTime(x, team.idteam)/1000 | number:'1.2-2'}}s</p>
|
||||||
|
</td>
|
||||||
|
</ng-container>
|
||||||
|
<td>{{getAvgOfBestTwo(team.idteam)/1000 | number:'1.2-2'}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
|||||||
@ -3,3 +3,15 @@
|
|||||||
margin: 2px;
|
margin: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.penaltycell {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
.penaltycell:after {
|
||||||
|
content: " s";
|
||||||
|
font-size: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.racetimetotal {
|
||||||
|
border-top: 1px solid black;
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
|||||||
@ -44,8 +44,6 @@ export class PouleComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
this.championshipService.getTimesInPoule(this.idChampionship, this.tier, this.poule).subscribe(val => {
|
this.championshipService.getTimesInPoule(this.idChampionship, this.tier, this.poule).subscribe(val => {
|
||||||
this.times = 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
|
// preprocess this array -> map idteam on the laptime array so we can index it using 0..n-1
|
||||||
this.timesIndexed = {};
|
this.timesIndexed = {};
|
||||||
@ -56,8 +54,6 @@ export class PouleComponent implements OnInit {
|
|||||||
this.timesIndexed[t.idteam].push({laptimesms: t.laptimesms, penaltysum: t.penaltysum});
|
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;
|
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('lapnr/idteam' + lapNr + ' ' + idTeam);
|
||||||
// console.log(this.timesIndexed);
|
// console.log(this.timesIndexed);
|
||||||
// console.log(this.timesIndexed[idTeam][lapNr]);
|
// console.log(this.timesIndexed[idTeam][lapNr]);
|
||||||
if (!this.timesIndexed
|
if (!this.timesIndexed
|
||||||
|| !this.timesIndexed[idTeam]
|
|| !this.timesIndexed[idTeam]
|
||||||
|| !this.timesIndexed[idTeam][lapNr]
|
|| !this.timesIndexed[idTeam][raceNr]
|
||||||
|| !this.timesIndexed[idTeam][lapNr].laptimesms) {
|
|| !this.timesIndexed[idTeam][raceNr].laptimesms) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.timesIndexed[idTeam][lapNr].laptimesms;
|
return this.timesIndexed[idTeam][raceNr].laptimesms;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
app-poule {
|
||||||
|
background-color: yellowgreen;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
@ -26,6 +26,7 @@ export class TierComponent implements OnInit {
|
|||||||
if (tier && idChampionship) {
|
if (tier && idChampionship) {
|
||||||
this.tier = tier;
|
this.tier = tier;
|
||||||
this.idChampionship = idChampionship;
|
this.idChampionship = idChampionship;
|
||||||
|
console.log('refreshing tier/championship combo: '+this.tier+' '+this.idChampionship);
|
||||||
// ... load the corresponding poules
|
// ... load the corresponding poules
|
||||||
this.championshipService.getPoules(tier, idChampionship).subscribe(poules => {
|
this.championshipService.getPoules(tier, idChampionship).subscribe(poules => {
|
||||||
this.poules = poules;
|
this.poules = poules;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user