opt-cc/static/src/app/statistic/campaign-player-detail/campaign-player-detail.comp...

196 lines
5.7 KiB
TypeScript
Raw Normal View History

2018-03-08 09:44:35 +01:00
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2018-03-07 11:56:50 +01:00
import {CampaignPlayer} from '../../models/model-interfaces';
import {PlayerService} from '../../services/logs/player.service';
import {ChartUtils} from '../../utils/chart-utils';
@Component({
selector: 'campaign-player-detail',
templateUrl: './campaign-player-detail.component.html',
styleUrls: ['./campaign-player-detail.component.css', '../../style/list-entry.css',
'../../style/hide-scrollbar.css', '../../style/overview.css']
})
2018-03-08 09:44:35 +01:00
export class CampaignPlayerDetailComponent implements OnInit {
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
2017-10-02 14:41:17 +02:00
campaignPlayer: CampaignPlayer = {campaign: {}, players: []};
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[] = [];
vehicleKillData: any[] = [];
2017-10-02 17:09:30 +02:00
deathData: any[] = [];
respawnData: any[] = [];
reviveData: any[] = [];
captureData: any[] = [];
yAxisKill = 'Kills';
yAxisFriendlyFire = 'FriendlyFire';
yAxisVehicleKill = 'Farzeug-Kills';
2017-10-02 17:09:30 +02:00
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 = [];
vehicleKillRefLines = [];
2017-10-02 17:09:30 +02:00
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-02 17:09:30 +02:00
totalKills;
totalFriendlyFire;
totalVehicleKills;
2017-10-02 17:09:30 +02:00
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-11-13 15:45:12 +01:00
constructor(private playerService: PlayerService) {
}
ngOnInit() {
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-03-07 11:56:50 +01:00
this.killData = this.assignData(this.yAxisKill, 'kill');
this.vehicleKillData = this.assignData(this.yAxisVehicleKill, 'vehicle');
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');
2018-02-26 09:04:27 +01:00
this.kdRatio = parseFloat((this.totalKills / (this.totalDeath === 0 ? 1 : this.totalDeath)).toFixed(2));
2018-03-11 09:39:05 +01:00
if (this.kdRatio > 1) {
this.maxKd = this.kdRatio * 1.7;
}
2018-02-26 09:04:27 +01:00
this.respawnDeathRatio = parseFloat((this.totalRespawn / (this.totalDeath === 0 ? 1 : this.totalDeath)).toFixed(2));
this.sumData = [
{
name: this.yAxisKill,
value: this.totalKills
},
{
name: this.yAxisFriendlyFire,
value: this.totalFriendlyFire
},
{
name: this.yAxisVehicleKill,
value: this.totalVehicleKills
},
2018-02-26 09:04:27 +01:00
{
name: this.yAxisDeath,
value: this.totalDeath
},
{
name: this.yAxisRespawn,
value: this.totalRespawn
},
{
name: this.yAxisRevive,
value: this.totalRevive
},
{
name: this.yAxisCapture,
value: this.totalCapture
}
];
2018-03-08 09:44:35 +01:00
Object.assign(this, [this.sumData, this.killData, this.friendlyFireData, this.vehicleKillData,
this.deathData, this.respawnData, this.reviveData, this.captureData]);
2018-02-26 09:04:27 +01:00
});
2017-10-02 14:41:17 +02:00
}
2017-10-02 17:09:30 +02:00
private assignData(label, field) {
2018-03-07 11:56:50 +01:00
const 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);
const value = this.campaignPlayer.players[i][field];
2017-10-02 14:41:17 +02:00
killObj.series.push({
name: warDateString,
value: value
});
total += value;
2017-10-02 14:41:17 +02:00
}
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 'vehicle':
this.vehicleKillRefLines.push({value: total / playerLength, name: this.avgLabel});
this.totalVehicleKills = total;
break;
2017-10-02 17:09:30 +02:00
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-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
}
}