Use min interval for fraction stats

pull/17/head
HardiReady 2017-11-03 21:31:03 +01:00
parent 8f34d44139
commit 4ea1239a75
2 changed files with 157 additions and 114 deletions

View File

@ -97,23 +97,24 @@
<img src="../../../assets/fraction-btn.png"> Fraktionen <img src="../../../assets/fraction-btn.png"> Fraktionen
</ng-template> </ng-template>
<div class="btn-group" style="position: absolute; margin-left: 5%;" dropdown> <!--<div class="btn-group" style="position: absolute; margin-left: 5%;" dropdown>-->
<button dropdownToggle type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split"> <!--<button dropdownToggle type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split">-->
{{dataMode}} <span class="caret"></span> <!--{{dataMode}} <span class="caret"></span>-->
</button> <!--</button>-->
<ul *dropdownMenu class="dropdown-menu" role="menu"> <!--<ul *dropdownMenu class="dropdown-menu" role="menu">-->
<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(0, 'Summe')">Summe</a></li> <!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(0, 'Summe')">Summe</a></li>-->
<li class="divider dropdown-divider"></li> <!--<li class="divider dropdown-divider"></li>-->
<li class="disabled" role="menuitem"> <!--<li class="disabled" role="menuitem">-->
<a class="dropdown-item" style="cursor: default!important;">Interval:</a> <!--<a class="dropdown-item" style="cursor: default!important;">Interval:</a>-->
</li> <!--</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(1, '1 Minute')">1 Minute</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(5, '5 Minuten')">5 Minuten</a></li>-->
<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(20, '20 Minuten')">20 Minuten</a> <!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(10, '10 Minuten')">10 Minuten</a>-->
<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(40, '40 Minuten')">40 Minuten</a> <!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(20, '20 Minuten')">20 Minuten</a>-->
</li> <!--<li role="menuitem"><a class="dropdown-item" (click)="toggleDataMode(40, '40 Minuten')">40 Minuten</a>-->
</ul> <!--</li>-->
</div> <!--</ul>-->
<!--</div>-->
<div class="chart-select-group btn-group" (click)="selectChart()"> <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="{{labelPoints}}">{{labelPoints}}</label>

View File

