simplify graph data loops
parent
4ea1239a75
commit
e263ce050a
|
@ -26,7 +26,7 @@
|
|||
|
||||
<div class="pull-left " style="padding-left: 150px; padding-top:15px">
|
||||
<a class="btn btn-default" style="margin: 20px" target="_blank" onclick="window.open(this.href, 'logfileWindow',
|
||||
'left=20,top=20,width=1100,height=600,toolbar=1,resizable=0'); return false;"
|
||||
'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 class="form-group">
|
||||
|
@ -118,7 +118,6 @@
|
|||
|
||||
<div class="chart-select-group btn-group" (click)="selectChart()">
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel" btnRadio="{{labelPoints}}">{{labelPoints}}</label>
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel" btnRadio="{{labelFlag}}">{{labelFlag}}</label>
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel" btnRadio="{{labelBudget}}">{{labelBudget}}</label>
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel" btnRadio="{{labelKill}}">{{labelKill}}</label>
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel" btnRadio="{{labelFriendlyFire}}">{{labelFriendlyFire}}</label>
|
||||
|
@ -127,6 +126,7 @@
|
|||
btnRadio="{{labelStabilize}}">{{labelStabilize}}</label>
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel"
|
||||
btnRadio="{{labelTransport}}">{{labelTransport}}</label>
|
||||
<label class="btn btn-default" [(ngModel)]="chartSelectModel" btnRadio="{{labelFlag}}">{{labelFlag}}</label>
|
||||
</div>
|
||||
|
||||
<div *ngIf="showLineChart" class="chart-container">
|
||||
|
|
|
@ -63,7 +63,7 @@ export class WarDetailComponent {
|
|||
labelRevive = 'Revive';
|
||||
labelStabilize = 'Stabilisiert';
|
||||
labelFlag = 'Flaggenbesitz';
|
||||
lineChartLabel = this.labelPoints;
|
||||
lineChartLabel: string = this.labelPoints;
|
||||
|
||||
showLineChart = true;
|
||||
stepCurve = d3.curveStepAfter;
|
||||
|
@ -184,34 +184,16 @@ export class WarDetailComponent {
|
|||
return;
|
||||
}
|
||||
|
||||
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.initializeTempCollections();
|
||||
|
||||
this.logsService.getFullLog(this.war._id).subscribe((data) => {
|
||||
this.logData = data;
|
||||
|
||||
this.initPointData();
|
||||
this.initBudgetData();
|
||||
|
||||
this.initKillData();
|
||||
|
||||
this.initRevive();
|
||||
|
||||
|
||||
this.initTransportData();
|
||||
|
||||
this.initFlagHoldData();
|
||||
|
||||
this.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate));
|
||||
|
@ -228,65 +210,69 @@ export class WarDetailComponent {
|
|||
}
|
||||
|
||||
initBudgetData() {
|
||||
this.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(this.startDateObj, this.war.budgetBlufor));
|
||||
this.tmpBudgetData[1].series.push(ChartUtils.getSeriesEntry(this.startDateObj, this.war.budgetOpfor));
|
||||
// This adds an entry for both fractions on every event
|
||||
for (let i = 0; i < this.logData.budget.length; i++) {
|
||||
const budgetEntry = this.logData.budget[i];
|
||||
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(budgetEntry, this.tmpBudgetData, i, this.logData.budget.length)) {
|
||||
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.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(new Date(this.war.endDate), this.war.endBudgetBlufor));
|
||||
this.tmpBudgetData[1].series.push(ChartUtils.getSeriesEntry(new Date(this.war.endDate), this.war.endBudgetOpfor));
|
||||
});
|
||||
}
|
||||
|
||||
initKillData() {
|
||||
let killCountBlufor = 0, killCountOpfor = 0, ffKillCountBlufor = 0, ffKillCountOpfor = 0
|
||||
for (let i = 0; i < this.logData.kill.length; i++) {
|
||||
const killEntry = this.logData.kill[i];
|
||||
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++;
|
||||
} else {
|
||||
}
|
||||
if (killEntry.fraction === 'OPFOR') {
|
||||
killCountOpfor++;
|
||||
}
|
||||
if (WarDetailComponent.isTwoMinutesAhead(killEntry, this.tmpKillData, i, this.logData.kill.length)) {
|
||||
this.tmpKillData[0].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), killCountBlufor));
|
||||
this.tmpKillData[1].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), 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++;
|
||||
} else {
|
||||
}
|
||||
if (killEntry.fraction === 'OPFOR') {
|
||||
ffKillCountOpfor++;
|
||||
}
|
||||
if (WarDetailComponent.isTwoMinutesAhead(killEntry, this.tmpFrienlyFireData, i, this.logData.kill.length)) {
|
||||
this.tmpFrienlyFireData[0].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), ffKillCountBlufor));
|
||||
this.tmpFrienlyFireData[1].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initRevive() {
|
||||
let reviveCountBlufor = 0, reviveCountOpfor = 0, stabilizeCountBlufor = 0, stabilizeCountOpfor = 0;
|
||||
for (let i = 0; i < this.logData.revive.length; i++) {
|
||||
const reviveEntry = this.logData.revive[i];
|
||||
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(reviveEntry, this.tmpReviveData, i, this.logData.revive.length)) {
|
||||
this.tmpReviveData[0].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), reviveCountBlufor));
|
||||
this.tmpReviveData[1].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), 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') {
|
||||
|
@ -294,26 +280,35 @@ export class WarDetailComponent {
|
|||
} else {
|
||||
stabilizeCountOpfor++;
|
||||
}
|
||||
if (WarDetailComponent.isTwoMinutesAhead(reviveEntry, this.tmpStabilizeData, i, this.logData.revive.length)) {
|
||||
this.tmpStabilizeData[0].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), stabilizeCountBlufor));
|
||||
this.tmpStabilizeData[1].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initTransportData() {
|
||||
let transportCountBlufor = 0, transportCountOpfor = 0;
|
||||
for (let i = 0; i < this.logData.transport.length; i++) {
|
||||
const transportEntry = this.logData.transport[i];
|
||||
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(transportEntry, this.tmpTransportData, i, this.logData.transport.length)) {
|
||||
this.tmpTransportData[0].series.push(ChartUtils.getSeriesEntry(new Date(transportEntry.time), transportCountBlufor));
|
||||
this.tmpTransportData[1].series.push(ChartUtils.getSeriesEntry(new Date(transportEntry.time), 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -336,12 +331,31 @@ export class WarDetailComponent {
|
|||
});
|
||||
}
|
||||
|
||||
private static isTwoMinutesAhead(entry: any, tmpData: any, index: number, logDataLength: number): boolean {
|
||||
return new Date(entry.time).getTime() >= tmpData[0].series[tmpData[0].series.length - 1].name.getTime() + (1.5 * 60000) || index === logDataLength - 1
|
||||
private static isTwoMinutesAhead(entryDate: Date, tmpData: any): boolean {
|
||||
return entryDate.getTime() >= tmpData[0].series[tmpData[0].series.length - 1].name.getTime() + (1.5 * 60000)
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
addFinalTimeDataEntriesAndPopulate(endDate) {
|
||||
[this.tmpPointData, this.tmpBudgetData, this.tmpTransportData, this.tmpReviveData, this.tmpStabilizeData,
|
||||
[this.tmpPointData, 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) {
|
||||
|
@ -349,6 +363,8 @@ export class WarDetailComponent {
|
|||
}
|
||||
}
|
||||
});
|
||||
this.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(endDate, this.war.endBudgetBlufor));
|
||||
this.tmpBudgetData[1].series.push(ChartUtils.getSeriesEntry(endDate, this.war.endBudgetOpfor));
|
||||
|
||||
this.showLineChart = true;
|
||||
this.lineChartLabel = this.labelPoints;
|
||||
|
|
Loading…
Reference in New Issue