diff --git a/api/tools/log-parse-tool.js b/api/tools/log-parse-tool.js index ef07199..f780177 100644 --- a/api/tools/log-parse-tool.js +++ b/api/tools/log-parse-tool.js @@ -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)) diff --git a/package.json b/package.json index f4446c7..9d1d374 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opt-cc", - "version": "1.6.1", + "version": "1.6.2", "license": "MIT", "author": "Florian Hartwich ", "private": true, diff --git a/static/src/app/statistic/war-detail/war-detail.component.ts b/static/src/app/statistic/war-detail/war-detail.component.ts index 749496d..936f3a4 100644 --- a/static/src/app/statistic/war-detail/war-detail.component.ts +++ b/static/src/app/statistic/war-detail/war-detail.component.ts @@ -155,198 +155,152 @@ export class WarDetailComponent { } loadFractionData() { - if (!this.fractionChartsInitialized) { - const startDateObj = new Date(this.war.date); - startDateObj.setHours(0); - startDateObj.setMinutes(1); - - 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 - }); - this.tmpPointData[1].series.push({ - "name": new Date(pointEntry.time), - "value": 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 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 - }); - } - - // 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 - }); - - data.kill.forEach(killEntry => { - if (killEntry.fraction === 'BLUFOR') { - if (killEntry.friendlyFire === false) { - killCountBlufor++; - } else { - ffKillCountBlufor++; - } - } else { - if (killEntry.friendlyFire === false) { - killCountOpfor++; - } else { - 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 - }); - }); - - // 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) { - reviveCountBlufor++; - } else { - stabilizeCountBlufor++; - } - } else { - if (reviveEntry.stabilized === false) { - reviveCountOpfor++; - } else { - 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 - }); - }); - - // 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 - }); - - data.flag.forEach(flagEntry => { - if (flagEntry.flagFraction === 'BLUFOR') { - flagStatusBlufor = !flagEntry.capture - } 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.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate)); - - this.fractionChartsInitialized = true; - }); + 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 => { + 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 + }); + }); + + // BUDGET + this.tmpBudgetData[0].series.push({ + "name": startDateObj, + "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 + 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 + }); + } + + // KILLS & FRIENDLY FIRE + data.kill.forEach(killEntry => { + if (killEntry.fraction === 'BLUFOR') { + if (killEntry.friendlyFire === false) { + killCountBlufor++; + } else { + ffKillCountBlufor++; + } + } else { + if (killEntry.friendlyFire === false) { + killCountOpfor++; + } else { + 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) { + reviveCountBlufor++; + } else { + stabilizeCountBlufor++; + } + } else { + if (reviveEntry.stabilized === false) { + reviveCountOpfor++; + } else { + 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 + let flagStatusBlufor = true; + let flagStatusOpfor = true; + this.tmpFlagCaptureData[0].series.push({ + "name": startDateObj, + "value": flagStatusBlufor + }); + this.tmpFlagCaptureData[1].series.push({ + "name": startDateObj, + "value": 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( + newGraphEntry(flagEntry, flagStatusBlufor, flagStatusOpfor) + ); + }); + + this.addFinalTimeDataEntriesAndPopulate(new Date(this.war.endDate)); + + this.fractionChartsInitialized = true; + }); } addFinalTimeDataEntriesAndPopulate(endDate) {