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

View File

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