wrap duplicated code and try to improve readability
parent
c27b14b0a5
commit
54d2c257a7
|
@ -67,9 +67,10 @@ const parseWarLog = (lineArray, war) => {
|
|||
stats.war['endBudgetOpfor'] = transformMoneyString(budg[14]);
|
||||
stats.war.endDate = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T0' + budg[5]);
|
||||
} 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['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 {
|
||||
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
|
||||
}
|
||||
|
@ -103,6 +104,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
if (line.includes('Endpunktestand')) {
|
||||
stats.war['ptBlufor'] = parseInt(pt[11]);
|
||||
stats.war['ptOpfor'] = parseInt(pt[14].slice(0, -1));
|
||||
// EXIT LOOP
|
||||
return true;
|
||||
} else {
|
||||
stats.points.push(getPointsEntry(pt, line, war._id, war.date))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "opt-cc",
|
||||
"version": "1.6.1",
|
||||
"version": "1.6.2",
|
||||
"license": "MIT",
|
||||
"author": "Florian Hartwich <hardi@noarch.de>",
|
||||
"private": true,
|
||||
|
|
|
@ -155,18 +155,34 @@ export class WarDetailComponent {
|
|||
}
|
||||
|
||||
loadFractionData() {
|
||||
if (!this.fractionChartsInitialized) {
|
||||
if (this.fractionChartsInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newGraphEntry = (entry: any, val1: any, val2: any) => {
|
||||
return {"name": new Date(entry.time), "value": 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 => {
|
||||
[0, 1].forEach(index => {
|
||||
tmp[index].series.push({
|
||||
"name": startDateObj,
|
||||
"value": 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) => {
|
||||
// POINTS
|
||||
data.points.forEach(pointEntry => {
|
||||
const dateObj = new Date(this.war.date);
|
||||
const time = pointEntry.time.split(':');
|
||||
dateObj.setHours(time[0]);
|
||||
dateObj.setMinutes(time[1]);
|
||||
this.tmpPointData[0].series.push({
|
||||
"name": new Date(pointEntry.time),
|
||||
"value": pointEntry.ptBlufor
|
||||
|
@ -203,28 +219,7 @@ export class WarDetailComponent {
|
|||
});
|
||||
}
|
||||
|
||||
// KILLS
|
||||
let killCountBlufor = 0;
|
||||
let killCountOpfor = 0;
|
||||
let ffKillCountBlufor = 0;
|
||||
let 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
|
||||
});
|
||||
|
||||
// KILLS & FRIENDLY FIRE
|
||||
data.kill.forEach(killEntry => {
|
||||
if (killEntry.fraction === 'BLUFOR') {
|
||||
if (killEntry.friendlyFire === false) {
|
||||
|
@ -239,61 +234,15 @@ export class WarDetailComponent {
|
|||
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
|
||||
let transportCountBlufor = 0;
|
||||
let transportCountOpfor = 0;
|
||||
this.tmpTransportData[0].series.push({
|
||||
"name": startDateObj,
|
||||
"value": transportCountBlufor
|
||||
});
|
||||
this.tmpTransportData[1].series.push({
|
||||
"name": startDateObj,
|
||||
"value": transportCountOpfor
|
||||
});
|
||||
|
||||
data.transport.forEach(transportEntry => {
|
||||
if (transportEntry.fraction === 'BLUFOR') {
|
||||
transportCountBlufor++;
|
||||
} else {
|
||||
transportCountOpfor++;
|
||||
}
|
||||
this.tmpTransportData[transportEntry.fraction === 'BLUFOR' ? 0 : 1].series.push({
|
||||
"name": new Date(transportEntry.time),
|
||||
"value": transportEntry.fraction === 'BLUFOR' ? transportCountBlufor : transportCountOpfor
|
||||
});
|
||||
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
|
||||
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) {
|
||||
|
@ -308,14 +257,21 @@ export class WarDetailComponent {
|
|||
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
|
||||
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
|
||||
data.transport.forEach(transportEntry => {
|
||||
if (transportEntry.fraction === 'BLUFOR') {
|
||||
transportCountBlufor++;
|
||||
} else {
|
||||
transportCountOpfor++;
|
||||
}
|
||||
this.tmpTransportData[transportEntry.fraction === 'BLUFOR' ? 0 : 1].series.push(
|
||||
newGraphEntry(transportEntry, transportCountBlufor, transportCountOpfor));
|
||||
});
|
||||
|
||||
// FLAG
|
||||
|
@ -336,10 +292,9 @@ export class WarDetailComponent {
|
|||
} else {
|
||||
flagStatusOpfor = !flagEntry.capture;
|
||||
}
|
||||
this.tmpFlagCaptureData[flagEntry.flagFraction === 'BLUFOR' ? 0 : 1].series.push({
|
||||
"name": new Date(flagEntry.time),
|
||||
"value": flagEntry.flagFraction === 'BLUFOR' ? flagStatusBlufor : flagStatusOpfor
|
||||
});
|
||||
this.tmpFlagCaptureData[flagEntry.flagFraction === 'BLUFOR' ? 0 : 1].series.push(
|
||||
newGraphEntry(flagEntry, flagStatusBlufor, flagStatusOpfor)
|
||||
);
|
||||
});
|
||||
|
||||
this.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate));
|
||||
|
@ -347,7 +302,6 @@ export class WarDetailComponent {
|
|||
this.fractionChartsInitialized = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addFinalTimeDataEntriesAndPopulate(endDate) {
|
||||
[this.tmpPointData, this.tmpBudgetData, this.tmpTransportData, this.tmpReviveData, this.tmpStabilizeData,
|
||||
|
|
Loading…
Reference in New Issue