Adjust player stat attribute order; improve code for player campaign stats init

pull/34/head
HardiReady 2018-05-05 09:32:16 +02:00
parent d6703f715d
commit 96afbefbf2
2 changed files with 22 additions and 20 deletions

View File

@ -2,6 +2,7 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {CampaignPlayer} from '../../../models/model-interfaces';
import {PlayerService} from '../../../services/logs/player.service';
import {ChartUtils} from '../../../utils/chart-utils';
import {PlayerUtils} from '../../../utils/player-utils';
@Component({
@ -18,7 +19,7 @@ export class CampaignPlayerDetailComponent implements OnInit {
@Output() switchTab = new EventEmitter();
campaignPlayer: CampaignPlayer = { campaign: {}, players: [] };
campaignPlayer: CampaignPlayer = {campaign: {}, players: []};
graphData: any[] = [];
sumData: any[] = [];
@ -51,6 +52,8 @@ export class CampaignPlayerDetailComponent implements OnInit {
respawnDeathRatio = 0;
maxRespawnDeathRatio = 1;
playerAttributeNameMap = PlayerUtils.attributeDisplayNames.slice(2, PlayerUtils.attributeDisplayNames.length);
constructor(private playerService: PlayerService) {
}
@ -59,32 +62,25 @@ export class CampaignPlayerDetailComponent implements OnInit {
.subscribe(campaignPlayer => {
this.campaignPlayer = campaignPlayer;
this.graphData = [
{ key: 'kill', label: 'Abschüsse', },
{ key: 'friendlyFire', label: 'Friendly Fire', },
{ key: 'death', label: 'Tode', },
{ key: 'respawn', label: 'Respawn', },
{ key: 'revive', label: 'Revive', },
{ key: 'flagTouch', label: 'Eroberungen', },
{ key: 'vehicleLight', label: 'Fahrzeug (Leicht)', },
{ key: 'vehicleHeavy', label: 'Fahrzeug (Schwer)', },
{ key: 'vehicleAir', label: 'Fahrzeug (Luft)', },
];
for (let i = 0; i < this.playerAttributeNameMap.length; i++) {
const attr = this.playerAttributeNameMap[i];
this.graphData.push({key: attr.prop, label: attr.head});
}
this.initDataArray();
const totalDeathDiv = this.graphData[2].total === 0 ? 1 : this.graphData[2].total;
const totalDeathDiv = this.graphData[7].total === 0 ? 1 : this.graphData[7].total;
this.kdRatio = parseFloat((this.graphData[0].total / totalDeathDiv).toFixed(2));
if (this.kdRatio > 1) {
this.maxKd = this.kdRatio * 1.7;
}
this.respawnDeathRatio = parseFloat((this.graphData[3].total / totalDeathDiv).toFixed(2));
this.respawnDeathRatio = parseFloat((this.graphData[8].total / totalDeathDiv).toFixed(2));
// we can not directly push to target array, since only full reference changes trigger the refresh of data
const tmpSumData = [];
this.graphData.forEach(dataSet => {
tmpSumData.push({ name: dataSet.label, value: dataSet.total });
tmpSumData.push({name: dataSet.label, value: dataSet.total});
});
this.sumData = tmpSumData;
});
@ -109,7 +105,7 @@ export class CampaignPlayerDetailComponent implements OnInit {
}
dataSet.data = [killObj];
dataSet.refLine = [{ value: total / playerLength, name: this.avgLabel }];
dataSet.refLine = [{value: total / playerLength, name: this.avgLabel}];
dataSet.total = total;
});
}

View File

@ -1,10 +1,16 @@
export class PlayerUtils {
public static readonly attributeDisplayNames = [
{prop: 'name', head: 'Spieler'}, {prop: 'fraction', head: 'Fraktion'}, {prop: 'kill', head: 'Abschüsse'},
{prop: 'friendlyFire', head: 'Friendly Fire'}, {prop: 'vehicleLight', head: 'Fahrzeug (leicht)'},
{prop: 'vehicleHeavy', head: 'Fahrzeug (schwer)'}, {prop: 'vehicleAir', head: 'Fahrzeug (Luft)'},
{prop: 'revive', head: 'Revive'}, {prop: 'flagTouch', head: 'Eroberungen'}, {prop: 'death', head: 'Tode'},
{prop: 'name', head: 'Spieler'},
{prop: 'fraction', head: 'Fraktion'},
{prop: 'kill', head: 'Abschüsse'},
{prop: 'friendlyFire', head: 'Friendly Fire'},
{prop: 'revive', head: 'Revive'},
{prop: 'flagTouch', head: 'Eroberungen'},
{prop: 'vehicleLight', head: 'Fahrzeug (leicht)'},
{prop: 'vehicleHeavy', head: 'Fahrzeug (schwer)'},
{prop: 'vehicleAir', head: 'Fahrzeug (Luft)'},
{prop: 'death', head: 'Tode'},
{prop: 'respawn', head: 'Respawn'}
];