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); return next(err);
} }
// delete players having this war ID as foreign key // delete linked appearances
PlayerModel.find({warId: item._id}).remove().exec(); 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 // check if logfiles exist and delete from fs
const warDir = __dirname + '/../resource/logs/' + req.params.id; 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['endBudgetOpfor'] = transformMoneyString(budg[14]);
stats.war.endDate = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T0' + budg[5]); stats.war.endDate = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T0' + budg[5]);
} else if (line.includes('Startbudget')) { } 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['budgetBlufor'] = transformMoneyString(budg[11]);
stats.war['budgetOpfor'] = transformMoneyString(budg[14]); 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 { } else {
stats.budget.push(getBudgetEntry(budg, war._id, war.date)); stats.budget.push(getBudgetEntry(budg, war._id, war.date));
} }
@ -103,6 +104,7 @@ const parseWarLog = (lineArray, war) => {
if (line.includes('Endpunktestand')) { if (line.includes('Endpunktestand')) {
stats.war['ptBlufor'] = parseInt(pt[11]); stats.war['ptBlufor'] = parseInt(pt[11]);
stats.war['ptOpfor'] = parseInt(pt[14].slice(0, -1)); stats.war['ptOpfor'] = parseInt(pt[14].slice(0, -1));
// EXIT LOOP
return true; return true;
} else { } else {
stats.points.push(getPointsEntry(pt, line, war._id, war.date)) stats.points.push(getPointsEntry(pt, line, war._id, war.date))

View File

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

View File

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

View File

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

View File

@ -42,19 +42,10 @@
color: blue; color: blue;
} }
.chart-container {
width: 90%;
margin: 2%;
min-width: 900px;
height: 400px;
padding: 15px;
float: left;
}
/* ########### TABS ########### */ /* ########### TABS ########### */
:host /deep/ .nav-tabs { :host /deep/ .nav-tabs {
padding-left: 35%!important; padding-left: 35% !important;
} }
:host /deep/ .nav-link { :host /deep/ .nav-link {
@ -63,11 +54,11 @@
} }
:host /deep/ .nav-link:hover { :host /deep/ .nav-link:hover {
background: #286090; background: #afafaf;
color: #000; color: #000;
} }
:host /deep/ .nav-tabs>li.active>a{ :host /deep/ .nav-tabs > li.active > a {
background: #222222; background: #222222;
color: white; color: white;
} }
@ -107,3 +98,40 @@
background-color: #f7f7f7; 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>
<div class="pull-left " style="padding-left: 150px; padding-top:15px"> <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 <a class="btn btn-default" style="margin: 20px" target="_blank" onclick="window.open(this.href, 'logfileWindow',
anzeigen</a> 'left=20,top=20,width=1380,height=600,toolbar=1,resizable=0'); return false;"
<form class="form-group"> href="resource/logs/{{war._id}}/clean.log">
Logfile anzeigen</a>
<form *ngIf="staticTabs.tabs[0].active" class="form-group">
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" name="fractSelect" <input type="radio" name="fractSelect"
[checked]="(fractionRadioSelect == undefined) ? 'true' : 'false'" [checked]="(fractionRadioSelect == undefined) ? 'true' : 'false'"
@ -94,10 +96,43 @@
<ng-template tabHeading> <ng-template tabHeading>
<img src="../../../assets/fraction-btn.png"> Fraktionen <img src="../../../assets/fraction-btn.png"> Fraktionen
</ng-template> </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 <ngx-charts-line-chart
[scheme]="colorScheme" [scheme]="colorScheme"
[results]="pointData" [results]="lineChartData"
[gradient]="gradient" [gradient]="gradient"
[xAxis]="xAxis" [xAxis]="xAxis"
[yAxis]="yAxis" [yAxis]="yAxis"
@ -105,118 +140,17 @@
[legendTitle]="legendTitle" [legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel" [showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel" [showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelPoints" [yAxisLabel]="lineChartLabel"
[autoScale]="autoscale" [autoScale]="autoscale"
[timeline]="timeline" [timeline]="timeline"
[roundDomains]="roundDomains"> [roundDomains]="roundDomains">
</ngx-charts-line-chart> </ngx-charts-line-chart>
</div> </div>
<div class="fade-in chart-container">
<ngx-charts-line-chart <div *ngIf="!showLineChart" class="chart-container">
[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">
<ngx-charts-area-chart <ngx-charts-area-chart
[scheme]="colorScheme" [scheme]="colorScheme"
[results]="flagData" [results]="areaChartData"
[xAxis]="xAxis" [xAxis]="xAxis"
[yAxis]="yAxis" [yAxis]="yAxis"
[curve]="stepCurve" [curve]="stepCurve"
@ -224,7 +158,7 @@
[legendTitle]="legendTitle" [legendTitle]="legendTitle"
[showXAxisLabel]="showXAxisLabel" [showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel" [showYAxisLabel]="showYAxisLabel"
[yAxisLabel]="yAxisLabelFlag" [yAxisLabel]="labelFlag"
[autoScale]="autoscale" [autoScale]="autoscale"
[timeline]="timeline" [timeline]="timeline"
[roundDomains]="false"> [roundDomains]="false">

View File

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

View File

@ -6,4 +6,32 @@ export class ChartUtils {
return (dayDate < 10 ? "0" + dayDate : dayDate) + '.' return (dayDate < 10 ? "0" + dayDate : dayDate) + '.'
+ isoDate.slice(5, 7) + '.' + isoDate.slice(2, 4); + 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
}];
}
} }