got first / second time working in color

This commit is contained in:
Joachim 2018-09-08 20:19:34 +02:00
parent 59b15ac310
commit ff4d5695a3
3 changed files with 56 additions and 5 deletions

View File

@ -38,7 +38,9 @@
<!--<span class="timecell seconds">{{getPenaltySum(raceindex, team.idteam)}}</span>--> <!--<span class="timecell seconds">{{getPenaltySum(raceindex, team.idteam)}}</span>-->
<app-timespan [theNumber]="getPenaltySum(raceindex, team.idteam)" [theUnit]="'s'"></app-timespan> <app-timespan [theNumber]="getPenaltySum(raceindex, team.idteam)" [theUnit]="'s'"></app-timespan>
</div> </div>
<div class="totalcell" [ngStyle]="{'grid-column':3, 'grid-row':2+(teamindex*(maxRaces+1))+raceindex+1}"> <div class="totalcell" [ngStyle]="{'grid-column':3, 'grid-row':2+(teamindex*(maxRaces+1))+raceindex+1}"
[class]="'timerank'+getTimeRank(raceindex, team.idteam)"
>
<app-timespan [theNumber]="getRaceTime(raceindex, team.idteam) | minutes" [theUnit]="'m'"></app-timespan> <app-timespan [theNumber]="getRaceTime(raceindex, team.idteam) | minutes" [theUnit]="'m'"></app-timespan>
<app-timespan [theNumber]="getRaceTimeSeconds(raceindex, team.idteam)" [theUnit]="'s'"></app-timespan> <app-timespan [theNumber]="getRaceTimeSeconds(raceindex, team.idteam)" [theUnit]="'s'"></app-timespan>
</div> </div>

View File

@ -40,6 +40,11 @@
.resultcell { .resultcell {
font-size: 120%; font-size: 120%;
} }
.best { .timerank0 {
background-color: forestgreen; color: #1dd21d;
font-weight: bolder;
}
.timerank1 {
color :darkorange;
font-weight: bold;
} }

View File

@ -14,6 +14,7 @@ export class PouleComponent implements OnInit {
protected teams: any[] = []; protected teams: any[] = [];
protected times: any[] = []; protected times: any[] = [];
protected teamtotaltimes: {};
protected maxRaces = 0; protected maxRaces = 0;
private timesIndexed: {}; private timesIndexed: {};
@ -56,7 +57,8 @@ export class PouleComponent implements OnInit {
console.log('loading data.'); console.log('loading data.');
// fetch the poule data // fetch the poule data
this.championshipService.getTeamsInPoule(this.topmenuService.championship$.value, this.topmenuService.tier$.value, this.topmenuService.poule$.value) this.championshipService.getTeamsInPoule(this.topmenuService.championship$.value, this.topmenuService.tier$.value,
this.topmenuService.poule$.value)
.subscribe(val => { .subscribe(val => {
this.teams = val; this.teams = val;
@ -69,11 +71,13 @@ export class PouleComponent implements OnInit {
}); });
this.maxRaces = maxRaces; this.maxRaces = maxRaces;
}); });
this.championshipService.getTimesInPoule(this.topmenuService.championship$.value, this.topmenuService.tier$.value, this.topmenuService.poule$.value).subscribe(val => { this.championshipService.getTimesInPoule(this.topmenuService.championship$.value, this.topmenuService.tier$.value,
this.topmenuService.poule$.value).subscribe(val => {
this.times = val; this.times = 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 = {};
this.teamtotaltimes = {};
this.maxLaps = 0; this.maxLaps = 0;
this.times.forEach(t => { this.times.forEach(t => {
if (!this.timesIndexed[t.idteam]) { if (!this.timesIndexed[t.idteam]) {
@ -84,10 +88,35 @@ export class PouleComponent implements OnInit {
this.maxLaps = t.laptimesms.length; this.maxLaps = t.laptimesms.length;
} }
// get the list of times, sorted, for each team
if (!this.teamtotaltimes[t.idteam]) {
this.teamtotaltimes[t.idteam] = [];
}
const sum = t.laptimesms.reduce((prev, next) => {
return prev + next;
});
this.teamtotaltimes[t.idteam].push(+(sum + (t.penaltysum * 1000)));
// calculate the best two // calculate the best two
this.bestTwo[t.idteam] = this.getBestTwo(t.idteam); this.bestTwo[t.idteam] = this.getBestTwo(t.idteam);
}); });
console.log('totaltimes');
console.log(this.teamtotaltimes);
Object.keys(this.teamtotaltimes).forEach(key => {
this.teamtotaltimes[key].sort((a, b) => {
if (a < b) {
return -1;
} else if (a === b) {
return 0;
} else {
return 1;
}
}
);
});
}); });
} }
@ -160,6 +189,10 @@ export class PouleComponent implements OnInit {
} }
} }
getPenalisedRaceTime(raceNr: number, idTeam: number): number {
return this.getRaceTime(raceNr, idTeam) + (this.getPenaltySum(raceNr, idTeam) * 1000);
}
getRaceTime(raceNr: number, idTeam: number): number { getRaceTime(raceNr: number, idTeam: number): number {
const time = this.getLapTimes(raceNr, idTeam); const time = this.getLapTimes(raceNr, idTeam);
if (!time) { if (!time) {
@ -201,4 +234,15 @@ export class PouleComponent implements OnInit {
} }
} }
getTimeRank(raceindex, idteam: any) {
if (!this.teamtotaltimes) {
return -1;
}
let penalisedRaceTime = this.getPenalisedRaceTime(raceindex, idteam);
let indexOf = this.teamtotaltimes[idteam].indexOf(penalisedRaceTime);
console.log(penalisedRaceTime + ' ' + indexOf);
console.log(this.teamtotaltimes[idteam]);
console.log(this.timesIndexed[idteam]);
return indexOf;
}
} }