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

182 lines
5.2 KiB
TypeScript
Raw Normal View History

2017-11-13 15:45:12 +01:00
import {Component, EventEmitter} from "@angular/core";
import {CampaignPlayer} from "../../models/model-interfaces";
2017-10-22 18:06:37 +02:00
import {PlayerService} from "../../services/logs/player.service";
2017-10-02 14:41:17 +02:00
import {ChartUtils} from "../../utils/chart-utils";
@Component({
selector: 'campaign-player-detail',
templateUrl: './campaign-player-detail.component.html',
2017-11-13 15:45:12 +01:00
inputs: ['campaignId', 'playerName'],
outputs: ['switchTab'],
styleUrls: ['./campaign-player-detail.component.css', '../../style/list-entry.css',
'../../style/hide-scrollbar.css', '../../style/overview.css']
})
export class CampaignPlayerDetailComponent {
2017-11-13 15:45:12 +01:00
campaignId: string;
playerName: string;
switchTab = new EventEmitter();
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[] = [];
deathData: any[] = [];
respawnData: any[] = [];
reviveData: any[] = [];
captureData: any[] = [];
yAxisKill = 'Kills';
yAxisFriendlyFire = 'FriendlyFire';
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 = [];
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;
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;
this.killData = this.assignData(this.yAxisKill, "kill");
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");
this.kdRatio = parseFloat((this.totalKills / (this.totalDeath === 0 ? 1 : this.totalDeath)).toFixed(2));
if (this.kdRatio > 1) this.maxKd = this.kdRatio * 1.7;
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.yAxisDeath,
value: this.totalDeath
},
{
name: this.yAxisRespawn,
value: this.totalRespawn
},
{
name: this.yAxisRevive,
value: this.totalRevive
},
{
name: this.yAxisCapture,
value: this.totalCapture
}
];
Object.assign(this, [this.sumData, this.killData, this.friendlyFireData, this.deathData, this.respawnData, this.reviveData, this.captureData]);
});
2017-10-02 14:41:17 +02:00
}
2017-10-02 17:09:30 +02:00
private assignData(label, field) {
2017-10-02 14:41:17 +02:00
let 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);
2017-10-02 17:09:30 +02:00
const warKills = this.campaignPlayer.players[i][field];
2017-10-02 14:41:17 +02:00
killObj.series.push({
name: warDateString,
value: warKills
});
2017-10-02 14:41:17 +02:00
total += warKills;
}
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 '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
}
}