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

View File

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