Add both fraction values for each entry

pull/17/head
HardiReady 2017-11-02 19:40:16 +01:00
parent 54d2c257a7
commit 2852445edf
2 changed files with 45 additions and 69 deletions

View File

@ -5,6 +5,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({
@ -159,8 +160,8 @@ export class WarDetailComponent {
return;
}
const newGraphEntry = (entry: any, val1: any, val2: any) => {
return {"name": new Date(entry.time), "value": entry.fraction === 'BLUFOR' ? val1 : val2};
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);
@ -169,10 +170,7 @@ export class WarDetailComponent {
[this.tmpKillData, this.tmpFrienlyFireData, this.tmpReviveData, this.tmpStabilizeData, this.tmpTransportData].forEach(tmp => {
[0, 1].forEach(index => {
tmp[index].series.push({
"name": startDateObj,
"value": 0
});
tmp[index].series.push(ChartUtils.getSeriesEntry(startDateObj, 0));
})
});
@ -183,84 +181,65 @@ export class WarDetailComponent {
this.logsService.getFullLog(this.war._id).subscribe((data) => {
// POINTS
data.points.forEach(pointEntry => {
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.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.tmpBudgetData[0].series.push({
"name": startDateObj,
"value": this.war.budgetBlufor
});
this.tmpBudgetData[1].series.push({
"name": startDateObj,
"value": this.war.budgetOpfor
});
this.tmpBudgetData[0].series.push(ChartUtils.getSeriesEntry(startDateObj, this.war.budgetBlufor));
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({
"name": new Date(budgetEntry.time),
"value": budgetEntry.newBudget
});
this.tmpBudgetData[fractionOld].series.push({
"name": new Date(budgetEntry.time),
"value": this.tmpBudgetData[fractionOld].series[this.tmpBudgetData[fractionOld].series.length - 1].value
});
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));
}
// KILLS & FRIENDLY FIRE
data.kill.forEach(killEntry => {
if (killEntry.fraction === 'BLUFOR') {
if (killEntry.friendlyFire === false) {
if (killEntry.fraction === 'BLUFOR') {
killCountBlufor++;
} else {
ffKillCountBlufor++;
}
} else {
if (killEntry.friendlyFire === false) {
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));
}
this.tmpKillData[killEntry.fraction === 'BLUFOR' ? 0 : 1].series.push(
newGraphEntry(killEntry, killCountBlufor, killCountOpfor)
);
this.tmpFrienlyFireData[killEntry.fraction === 'BLUFOR' ? 0 : 1].series.push(
newGraphEntry(killEntry, ffKillCountBlufor, ffKillCountOpfor)
)
});
// REVIVE & STABILIZE
data.revive.forEach(reviveEntry => {
if (reviveEntry.fraction === 'BLUFOR') {
if (reviveEntry.stabilized === false) {
if (reviveEntry.fraction === 'BLUFOR') {
reviveCountBlufor++;
} else {
stabilizeCountBlufor++;
}
} else {
if (reviveEntry.stabilized === false) {
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));
}
this.tmpReviveData[reviveEntry.fraction === 'BLUFOR' ? 0 : 1].series.push(
newGraphEntry(reviveEntry, reviveCountBlufor, reviveCountOpfor));
this.tmpStabilizeData[reviveEntry.fraction === 'BLUFOR' ? 0 : 1].series.push(
newGraphEntry(reviveEntry, stabilizeCountBlufor, stabilizeCountOpfor));
});
// TRANSPORT
@ -270,21 +249,15 @@ export class WarDetailComponent {
} else {
transportCountOpfor++;
}
this.tmpTransportData[transportEntry.fraction === 'BLUFOR' ? 0 : 1].series.push(
newGraphEntry(transportEntry, transportCountBlufor, 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({
"name": startDateObj,
"value": flagStatusBlufor
});
this.tmpFlagCaptureData[1].series.push({
"name": startDateObj,
"value": flagStatusOpfor
});
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') {
@ -293,7 +266,7 @@ export class WarDetailComponent {
flagStatusOpfor = !flagEntry.capture;
}
this.tmpFlagCaptureData[flagEntry.flagFraction === 'BLUFOR' ? 0 : 1].series.push(
newGraphEntry(flagEntry, flagStatusBlufor, flagStatusOpfor)
newFractionGraphEntry(flagEntry, flagStatusBlufor, flagStatusOpfor)
);
});
@ -308,11 +281,7 @@ export class WarDetailComponent {
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
}
)
tmp[j].series.push(ChartUtils.getSeriesEntry(endDate, tmp[j].series[tmp[j].series.length - 1].value));
}
}
});

View File

@ -6,4 +6,11 @@ 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
};
}
}