Merge branch 'release/v1.6.2' of hardi/opt-cc into master

feature/player-war-detail
hardi 2017-11-04 21:08:17 +01:00 committed by HardiReady
commit 7f84b065fc
9 changed files with 410 additions and 376 deletions

View File

@ -176,8 +176,15 @@ wars.route('/:id')
return next(err);
}
// delete players having this war ID as foreign key
// delete linked appearances
PlayerModel.find({warId: item._id}).remove().exec();
LogKillModel.find({war: item._id}).remove().exec();
LogRespawnModel.find({war: item._id}).remove().exec();
LogReviveModel.find({war: item._id}).remove().exec();
LogFlagModel.find({war: item._id}).remove().exec();
LogBudgetModel.find({war: item._id}).remove().exec();
LogTransportModel.find({war: item._id}).remove().exec();
LogPointsModel.find({war: item._id}).remove().exec();
// check if logfiles exist and delete from fs
const warDir = __dirname + '/../resource/logs/' + req.params.id;

View File

@ -67,9 +67,10 @@ const parseWarLog = (lineArray, war) => {
stats.war['endBudgetOpfor'] = transformMoneyString(budg[14]);
stats.war.endDate = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T0' + budg[5]);
} else if (line.includes('Startbudget')) {
stats.war.date = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T22:00:00');
stats.war['budgetBlufor'] = transformMoneyString(budg[11]);
stats.war['budgetOpfor'] = transformMoneyString(budg[14]);
// this date needs to be assigned in first place !important
stats.war.date = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T22:00:00');
} else {
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
}
@ -103,6 +104,7 @@ const parseWarLog = (lineArray, war) => {
if (line.includes('Endpunktestand')) {
stats.war['ptBlufor'] = parseInt(pt[11]);
stats.war['ptOpfor'] = parseInt(pt[14].slice(0, -1));
// EXIT LOOP
return true;
} else {
stats.points.push(getPointsEntry(pt, line, war._id, war.date))

View File

@ -1,6 +1,6 @@
{
"name": "opt-cc",
"version": "1.6.1",
"version": "1.6.2",
"license": "MIT",
"author": "Florian Hartwich <hardi@noarch.de>",
"private": true,

View File

@ -97,7 +97,6 @@ export class StatisticOverviewComponent {
break;
}
this.activeSlideIndex = index;
}
initChart(wars: any[]) {

View File

@ -4,7 +4,7 @@ import {SharedModule} from "../shared.module";
import {statsRouterModule, statsRoutingComponents} from "./stats.routing";
import {WarService} from "../services/logs/war.service";
import {NgxChartsModule} from "@swimlane/ngx-charts";
import {AccordionModule, TabsModule} from "ngx-bootstrap";
import {AccordionModule, BsDropdownModule, ButtonsModule, TabsModule} from "ngx-bootstrap";
import {CampaignService} from "../services/logs/campaign.service";
import {NgxDatatableModule} from "@swimlane/ngx-datatable";
import {PlayerService} from "../services/logs/player.service";
@ -13,7 +13,7 @@ import {LogsService} from "../services/logs/logs.service";
@NgModule({
declarations: statsRoutingComponents,
imports: [CommonModule, SharedModule, statsRouterModule, NgxChartsModule,
AccordionModule.forRoot(), TabsModule.forRoot(), NgxDatatableModule],
AccordionModule.forRoot(), BsDropdownModule.forRoot(), ButtonsModule.forRoot(), TabsModule.forRoot(), NgxDatatableModule],
providers: [WarService, CampaignService, PlayerService, LogsService]
})
export class StatsModule {

View File

@ -42,19 +42,10 @@
color: blue;
}
.chart-container {
width: 90%;
margin: 2%;
min-width: 900px;
height: 400px;
padding: 15px;
float: left;
}
/* ########### TABS ########### */
:host /deep/ .nav-tabs {
padding-left: 35%!important;
padding-left: 35% !important;
}
:host /deep/ .nav-link {
@ -63,11 +54,11 @@
}
:host /deep/ .nav-link:hover {
background: #286090;
background: #afafaf;
color: #000;
}
:host /deep/ .nav-tabs>li.active>a{
:host /deep/ .nav-tabs > li.active > a {
background: #222222;
color: white;
}
@ -107,3 +98,40 @@
background-color: #f7f7f7;
}
/* ########### CHART-TAB ######## */
.btn-dark {
background: #4b4b4b;
color: #f5f5f5;
border-color: #000;
}
.btn-dark:hover {
background: #afafaf;
color: #f5f5f5;
}
.btn-dark.active {
background: #222222;
}
.chart-container {
width: 95%;
margin: 2%;
min-width: 900px;
height: 600px;
padding: 15px;
float: left;
}
.chart-select-group {
width: 50%;
margin: auto;
position: inherit;
display: block;
vertical-align: middle;
}
/*.dropdown-menu > li > a {*/
/*cursor: pointer;*/
/*}*/

View File

@ -25,9 +25,11 @@
</div>
<div class="pull-left " style="padding-left: 150px; padding-top:15px">
<a class="btn btn-default" style="margin: 20px" target="_blank" href="resource/logs/{{war._id}}/clean.log">Logfile
anzeigen</a>
<form class="form-group">
<a class="btn btn-default" style="margin: 20px" target="_blank" onclick="window.open(this.href, 'logfileWindow',
'left=20,top=20,width=1380,height=600,toolbar=1,resizable=0'); return false;"
href="resource/logs/{{war._id}}/clean.log">
Logfile anzeigen</a>
<form *ngIf="staticTabs.tabs[0].active" class="form-group">
<label class="radio-inline">
<input type="radio" name="fractSelect"
[checked]="(fractionRadioSelect == undefined) ? 'true' : 'false'"
@ -94,10 +96,43 @@
<ng-template tabHeading>
<img src="../../../assets/fraction-btn.png"> Fraktionen
</ng-template>
<div class="fade-in chart-container">
<!--<div class="btn-group" style="position: absolute; margin-left: 5%;" dropdown>-->
<!--<button dropdownToggle type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split">-->
<!--{{dataMode}} <span class="caret"></span>-->
<!--</button>-->
<!--<ul *dropdownMenu class="dropdown-menu" role="menu">-->
<!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(0, 'Summe')">Summe</a></li>-->
<!--<li class="divider dropdown-divider"></li>-->
<!--<li class="disabled" role="menuitem">-->
<!--<a class="dropdown-item" style="cursor: default!important;">Interval:</a>-->
<!--</li>-->
<!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(1, '1 Minute')">1 Minute</a></li>-->
<!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(5, '5 Minuten')">5 Minuten</a></li>-->
<!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(10, '10 Minuten')">10 Minuten</a>-->
<!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(20, '20 Minuten')">20 Minuten</a>-->
<!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(40, '40 Minuten')">40 Minuten</a>-->
<!--</li>-->
<!--</ul>-->
<!--</div>-->
<div class="chart-select-group btn-group" (click)="selectChart()">
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel" btnRadio="{{labelPoints}}">{{labelPoints}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel" btnRadio="{{labelBudget}}">{{labelBudget}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel" btnRadio="{{labelKill}}">{{labelKill}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel" btnRadio="{{labelFriendlyFire}}">{{labelFriendlyFire}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel" btnRadio="{{labelRevive}}">{{labelRevive}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel"
btnRadio="{{labelStabilize}}">{{labelStabilize}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel"
btnRadio="{{labelTransport}}">{{labelTransport}}</label>
<label class="btn btn-default btn-dark" [(ngModel)]="chartSelectModel" btnRadio="{{labelFlag}}">{{labelFlag}}</label>
</div>
<div *ngIf="showLineChart" class="chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="pointData"
[results]="lineChartData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
@ -105,118 +140,17 @@
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelPoints"
[yAxisLabel]="lineChartLabel"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="budgetData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
[legend]="legend"
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelBudget"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="killData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
[legend]="legend"
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelKill"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="friendlyFireData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
[legend]="legend"
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelFriendlyFire"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="transportData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
[legend]="legend"
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelTransport"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="reviveData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
[legend]="legend"
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelRevive"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<ngx-charts-line-chart
[scheme]="colorScheme"
[results]="stabilizedData"
[gradient]="gradient"
[xAxis]="xAxis"
[yAxis]="yAxis"
[legend]="legend"
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelStabilize"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="roundDomains">
</ngx-charts-line-chart>
</div>
<div class="fade-in chart-container">
<div *ngIf="!showLineChart" class="chart-container">
<ngx-charts-area-chart
[scheme]="colorScheme"
[results]="flagData"
[results]="areaChartData"
[xAxis]="xAxis"
[yAxis]="yAxis"
[curve]="stepCurve"
@ -224,7 +158,7 @@
[legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelFlag"
[yAxisLabel]="labelFlag"
[autoScale]="autoscale"
[timeline]="timeline"
[roundDomains]="false">

View File

@ -1,3 +1,4 @@
///<reference path="../../utils/chart-utils.ts"/>
import {Component, ElementRef, ViewChild} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {WarService} from "../../services/logs/war.service";
@ -5,6 +6,7 @@ import {War} from "../../models/model-interfaces";
import {LogsService} from "../../services/logs/logs.service";
import {TabsetComponent} from "ngx-bootstrap";
import * as d3 from "d3";
import {ChartUtils} from "../../utils/chart-utils";
@Component({
@ -20,6 +22,8 @@ export class WarDetailComponent {
war: War = {players: []};
public chartSelectModel: string;
fractionRadioSelect: string;
playerChart: any[] = [];
@ -35,14 +39,8 @@ export class WarDetailComponent {
sortDescending: 'glyphicon glyphicon-triangle-bottom',
};
pointData: any[] = [];
budgetData: any[] = [];
killData: any[] = [];
friendlyFireData: any[] = [];
transportData: any[] = [];
reviveData: any[] = [];
stabilizedData: any[] = [];
flagData: any[] = [];
lineChartData: any[] = [];
areaChartData: any[] = [];
tmpPointData;
tmpBudgetData;
@ -53,19 +51,23 @@ export class WarDetailComponent {
tmpStabilizeData;
tmpFlagCaptureData;
initialized;
colorScheme = {
domain: ['#0000FF', '#B22222']
};
yAxisLabelPoints = 'Punkte';
yAxisLabelBudget = 'Budget';
yAxisLabelKill = 'Kills';
yAxisLabelFriendlyFire = 'FriendlyFire';
yAxisLabelTransport = 'Lufttransport';
yAxisLabelRevive = 'Revive';
yAxisLabelStabilize = 'Stabilisiert';
yAxisLabelFlag = 'Flaggenbesitz';
labelPoints = 'Punkte';
labelBudget = 'Budget';
labelKill = 'Kills';
labelFriendlyFire = 'FriendlyFire';
labelTransport = 'Lufttransport';
labelRevive = 'Revive';
labelStabilize = 'Stabilisiert';
labelFlag = 'Flaggenbesitz';
lineChartLabel: string = this.labelPoints;
showLineChart = true;
stepCurve = d3.curveStepAfter;
gradient = false;
yAxis = true;
@ -77,7 +79,12 @@ export class WarDetailComponent {
autoscale = true;
timeline = false;
roundDomains = true;
fractionChartsInitialized: boolean = false;
startDateObj;
dataMode: string = 'Summe';
dataInterval: number = 0;
logData;
constructor(private route: ActivatedRoute,
private router: Router,
@ -93,38 +100,24 @@ export class WarDetailComponent {
.subscribe(war => {
this.war = war;
this.rows = war.players;
this.playerChart = [
{
"name": "CSAT",
"value": war.playersOpfor
},
{
"name": "NATO",
"value": war.playersBlufor
}
];
this.tmpPointData = [
{
"name": "NATO",
"series": []
},
{
"name": "CSAT",
"series": []
}
];
this.tmpBudgetData = JSON.parse(JSON.stringify(this.tmpPointData));
this.tmpKillData = JSON.parse(JSON.stringify(this.tmpPointData));
this.tmpFrienlyFireData = JSON.parse(JSON.stringify(this.tmpPointData));
this.tmpTransportData = JSON.parse(JSON.stringify(this.tmpPointData));
this.tmpReviveData = JSON.parse(JSON.stringify(this.tmpPointData));
this.tmpStabilizeData = JSON.parse(JSON.stringify(this.tmpPointData));
this.tmpFlagCaptureData = JSON.parse(JSON.stringify(this.tmpPointData));
this.playerChart = ChartUtils.getSingleDataArray('CSAT', war.playersOpfor, 'NATO', war.playersBlufor);
Object.assign(this, [this.playerChart, this.pointData, this.budgetData, this.killData,
this.friendlyFireData, this.transportData, this.reviveData, this.stabilizedData, this.flagData]);
this.initialized = {
basic: false,
budget: false,
kill: false,
revive: false,
transport: false,
flag: false
};
Object.assign(this, [this.playerChart, this.lineChartData, this.areaChartData]);
this.chartSelectModel = this.labelPoints;
this.fractionChartsInitialized = false;
this.startDateObj = new Date(this.war.date);
this.startDateObj.setHours(0);
this.startDateObj.setMinutes(1);
this.fractionRadioSelect = undefined;
this.staticTabs.tabs[0].active = true;
this.scrollOverviewTop();
});
@ -140,6 +133,46 @@ export class WarDetailComponent {
}
}
selectChart() {
if (this.chartSelectModel !== this.labelFlag) {
this.showLineChart = true;
this.lineChartLabel = this.chartSelectModel;
switch (this.chartSelectModel) {
case this.labelPoints:
this.lineChartData = this.tmpPointData;
break;
case this.labelBudget:
this.initBudgetData();
this.lineChartData = this.tmpBudgetData;
break;
case this.labelKill:
this.initKillData();
this.lineChartData = this.tmpKillData;
break;
case this.labelFriendlyFire:
this.initKillData();
this.lineChartData = this.tmpFrienlyFireData;
break;
case this.labelRevive:
this.initRevive();
this.lineChartData = this.tmpReviveData;
break;
case this.labelStabilize:
this.initRevive();
this.lineChartData = this.tmpStabilizeData;
break;
case this.labelTransport:
this.initTransportData();
this.lineChartData = this.tmpTransportData;
break;
}
} else {
this.initFlagHoldData();
this.showLineChart = false;
this.areaChartData = this.tmpFlagCaptureData;
}
}
selectPlayerDetail(player) {
if (player && player.selected && player.selected.length > 0) {
this.router.navigate(['../../campaign-player/' + this.war.campaign + '/' + player.selected[0].name],
@ -154,222 +187,225 @@ export class WarDetailComponent {
}
}
toggleDataMode(interval, entryString) {
this.dataInterval = interval;
this.dataMode = entryString;
this.initTransportData();
this.lineChartData = this.tmpTransportData;
}
loadFractionData() {
if (!this.fractionChartsInitialized) {
const startDateObj = new Date(this.war.date);
startDateObj.setHours(0);
startDateObj.setMinutes(1);
if (this.initialized.basic) {
return;
}
this.logsService.getFullLog(this.war._id).subscribe((data) => {
// POINTS
data.points.forEach(pointEntry => {
const dateObj = new Date(this.war.date);
const time = pointEntry.time.split(':');
dateObj.setHours(time[0]);
dateObj.setMinutes(time[1]);
this.tmpPointData[0].series.push({
"name": new Date(pointEntry.time),
"value": pointEntry.ptBlufor
});
this.tmpPointData[1].series.push({
"name": new Date(pointEntry.time),
"value": pointEntry.ptOpfor
});
});
this.initializeTempCollections();
// BUDGET
this.tmpBudgetData[0].series.push({
"name": startDateObj,
"value": this.war.budgetBlufor
});
this.tmpBudgetData[1].series.push({
"name": startDateObj,
"value": this.war.budgetOpfor
});
// This adds an entry for both fractions on every event
for (let i = 0; i < data.budget.length; i++) {
const budgetEntry = data.budget[i];
const fractionChange = budgetEntry.fraction === 'BLUFOR' ? 0 : 1;
const fractionOld = budgetEntry.fraction !== 'BLUFOR' ? 0 : 1;
this.logsService.getFullLog(this.war._id).subscribe((data) => {
this.logData = data;
this.initPointData();
this.showLineChart = true;
this.lineChartLabel = this.labelPoints;
this.lineChartData = this.tmpPointData;
this.initialized.basic = true;
});
}
this.tmpBudgetData[fractionChange].series.push({
"name": new Date(budgetEntry.time),
"value": budgetEntry.newBudget
});
initPointData() {
this.logData.points.forEach(pointEntry => {
this.tmpPointData[0].series.push(ChartUtils.getSeriesEntry(new Date(pointEntry.time), pointEntry.ptBlufor));
this.tmpPointData[1].series.push(ChartUtils.getSeriesEntry(new Date(pointEntry.time), pointEntry.ptOpfor));
});
this.addFinalTimeData(this.tmpPointData);
}
this.tmpBudgetData[fractionOld].series.push({
"name": new Date(budgetEntry.time),
"value": this.tmpBudgetData[fractionOld].series[this.tmpBudgetData[fractionOld].series.length-1].value
});
initBudgetData() {
if (this.initialized.budget) {
return;
}
this.logData.budget.forEach(budgetEntry => {
const budgetEntryDate = new Date(budgetEntry.time);
const fractionChange = budgetEntry.fraction === 'BLUFOR' ? 0 : 1;
const fractionOld = budgetEntry.fraction !== 'BLUFOR' ? 0 : 1;
if (WarDetailComponent.isTwoMinutesAhead(budgetEntryDate, this.tmpBudgetData)) {
this.tmpBudgetData[fractionChange].series.push(ChartUtils.getSeriesEntry(new Date(budgetEntry.time), budgetEntry.newBudget));
this.tmpBudgetData[fractionOld].series.push(ChartUtils.getSeriesEntry(new Date(budgetEntry.time),
this.tmpBudgetData[fractionOld].series[this.tmpBudgetData[fractionOld].series.length - 1].value));
}
});
this.addFinalTimeData(this.tmpBudgetData);
this.initialized.budget = true;
}
initKillData() {
if (!this.initialized.kill) {
return;
}
let killCountBlufor = 0, killCountOpfor = 0, ffKillCountBlufor = 0, ffKillCountOpfor = 0;
for (const {killEntry, index} of this.logData.kill.map((killEntry, index) => ({killEntry, index}))) {
const killEntryDate = new Date(killEntry.time);
if (killEntry.friendlyFire === false) {
if (killEntry.fraction === 'BLUFOR') {
killCountBlufor++;
}
if (killEntry.fraction === 'OPFOR') {
killCountOpfor++;
}
if (WarDetailComponent.isTwoMinutesAhead(killEntryDate, this.tmpKillData)) {
this.tmpKillData[0].series.push(ChartUtils.getSeriesEntry(killEntryDate, killCountBlufor));
this.tmpKillData[1].series.push(ChartUtils.getSeriesEntry(killEntryDate, killCountOpfor));
}
} else {
if (killEntry.fraction === 'BLUFOR') {
ffKillCountBlufor++;
}
if (killEntry.fraction === 'OPFOR') {
ffKillCountOpfor++;
}
if (WarDetailComponent.isTwoMinutesAhead(killEntryDate, this.tmpFrienlyFireData)) {
this.tmpFrienlyFireData[0].series.push(ChartUtils.getSeriesEntry(killEntryDate, ffKillCountBlufor));
this.tmpFrienlyFireData[1].series.push(ChartUtils.getSeriesEntry(killEntryDate, ffKillCountOpfor));
}
}
if (index === this.logData.kill.length - 1) {
this.tmpKillData[0].series.push(ChartUtils.getSeriesEntry(killEntryDate, killCountBlufor));
this.tmpKillData[1].series.push(ChartUtils.getSeriesEntry(killEntryDate, killCountOpfor));
this.tmpFrienlyFireData[0].series.push(ChartUtils.getSeriesEntry(killEntryDate, ffKillCountBlufor));
this.tmpFrienlyFireData[1].series.push(ChartUtils.getSeriesEntry(killEntryDate, ffKillCountOpfor));
}
}
// KILLS
let killCountBlufor = 0;
let killCountOpfor = 0;
let ffKillCountBlufor = 0;
let ffKillCountOpfor = 0;
this.tmpKillData[0].series.push({
"name": startDateObj,
"value": killCountBlufor
});
this.tmpKillData[1].series.push({
"name": startDateObj,
"value": killCountOpfor
});
this.tmpFrienlyFireData[0].series.push({
"name": startDateObj,
"value": ffKillCountBlufor
});
this.tmpFrienlyFireData[1].series.push({
"name": startDateObj,
"value": ffKillCountOpfor
});
this.addFinalTimeData(this.tmpKillData);
this.addFinalTimeData(this.tmpFrienlyFireData)
this.initialized.kill = true;
}
data.kill.forEach(killEntry => {
if (killEntry.fraction === 'BLUFOR') {
if (killEntry.friendlyFire === false) {
killCountBlufor++;
} else {
ffKillCountBlufor++;
}
} else {
if (killEntry.friendlyFire === false) {
killCountOpfor++;
} else {
ffKillCountOpfor++;
}
}
this.tmpKillData[killEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
"name": new Date(killEntry.time),
"value": killEntry.fraction === 'BLUFOR' ? killCountBlufor : killCountOpfor
});
this.tmpFrienlyFireData[killEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
"name": new Date(killEntry.time),
"value": killEntry.fraction === 'BLUFOR' ? ffKillCountBlufor : ffKillCountOpfor
});
});
initRevive() {
if (this.initialized.revive) {
return;
}
let reviveCountBlufor = 0, reviveCountOpfor = 0, stabilizeCountBlufor = 0, stabilizeCountOpfor = 0;
for (const {reviveEntry, index} of this.logData.revive.map((reviveEntry, index) => ({reviveEntry, index}))) {
const reviveEntryDate = new Date(reviveEntry.time);
if (reviveEntry.stabilized === false) {
if (reviveEntry.fraction === 'BLUFOR') {
reviveCountBlufor++;
} else {
reviveCountOpfor++;
}
if (WarDetailComponent.isTwoMinutesAhead(reviveEntryDate, this.tmpReviveData)) {
this.tmpReviveData[0].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, reviveCountBlufor));
this.tmpReviveData[1].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, reviveCountOpfor));
}
} else {
if (reviveEntry.fraction === 'BLUFOR') {
stabilizeCountBlufor++;
} else {
stabilizeCountOpfor++;
}
if (WarDetailComponent.isTwoMinutesAhead(reviveEntryDate, this.tmpStabilizeData)) {
this.tmpStabilizeData[0].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, stabilizeCountBlufor));
this.tmpStabilizeData[1].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, stabilizeCountOpfor));
}
}
if (index === this.logData.revive.length - 1) {
this.tmpReviveData[0].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, reviveCountBlufor));
this.tmpReviveData[1].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, reviveCountOpfor));
this.tmpStabilizeData[0].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, stabilizeCountBlufor));
this.tmpStabilizeData[1].series.push(ChartUtils.getSeriesEntry(reviveEntryDate, stabilizeCountOpfor));
}
}
this.addFinalTimeData(this.tmpReviveData);
this.addFinalTimeData(this.tmpStabilizeData);
this.initialized.revive = true;
}
// TRANSPORT
let transportCountBlufor = 0;
let transportCountOpfor = 0;
this.tmpTransportData[0].series.push({
"name": startDateObj,
"value": transportCountBlufor
});
this.tmpTransportData[1].series.push({
"name": startDateObj,
"value": transportCountOpfor
});
initTransportData() {
if (this.initialized.transport) {
return;
}
let transportCountBlufor = 0, transportCountOpfor = 0;
for (const {transportEntry, index} of this.logData.transport.map((transportEntry, index) => ({
transportEntry,
index
}))) {
const transportEntryDate = new Date(transportEntry.time);
if (transportEntry.fraction === 'BLUFOR') {
transportCountBlufor++;
} else {
transportCountOpfor++;
}
if (WarDetailComponent.isTwoMinutesAhead(transportEntryDate, this.tmpTransportData) || index === this.logData.transport.length - 1) {
this.tmpTransportData[0].series.push(ChartUtils.getSeriesEntry(transportEntryDate, transportCountBlufor));
this.tmpTransportData[1].series.push(ChartUtils.getSeriesEntry(transportEntryDate, transportCountOpfor));
}
}
this.addFinalTimeData(this.tmpTransportData);
this.initialized.transport = true;
data.transport.forEach(transportEntry => {
if (transportEntry.fraction === 'BLUFOR') {
transportCountBlufor++;
} else {
transportCountOpfor++;
}
this.tmpTransportData[transportEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
"name": new Date(transportEntry.time),
"value": transportEntry.fraction === 'BLUFOR' ? transportCountBlufor : transportCountOpfor
});
});
}
// REVIVE & STABILIZE
let reviveCountBlufor = 0;
let reviveCountOpfor = 0;
let stabilizeCountBlufor = 0;
let stabilizeCountOpfor = 0;
this.tmpReviveData[0].series.push({
"name": startDateObj,
"value": reviveCountBlufor
});
this.tmpReviveData[1].series.push({
"name": startDateObj,
"value": reviveCountOpfor
});
this.tmpStabilizeData[0].series.push({
"name": startDateObj,
"value": stabilizeCountBlufor
});
this.tmpStabilizeData[1].series.push({
"name": startDateObj,
"value": stabilizeCountOpfor
});
data.revive.forEach(reviveEntry => {
if (reviveEntry.fraction === 'BLUFOR') {
if (reviveEntry.stabilized === false) {
reviveCountBlufor++;
} else {
stabilizeCountBlufor++;
}
} else {
if (reviveEntry.stabilized === false) {
reviveCountOpfor++;
} else {
stabilizeCountOpfor++;
}
}
this.tmpReviveData[reviveEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
"name": new Date(reviveEntry.time),
"value": reviveEntry.fraction === 'BLUFOR' ? reviveCountBlufor : reviveCountOpfor
});
this.tmpStabilizeData[reviveEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
"name": new Date(reviveEntry.time),
"value": reviveEntry.fraction === 'BLUFOR' ? stabilizeCountBlufor : stabilizeCountOpfor
});
});
initFlagHoldData() {
if (this.initialized.flag) {
return;
}
let flagStatusBlufor = true;
let flagStatusOpfor = true;
this.tmpFlagCaptureData[0].series.push(ChartUtils.getSeriesEntry(this.startDateObj, flagStatusBlufor));
this.tmpFlagCaptureData[1].series.push(ChartUtils.getSeriesEntry(this.startDateObj, flagStatusOpfor));
// FLAG
let flagStatusBlufor = true;
let flagStatusOpfor = true;
this.tmpFlagCaptureData[0].series.push({
"name": startDateObj,
"value": flagStatusBlufor
});
this.tmpFlagCaptureData[1].series.push({
"name": startDateObj,
"value": flagStatusOpfor
});
this.logData.flag.forEach(flagEntry => {
if (flagEntry.flagFraction === 'BLUFOR') {
flagStatusBlufor = !flagEntry.capture;
} else {
flagStatusOpfor = !flagEntry.capture;
}
this.tmpFlagCaptureData[flagEntry.flagFraction === 'BLUFOR' ? 0 : 1].series.push(
ChartUtils.getSeriesEntry(new Date(flagEntry.time), flagEntry.flagFraction === 'BLUFOR' ? flagStatusBlufor : flagStatusOpfor)
)
});
data.flag.forEach(flagEntry => {
if (flagEntry.flagFraction === 'BLUFOR') {
flagStatusBlufor = !flagEntry.capture
} else {
flagStatusOpfor = !flagEntry.capture;
}
this.tmpFlagCaptureData[flagEntry.flagFraction === 'BLUFOR' ? 0 : 1].series.push({
"name": new Date(flagEntry.time),
"value": flagEntry.flagFraction === 'BLUFOR' ? flagStatusBlufor : flagStatusOpfor
});
});
this.addFinalTimeData(this.tmpFlagCaptureData);
this.initialized.flag = true;
}
this.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate));
private static isTwoMinutesAhead(entryDate: Date, tmpData: any): boolean {
return entryDate.getTime() >= tmpData[0].series[tmpData[0].series.length - 1].name.getTime() + (1.5 * 60000)
}
this.fractionChartsInitialized = true;
});
initializeTempCollections() {
this.tmpPointData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpBudgetData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpKillData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpFrienlyFireData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpTransportData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpReviveData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpStabilizeData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpFlagCaptureData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
[this.tmpKillData, this.tmpFrienlyFireData, this.tmpReviveData, this.tmpStabilizeData, this.tmpTransportData].forEach(tmp => {
[0, 1].forEach(index => {
tmp[index].series.push(ChartUtils.getSeriesEntry(this.startDateObj, 0));
})
});
this.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(this.startDateObj, this.war.budgetBlufor));
this.tmpBudgetData[1].series.push(ChartUtils.getSeriesEntry(this.startDateObj, this.war.budgetOpfor));
}
addFinalTimeData(tmpCollection) {
const endDate = new Date(this.war.endDate);
if (tmpCollection === this.tmpBudgetData) {
this.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(endDate, this.war.endBudgetBlufor));
this.tmpBudgetData[1].series.push(ChartUtils.getSeriesEntry(endDate, this.war.endBudgetOpfor));
} else {
for (let j in [0, 1]) {
if (tmpCollection[j].series[tmpCollection[j].series.length - 1].name < endDate) {
tmpCollection[j].series.push(ChartUtils.getSeriesEntry(endDate, tmpCollection[j].series[tmpCollection[j].series.length - 1].value));
}
}
}
}
addFinalTimeDataEntriesAndPopulate(endDate) {
[this.tmpPointData, this.tmpBudgetData, this.tmpTransportData, this.tmpReviveData, this.tmpStabilizeData,
this.tmpKillData, this.tmpFrienlyFireData, this.tmpFlagCaptureData].forEach(tmp => {
for (let j in [0, 1]) {
if (tmp[j].series[tmp[j].series.length - 1].name < endDate) {
tmp[j].series.push({
'name': endDate,
'value': tmp[j].series[tmp[j].series.length - 1].value
}
)
}
}
});
this.pointData = this.tmpPointData;
this.budgetData = this.tmpBudgetData;
this.transportData = this.tmpTransportData;
this.reviveData = this.tmpReviveData;
this.stabilizedData = this.tmpStabilizeData;
this.killData = this.tmpKillData;
this.friendlyFireData = this.tmpFrienlyFireData;
this.flagData = this.tmpFlagCaptureData;
}
}

View File

@ -6,4 +6,32 @@ export class ChartUtils {
return (dayDate < 10 ? "0" + dayDate : dayDate) + '.'
+ isoDate.slice(5, 7) + '.' + isoDate.slice(2, 4);
}
public static getSeriesEntry(name, value) {
return {
"name": name,
"value": value
};
}
public static getMultiDataArray(...args: string[]) : any[] {
const obj = [];
for (let i = 0, arg; arg = args[i]; i++) {
obj.push({
"name": arg,
"series": []
})
}
return obj;
}
public static getSingleDataArray(name1, value1, name2, value2): any[] {
return [{
"name": name1,
"value": value1
}, {
"name": name2,
"value": value2
}];
}
}