2018-03-08 09:44:35 +01:00
|
|
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
2018-04-29 10:07:20 +02:00
|
|
|
import {CampaignPlayer} from '../../../models/model-interfaces';
|
|
|
|
import {PlayerService} from '../../../services/logs/player.service';
|
|
|
|
import {ChartUtils} from '../../../utils/chart-utils';
|
2018-05-05 09:32:16 +02:00
|
|
|
import {PlayerUtils} from '../../../utils/player-utils';
|
2018-10-02 14:31:26 +02:00
|
|
|
import {TranslateService} from '@ngx-translate/core';
|
2017-10-01 20:24:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'campaign-player-detail',
|
|
|
|
templateUrl: './campaign-player-detail.component.html',
|
2018-04-29 10:07:20 +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
|
|
|
})
|
2018-03-08 09:44:35 +01:00
|
|
|
export class CampaignPlayerDetailComponent implements OnInit {
|
2017-10-01 20:24:35 +02:00
|
|
|
|
2018-03-07 11:56:50 +01:00
|
|
|
@Input() campaignId: string;
|
2017-11-13 15:45:12 +01:00
|
|
|
|
2018-03-07 11:56:50 +01:00
|
|
|
@Input() playerName: string;
|
2017-11-13 15:45:12 +01:00
|
|
|
|
2018-03-07 11:56:50 +01:00
|
|
|
@Output() switchTab = new EventEmitter();
|
2017-11-13 15:45:12 +01:00
|
|
|
|
2018-10-03 11:49:17 +02:00
|
|
|
campaignPlayer: CampaignPlayer = {name: '', campaign: {}, players: []};
|
2017-10-01 20:24:35 +02:00
|
|
|
|
2018-04-27 09:03:57 +02:00
|
|
|
graphData: any[] = [];
|
2017-10-02 17:09:30 +02:00
|
|
|
sumData: any[] = [];
|
|
|
|
|
2018-10-02 14:31:26 +02:00
|
|
|
translations = {};
|
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;
|
|
|
|
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
|
|
|
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
|
|
|
|
2019-02-10 18:22:47 +01:00
|
|
|
playerAttributeNameMap = PlayerUtils.tmpAttributeDisplayNames.slice(2, PlayerUtils.tmpAttributeDisplayNames.length);
|
2018-05-05 09:32:16 +02:00
|
|
|
|
2018-10-02 14:31:26 +02:00
|
|
|
constructor(private playerService: PlayerService,
|
|
|
|
private translate: TranslateService) {
|
2017-10-01 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-10-02 14:31:26 +02:00
|
|
|
['stats.player.detail.graph.average',
|
|
|
|
'stats.player.detail.kill.death.ratio',
|
|
|
|
'stats.player.detail.respawn.death.ratio'].forEach((i18n) => {
|
|
|
|
this.translate.get(i18n).subscribe((translated) => {
|
|
|
|
this.translations[i18n] = translated;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-13 15:45:12 +01:00
|
|
|
this.playerService.getCampaignPlayer(this.campaignId, encodeURIComponent(this.playerName))
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe(campaignPlayer => {
|
|
|
|
this.campaignPlayer = campaignPlayer;
|
|
|
|
|
2018-05-05 09:32:16 +02:00
|
|
|
for (let i = 0; i < this.playerAttributeNameMap.length; i++) {
|
|
|
|
const attr = this.playerAttributeNameMap[i];
|
2018-10-03 11:22:21 +02:00
|
|
|
this.translate.get(attr.head).subscribe((translated) => {
|
|
|
|
this.graphData.push({key: attr.prop, label: translated});
|
|
|
|
});
|
2018-05-05 09:32:16 +02:00
|
|
|
}
|
2018-02-26 09:04:27 +01:00
|
|
|
|
2018-04-27 09:23:43 +02:00
|
|
|
this.initDataArray();
|
|
|
|
|
2018-05-05 09:32:16 +02:00
|
|
|
const totalDeathDiv = this.graphData[7].total === 0 ? 1 : this.graphData[7].total;
|
2018-04-27 09:23:43 +02:00
|
|
|
this.kdRatio = parseFloat((this.graphData[0].total / totalDeathDiv).toFixed(2));
|
2018-04-27 09:03:57 +02:00
|
|
|
if (this.kdRatio > 1) {
|
|
|
|
this.maxKd = this.kdRatio * 1.7;
|
|
|
|
}
|
|
|
|
|
2018-05-05 09:32:16 +02:00
|
|
|
this.respawnDeathRatio = parseFloat((this.graphData[8].total / totalDeathDiv).toFixed(2));
|
2018-04-27 09:03:57 +02:00
|
|
|
|
|
|
|
// we can not directly push to target array, since only full reference changes trigger the refresh of data
|
|
|
|
const tmpSumData = [];
|
|
|
|
this.graphData.forEach(dataSet => {
|
2018-05-05 09:32:16 +02:00
|
|
|
tmpSumData.push({name: dataSet.label, value: dataSet.total});
|
2018-04-27 09:03:57 +02:00
|
|
|
});
|
|
|
|
this.sumData = tmpSumData;
|
2018-02-26 09:04:27 +01:00
|
|
|
});
|
2017-10-02 14:41:17 +02:00
|
|
|
}
|
|
|
|
|
2018-04-27 09:23:43 +02:00
|
|
|
private initDataArray() {
|
|
|
|
this.graphData.forEach(dataSet => {
|
|
|
|
const killObj = {
|
|
|
|
name: dataSet.label,
|
|
|
|
series: []
|
|
|
|
};
|
|
|
|
const playerLength = this.campaignPlayer.players.length;
|
|
|
|
let total = 0;
|
|
|
|
for (let i = 0; i < playerLength; i++) {
|
|
|
|
const warDateString = ChartUtils.getShortDateString(this.campaignPlayer.players[i].warId.date);
|
|
|
|
const value = this.campaignPlayer.players[i][dataSet.key];
|
|
|
|
killObj.series.push({
|
|
|
|
name: warDateString,
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
total += value;
|
|
|
|
}
|
|
|
|
|
|
|
|
dataSet.data = [killObj];
|
2018-10-02 14:31:26 +02:00
|
|
|
dataSet.refLine = [{value: total / playerLength, name: this.translations['stats.player.detail.graph.average']}];
|
2018-04-27 09:23:43 +02:00
|
|
|
dataSet.total = total;
|
2018-04-27 09:29:30 +02:00
|
|
|
});
|
2017-10-01 20:24:35 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 18:10:57 +02:00
|
|
|
navigateBack() {
|
2017-11-13 15:45:12 +01:00
|
|
|
this.switchTab.emit(0);
|
2017-10-02 18:10:57 +02:00
|
|
|
}
|
2017-10-01 20:24:35 +02:00
|
|
|
}
|