2017-10-01 20:24:35 +02:00
|
|
|
import {Component} from "@angular/core";
|
|
|
|
import {ActivatedRoute} from "@angular/router";
|
|
|
|
import {CampaignPlayer} from "../../models/model-interfaces";
|
2017-10-22 18:06:37 +02:00
|
|
|
import {PlayerService} from "../../services/logs/player.service";
|
2017-10-02 14:41:17 +02:00
|
|
|
import {ChartUtils} from "../../utils/chart-utils";
|
2017-10-02 18:10:57 +02:00
|
|
|
import {Location} from '@angular/common';
|
2017-10-01 20:24:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'campaign-player-detail',
|
|
|
|
templateUrl: './campaign-player-detail.component.html',
|
2017-10-07 19:32:16 +02:00
|
|
|
styleUrls: ['./campaign-player-detail.component.css', '../../style/list-entry.css',
|
|
|
|
'../../style/hide-scrollbar.css', '../../style/overview.css']
|
2017-10-01 20:24:35 +02:00
|
|
|
})
|
|
|
|
export class CampaignPlayerDetailComponent {
|
|
|
|
|
2017-10-02 14:41:17 +02:00
|
|
|
campaignPlayer: CampaignPlayer = {campaign: {}, players: []};
|
2017-10-01 20:24:35 +02:00
|
|
|
|
2017-10-02 17:09:30 +02:00
|
|
|
sumData: any[] = [];
|
2017-10-02 14:41:17 +02:00
|
|
|
killData: any[] = [];
|
2017-10-02 17:09:30 +02:00
|
|
|
friendlyFireData: any[] = [];
|
|
|
|
deathData: any[] = [];
|
|
|
|
respawnData: any[] = [];
|
|
|
|
reviveData: any[] = [];
|
|
|
|
captureData: any[] = [];
|
|
|
|
|
|
|
|
yAxisKill = 'Kills';
|
|
|
|
yAxisFriendlyFire = 'FriendlyFire';
|
|
|
|
yAxisDeath = 'Tode';
|
|
|
|
yAxisRespawn = 'Respawn';
|
|
|
|
yAxisRevive = 'Revive';
|
|
|
|
yAxisCapture = 'Eroberungen';
|
2017-10-02 18:10:57 +02:00
|
|
|
avgLabel = 'Durchschnitt';
|
2017-10-02 14:41:17 +02:00
|
|
|
|
|
|
|
colorScheme = {
|
|
|
|
domain: ['#00ce12']
|
|
|
|
};
|
2017-10-02 17:09:30 +02:00
|
|
|
colorSchemeBar = {
|
|
|
|
domain: [
|
|
|
|
'#2d5a00', '#455600', '#00561f', '#3f3b00', '#003c19', '#083c00'
|
|
|
|
]
|
|
|
|
};
|
2017-10-02 14:41:17 +02:00
|
|
|
showRefLines = true;
|
|
|
|
showRefLabels = true;
|
2017-10-02 17:09:30 +02:00
|
|
|
killRefLines = [];
|
|
|
|
deathRefLines = [];
|
|
|
|
captureRefLines = [];
|
|
|
|
friendlyFireRefLines = [];
|
|
|
|
reviveRefLines = [];
|
|
|
|
respawnRefLines = [];
|
|
|
|
|
2017-10-02 14:41:17 +02:00
|
|
|
gradient = false;
|
|
|
|
xAxis = true;
|
|
|
|
yAxis = true;
|
|
|
|
legend = false;
|
|
|
|
showXAxisLabel = true;
|
|
|
|
showYAxisLabel = true;
|
|
|
|
autoscale = false;
|
|
|
|
timeline = false;
|
|
|
|
roundDomains = true;
|
2017-10-01 20:24:35 +02:00
|
|
|
|
2017-10-02 17:09:30 +02:00
|
|
|
totalKills;
|
|
|
|
totalFriendlyFire;
|
|
|
|
totalDeath;
|
|
|
|
totalRespawn;
|
|
|
|
totalRevive;
|
|
|
|
totalCapture;
|
|
|
|
|
|
|
|
kdRatio = 0;
|
|
|
|
maxKd = 1.7;
|
2017-10-02 20:03:42 +02:00
|
|
|
|
2017-10-02 17:09:30 +02:00
|
|
|
respawnDeathRatio = 0;
|
2017-10-02 20:03:42 +02:00
|
|
|
maxRespawnDeathRatio = 1;
|
2017-10-02 17:09:30 +02:00
|
|
|
|
2017-10-01 20:24:35 +02:00
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
2017-10-02 18:10:57 +02:00
|
|
|
private location: Location,
|
2017-10-01 20:24:35 +02:00
|
|
|
private playerService: PlayerService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.params
|
|
|
|
.map(params => [params['id'], params['playerName']])
|
2017-10-02 18:10:57 +02:00
|
|
|
.flatMap(id => this.playerService.getCampaignPlayer(id[0], encodeURIComponent(id[1])))
|
2017-10-01 20:24:35 +02:00
|
|
|
.subscribe(campaignPlayer => {
|
|
|
|
this.campaignPlayer = campaignPlayer;
|
2017-10-02 17:09:30 +02:00
|
|
|
this.killData = this.assignData(this.yAxisKill, "kill");
|
|
|
|
this.friendlyFireData = this.assignData(this.yAxisFriendlyFire, "friendlyFire");
|
|
|
|
this.deathData = this.assignData(this.yAxisDeath, "death");
|
|
|
|
this.respawnData = this.assignData(this.yAxisRespawn, "respawn");
|
|
|
|
this.reviveData = this.assignData(this.yAxisRevive, "revive");
|
|
|
|
this.captureData = this.assignData(this.yAxisCapture, "flagTouch");
|
|
|
|
|
2017-10-28 12:58:40 +02:00
|
|
|
if (this.totalDeath === 0) {
|
|
|
|
// avoid infinite or NaN with no death
|
|
|
|
this.totalDeath = 1;
|
|
|
|
}
|
2017-10-02 17:09:30 +02:00
|
|
|
this.kdRatio = parseFloat((this.totalKills / this.totalDeath).toFixed(2));
|
|
|
|
if (this.kdRatio > 1) this.maxKd = this.kdRatio * 1.7;
|
|
|
|
|
|
|
|
this.respawnDeathRatio = parseFloat((this.totalRespawn / this.totalDeath).toFixed(2));
|
|
|
|
|
|
|
|
this.sumData = [
|
|
|
|
{
|
|
|
|
name: this.yAxisKill,
|
|
|
|
value: this.totalKills
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: this.yAxisFriendlyFire,
|
|
|
|
value: this.totalFriendlyFire
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: this.yAxisDeath,
|
|
|
|
value: this.totalDeath
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: this.yAxisRespawn,
|
2017-10-02 18:10:57 +02:00
|
|
|
value: this.totalRespawn
|
2017-10-02 17:09:30 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: this.yAxisRevive,
|
|
|
|
value: this.totalRevive
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: this.yAxisCapture,
|
|
|
|
value: this.totalCapture
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
Object.assign(this, [this.sumData, this.killData, this.friendlyFireData, this.deathData, this.respawnData, this.reviveData, this.captureData]);
|
2017-10-02 14:41:17 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-02 17:09:30 +02:00
|
|
|
private assignData(label, field) {
|
2017-10-02 14:41:17 +02:00
|
|
|
let killObj = {
|
2017-10-02 17:09:30 +02:00
|
|
|
name: label,
|
|
|
|
series: []
|
2017-10-02 14:41:17 +02:00
|
|
|
};
|
2017-10-02 17:09:30 +02:00
|
|
|
const playerLength = this.campaignPlayer.players.length;
|
2017-10-02 14:41:17 +02:00
|
|
|
let total = 0;
|
2017-10-02 17:09:30 +02:00
|
|
|
for (let i = 0; i < playerLength; i++) {
|
2017-10-02 14:41:17 +02:00
|
|
|
const warDateString = ChartUtils.getShortDateString(this.campaignPlayer.players[i].warId.date);
|
2017-10-02 17:09:30 +02:00
|
|
|
const warKills = this.campaignPlayer.players[i][field];
|
2017-10-02 14:41:17 +02:00
|
|
|
killObj.series.push({
|
|
|
|
name: warDateString,
|
|
|
|
value: warKills
|
2017-10-01 20:24:35 +02:00
|
|
|
});
|
2017-10-02 14:41:17 +02:00
|
|
|
total += warKills;
|
|
|
|
}
|
2017-10-02 17:09:30 +02:00
|
|
|
switch (field) {
|
|
|
|
case 'kill':
|
|
|
|
this.killRefLines.push({value: total / playerLength, name: this.avgLabel});
|
|
|
|
this.totalKills = total;
|
|
|
|
break;
|
|
|
|
case 'friendlyFire':
|
|
|
|
this.friendlyFireRefLines.push({value: total / playerLength, name: this.avgLabel});
|
|
|
|
this.totalFriendlyFire = total;
|
|
|
|
break;
|
|
|
|
case 'death':
|
|
|
|
this.deathRefLines.push({value: total / playerLength, name: this.avgLabel});
|
|
|
|
this.totalDeath = total;
|
|
|
|
break;
|
|
|
|
case 'respawn':
|
|
|
|
this.respawnRefLines.push({value: total / playerLength, name: this.avgLabel});
|
|
|
|
this.totalRespawn = total;
|
|
|
|
break;
|
|
|
|
case 'revive':
|
|
|
|
this.reviveRefLines.push({value: total / playerLength, name: this.avgLabel});
|
|
|
|
this.totalRevive = total;
|
|
|
|
break;
|
|
|
|
case 'flagTouch':
|
|
|
|
this.captureRefLines.push({value: total / playerLength, name: this.avgLabel});
|
|
|
|
this.totalCapture = total;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return [killObj];
|
2017-10-01 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 18:10:57 +02:00
|
|
|
navigateBack() {
|
|
|
|
this.location.back();
|
|
|
|
}
|
|
|
|
|
2017-10-01 20:24:35 +02:00
|
|
|
}
|