Simplify logic for player campaign detail page init

pull/34/head
HardiReady 2018-04-27 09:23:43 +02:00
parent dd7bce59e3
commit 216c19dccd
1 changed files with 37 additions and 142 deletions

View File

@ -23,15 +23,6 @@ export class CampaignPlayerDetailComponent implements OnInit {
graphData: any[] = []; graphData: any[] = [];
sumData: any[] = []; sumData: any[] = [];
yAxisKill = 'Kills';
yAxisFriendlyFire = 'FriendlyFire';
yAxisVehicleLight = 'Fahrzeug (Light)';
yAxisVehicleHeavy = 'Fahrzeug (Heavy)';
yAxisVehicleAir = 'Fahrzeug (Air)';
yAxisDeath = 'Tode';
yAxisRespawn = 'Respawn';
yAxisRevive = 'Revive';
yAxisCapture = 'Eroberungen';
avgLabel = 'Durchschnitt'; avgLabel = 'Durchschnitt';
colorScheme = { colorScheme = {
@ -44,16 +35,6 @@ export class CampaignPlayerDetailComponent implements OnInit {
}; };
showRefLines = true; showRefLines = true;
showRefLabels = true; showRefLabels = true;
killRefLines = [];
vehicleLightRefLines = [];
vehicleHeavyRefLines = [];
vehicleAirRefLines = [];
deathRefLines = [];
captureRefLines = [];
friendlyFireRefLines = [];
reviveRefLines = [];
respawnRefLines = [];
gradient = false; gradient = false;
xAxis = true; xAxis = true;
yAxis = true; yAxis = true;
@ -64,23 +45,12 @@ export class CampaignPlayerDetailComponent implements OnInit {
timeline = false; timeline = false;
roundDomains = true; roundDomains = true;
totalKills;
totalFriendlyFire;
totalVehicleLight;
totalVehicleHeavy;
totalVehicleAir;
totalDeath;
totalRespawn;
totalRevive;
totalCapture;
kdRatio = 0; kdRatio = 0;
maxKd = 1.7; maxKd = 1.7;
respawnDeathRatio = 0; respawnDeathRatio = 0;
maxRespawnDeathRatio = 1; maxRespawnDeathRatio = 1;
constructor(private playerService: PlayerService) { constructor(private playerService: PlayerService) {
} }
@ -90,69 +60,26 @@ export class CampaignPlayerDetailComponent implements OnInit {
this.campaignPlayer = campaignPlayer; this.campaignPlayer = campaignPlayer;
this.graphData = [ this.graphData = [
{ {key: 'kill', label: 'Kills',},
data: this.assignData(this.yAxisKill, 'kill'), {key: 'friendlyFire', label: 'Friendly Fire',},
refLine: this.killRefLines, {key: 'death', label: 'Tode',},
label: this.yAxisKill, {key: 'respawn', label: 'Respawn',},
total: this.totalKills {key: 'revive', label: 'Revive',},
}, {key: 'flagTouch', label: 'Eroberungen',},
{ {key: 'vehicleLight', label: 'Fahrzeug (Leicht)',},
data: this.assignData(this.yAxisFriendlyFire, 'friendlyFire'), {key: 'vehicleHeavy', label: 'Fahrzeug (Schwer)',},
refLine: this.friendlyFireRefLines, {key: 'vehicleAir', label: 'Fahrzeug (Luft)',},
label: this.yAxisFriendlyFire,
total: this.totalFriendlyFire
},
{
data: this.assignData(this.yAxisDeath, 'death'),
refLine: this.deathRefLines,
label: this.yAxisDeath,
total: this.totalDeath
},
{
data: this.assignData(this.yAxisRespawn, 'respawn'),
refLine: this.respawnRefLines,
label: this.yAxisRespawn,
total: this.totalRespawn
},
{
data: this.assignData(this.yAxisRevive, 'revive'),
refLine: this.reviveRefLines,
label: this.yAxisRevive,
total: this.totalRevive
},
{
data: this.assignData(this.yAxisCapture, 'flagTouch'),
refLine: this.captureRefLines,
label: this.yAxisCapture,
total: this.totalCapture
},
{
data: this.assignData(this.yAxisVehicleLight, 'vehicleLight'),
refLine: this.vehicleLightRefLines,
label: this.yAxisVehicleLight,
total: this.totalVehicleLight
},
{
data: this.assignData(this.yAxisVehicleHeavy, 'vehicleHeavy'),
refLine: this.vehicleHeavyRefLines,
label: this.yAxisVehicleHeavy,
total: this.totalVehicleHeavy
},
{
data: this.assignData(this.yAxisVehicleAir, 'vehicleAir'),
refLine: this.vehicleAirRefLines,
label: this.yAxisVehicleAir,
total: this.totalVehicleAir
},
]; ];
const totalDeathDiv = this.totalDeath === 0 ? 1 : this.totalDeath; this.initDataArray();
this.kdRatio = parseFloat((this.totalKills / totalDeathDiv).toFixed(2));
const totalDeathDiv = this.graphData[2].total === 0 ? 1 : this.graphData[2].total;
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.totalRespawn / totalDeathDiv).toFixed(2)); this.respawnDeathRatio = parseFloat((this.graphData[3].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 = [];
@ -163,61 +90,29 @@ export class CampaignPlayerDetailComponent implements OnInit {
}); });
} }
private assignData(label, field) { private initDataArray() {
this.graphData.forEach(dataSet => {
const killObj = { const killObj = {
name: label, name: dataSet.label,
series: [] series: []
}; };
const playerLength = this.campaignPlayer.players.length; const playerLength = this.campaignPlayer.players.length;
let total = 0; let total = 0;
for (let i = 0; i < playerLength; i++) { for (let i = 0; i < playerLength; i++) {
const warDateString = ChartUtils.getShortDateString(this.campaignPlayer.players[i].warId.date); const warDateString = ChartUtils.getShortDateString(this.campaignPlayer.players[i].warId.date);
const value = this.campaignPlayer.players[i][field]; const value = this.campaignPlayer.players[i][dataSet.key];
killObj.series.push({ killObj.series.push({
name: warDateString, name: warDateString,
value: value value: value
}); });
total += value; total += value;
} }
switch (field) {
case 'kill': dataSet.data = [killObj];
this.killRefLines.push({value: total / playerLength, name: this.avgLabel}); dataSet.refLine = [{value: total / playerLength, name: this.avgLabel}]
this.totalKills = total; dataSet.total = 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;
case 'vehicleLight':
this.vehicleLightRefLines.push({value: total / playerLength, name: this.avgLabel});
this.totalVehicleLight = total;
break;
case 'vehicleHeavy':
this.vehicleHeavyRefLines.push({value: total / playerLength, name: this.avgLabel});
this.totalVehicleHeavy = total;
break;
case 'vehicleAir':
this.vehicleAirRefLines.push({value: total / playerLength, name: this.avgLabel});
this.totalVehicleAir = total;
break;
}
return [killObj];
} }
navigateBack() { navigateBack() {