@ -79,7 +79,11 @@ export class WarDetailComponent {
roundDomains = true; roundDomains = true;
fractionChartsInitialized: boolean = false; fractionChartsInitialized: boolean = false;
startDateObj;
dataMode: string = 'Summe'; dataMode: string = 'Summe';
dataInterval: number = 0;
logData;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private router: Router, private router: Router,
@ -101,6 +105,10 @@ export class WarDetailComponent {
Object.assign(this, [this.playerChart, this.lineChartData, this.areaChartData]); Object.assign(this, [this.playerChart, this.lineChartData, this.areaChartData]);
this.chartSelectModel = this.labelPoints; this.chartSelectModel = this.labelPoints;
this.startDateObj = new Date(this.war.date);
this.startDateObj.setHours(0);
this.startDateObj.setMinutes(1);
this.fractionRadioSelect = undefined; this.fractionRadioSelect = undefined;
this.staticTabs.tabs[0].active = true; this.staticTabs.tabs[0].active = true;
this.scrollOverviewTop(); this.scrollOverviewTop();
@ -165,7 +173,10 @@ export class WarDetailComponent {
} }
toggleDataMode(interval, entryString) { toggleDataMode(interval, entryString) {
this.dataInterval = interval;
this.dataMode = entryString; this.dataMode = entryString;
this.initTransportData();
this.lineChartData = this.tmpTransportData;
} }
loadFractionData() { loadFractionData() {
@ -182,115 +193,26 @@ export class WarDetailComponent {
this.tmpStabilizeData = ChartUtils.getMultiDataArray('NATO', 'CSAT'); this.tmpStabilizeData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
this.tmpFlagCaptureData = ChartUtils.getMultiDataArray('NATO', 'CSAT'); this.tmpFlagCaptureData = ChartUtils.getMultiDataArray('NATO', 'CSAT');
const newFractionGraphEntry = (entry: any, val1: any, val2: any) => {
return ChartUtils.getSeriesEntry(new Date(entry.time), entry.fraction === 'BLUFOR' ? val1 : val2);
};
const startDateObj = new Date(this.war.date);
startDateObj.setHours(0);
startDateObj.setMinutes(1);
[this.tmpKillData, this.tmpFrienlyFireData, this.tmpReviveData, this.tmpStabilizeData, this.tmpTransportData].forEach(tmp => { [this.tmpKillData, this.tmpFrienlyFireData, this.tmpReviveData, this.tmpStabilizeData, this.tmpTransportData].forEach(tmp => {
[0, 1].forEach(index => { [0, 1].forEach(index => {
tmp[index].series.push(ChartUtils.getSeriesEntry(startDateObj, 0)); tmp[index].series.push(ChartUtils.getSeriesEntry(this.startDateObj, 0));
}) })
}); });
let killCountBlufor = 0, killCountOpfor = 0, ffKillCountBlufor = 0, ffKillCountOpfor = 0, reviveCountBlufor = 0,
reviveCountOpfor = 0, stabilizeCountBlufor = 0, stabilizeCountOpfor = 0, transportCountBlufor = 0,
transportCountOpfor = 0;
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.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));
});
// BUDGET this.initPointData();
this.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(startDateObj, this.war.budgetBlufor)); this.initBudgetData();
this.tmpBudgetData[1].series.push(ChartUtils.getSeriesEntry(startDateObj, 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.tmpBudgetData[fractionChange].series.push(ChartUtils.getSeriesEntry(new Date(budgetEntry.time), budgetEntry.newBudget)); this.initKillData();
this.tmpBudgetData[fractionOld].series.push(ChartUtils.getSeriesEntry(new Date(budgetEntry.time),
this.tmpBudgetData[fractionOld].series[this.tmpBudgetData[fractionOld].series.length - 1].value));
}
// KILLS & FRIENDLY FIRE this.initRevive();
data.kill.forEach(killEntry => {
if (killEntry.friendlyFire === false) {
if (killEntry.fraction === 'BLUFOR') {
killCountBlufor++;
} else {
killCountOpfor++;
}
this.tmpKillData[0].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), killCountBlufor));
this.tmpKillData[1].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), killCountOpfor));
} else {
if (killEntry.fraction === 'BLUFOR') {
ffKillCountBlufor++;
} else {
ffKillCountOpfor++;
}
this.tmpFrienlyFireData[0].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), ffKillCountBlufor));
this.tmpFrienlyFireData[1].series.push(ChartUtils.getSeriesEntry(new Date(killEntry.time), ffKillCountOpfor));
}
});
// REVIVE & STABILIZE this.initTransportData();
data.revive.forEach(reviveEntry => {
if (reviveEntry.stabilized === false) {
if (reviveEntry.fraction === 'BLUFOR') {
reviveCountBlufor++;
} else {
reviveCountOpfor++;
}
this.tmpReviveData[0].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), reviveCountBlufor));
this.tmpReviveData[1].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), reviveCountOpfor));
} else {
if (reviveEntry.fraction === 'BLUFOR') {
stabilizeCountBlufor++;
} else {
stabilizeCountOpfor++;
}
this.tmpStabilizeData[0].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), stabilizeCountBlufor));
this.tmpStabilizeData[1].series.push(ChartUtils.getSeriesEntry(new Date(reviveEntry.time), stabilizeCountOpfor));
}
});
// TRANSPORT this.initFlagHoldData();
data.transport.forEach(transportEntry => {
if (transportEntry.fraction === 'BLUFOR') {
transportCountBlufor++;
} else {
transportCountOpfor++;
}
this.tmpTransportData[0].series.push(ChartUtils.getSeriesEntry(new Date(transportEntry.time), transportCountBlufor));
this.tmpTransportData[1].series.push(ChartUtils.getSeriesEntry(new Date(transportEntry.time), transportCountOpfor));
});
// FLAG
let flagStatusBlufor = true;
let flagStatusOpfor = true;
this.tmpFlagCaptureData[0].series.push(ChartUtils.getSeriesEntry(startDateObj, flagStatusBlufor));
this.tmpFlagCaptureData[1].series.push(ChartUtils.getSeriesEntry(startDateObj, 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(
newFractionGraphEntry(flagEntry, flagStatusBlufor, flagStatusOpfor)
);
});
this.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate)); this.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate));
@ -298,6 +220,126 @@ export class WarDetailComponent {
}); });
} }
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));
});
}
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];
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)) {
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];
if (killEntry.friendlyFire === false) {
if (killEntry.fraction === 'BLUFOR') {
killCountBlufor++;
} else {
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));
}
} else {
if (killEntry.fraction === 'BLUFOR') {
ffKillCountBlufor++;
} else {
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));
}
}
}
}
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];
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));
}
} else {
if (reviveEntry.fraction === 'BLUFOR') {
stabilizeCountBlufor++;
} 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));
}
}
}
}
initTransportData() {
let transportCountBlufor = 0, transportCountOpfor = 0;
for (let i = 0; i < this.logData.transport.length; i++) {
const transportEntry = this.logData.transport[i];
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));
}
}
}
initFlagHoldData() {
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));
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.fraction === 'BLUFOR' ? flagStatusBlufor : flagStatusOpfor)
)
});
}
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
}
addFinalTimeDataEntriesAndPopulate(endDate) { addFinalTimeDataEntriesAndPopulate(endDate) {
[this.tmpPointData, this.tmpBudgetData, this.tmpTransportData, this.tmpReviveData, this.tmpStabilizeData, [this.tmpPointData, this.tmpBudgetData, this.tmpTransportData, this.tmpReviveData, this.tmpStabilizeData,
this.tmpKillData, this.tmpFrienlyFireData, this.tmpFlagCaptureData].forEach(tmp => { this.tmpKillData, this.tmpFrienlyFireData, this.tmpFlagCaptureData].forEach(tmp => {