diff --git a/server/apib/data_structures/_log.apib b/server/apib/data_structures/_log.apib index 535e4e4..852adc6 100644 --- a/server/apib/data_structures/_log.apib +++ b/server/apib/data_structures/_log.apib @@ -3,7 +3,6 @@ + _id: `` (string, required) - log entry id + war: `` (string, required) - warId + time: `` (string, required) - logging timestamp -+ __v: 0 (number, required) - object version number # LogPoints (Log) ## Properties @@ -74,14 +73,14 @@ #LogVehicle (Log) ## Properties + shooter: `HardiReady` (string, required) - name of player who shot the vehicle -+ additionalShooter: [`[GNC]Paolo`, `Dominik`] (array[string], required) - additional crew members of shooter vehicle ++ additionalShooter: `[GNC]Paolo`, `Dominik` (array[string], required) - additional crew members of shooter vehicle + target: `T-100` (string, required) - name of the vehicle + fraction: `BLUFOR` (enum, required) - fraction of the shooter + Members + `BLUFOR` + `OPFOR` + `NONE` -+ vehicleClass: `LIGHT` (enum, required) - class of shot vehicle ++ vehicleClass: `LIGHT` (enum[string], required) - class of shot vehicle + Members + `LIGHT` + `HEAVY` diff --git a/server/models/logs/budget.js b/server/models/logs/budget.js index 328e449..896b163 100644 --- a/server/models/logs/budget.js +++ b/server/models/logs/budget.js @@ -3,37 +3,49 @@ const mongoose = require('mongoose'); const Schema = mongoose.Schema; -const LogBudgetSchema = new Schema({ - war: { - type: mongoose.Schema.Types.ObjectId, - ref: 'War', - required: true, +const LogBudgetSchema = new Schema( + { + war: { + type: mongoose.Schema.Types.ObjectId, + ref: 'War', + required: true, + }, + time: { + type: Date, + required: true, + }, + fraction: { + type: String, + enum: ['BLUFOR', 'OPFOR'], + required: true, + }, + oldBudget: { + type: Number, + get: (v) => Math.round(v), + set: (v) => Math.round(v), + required: true, + }, + newBudget: { + type: Number, + get: (v) => Math.round(v), + set: (v) => Math.round(v), + required: true, + }, + buy: { + type: Boolean, + required: true, + }, + player: { + type: String, + }, + item: { + type: String, + } }, - time: { - type: Date, - required: true, - }, - fraction: { - type: String, - enum: ['BLUFOR', 'OPFOR'], - required: true, - }, - oldBudget: { - type: Number, - get: (v) => Math.round(v), - set: (v) => Math.round(v), - required: true, - }, - newBudget: { - type: Number, - get: (v) => Math.round(v), - set: (v) => Math.round(v), - required: true, - }, -}, { - collection: 'logBudget', - versionKey: false, -}); + { + collection: 'logBudget', + versionKey: false, + }); // optional more indices LogBudgetSchema.index({war: 1}); diff --git a/server/tools/log-parse-tool.js b/server/tools/log-parse-tool.js index 4f60397..98fba36 100644 --- a/server/tools/log-parse-tool.js +++ b/server/tools/log-parse-tool.js @@ -13,6 +13,12 @@ const VehicleClasses = Object.freeze({ const playerNameRegex = /(^|,\s)(.*?)\s\(/g; +const budgetPlayerNameRegex = /\d*\.\s(.*)\s\(ver\)kaufte/; + +const budgetItemNameRegex = /\(ver\)kaufte\s(.*)\"$/; + +const budgetRespawnNameRegex = /Respawn\svon\s(.*)\"$/; + const vehicleNameEndRegex = /\s\(\w+:/; const sideRegex = /(side:\s(.*?)\))/; @@ -178,7 +184,7 @@ const parseWarLog = (lineArray, war) => { const playerName = line.substring(line.lastIndexOf('Respawn von ') + 12, line.lastIndexOf('"')); stats.respawn.push(getRespawnEntry(budg, playerName, war._id, war.date)); } - stats.budget.push(getBudgetEntry(budg, war._id, war.date)); + stats.budget.push(getBudgetEntry(line, budg, war._id, war.date)); } } else if (line.includes('(Fahne)') && !line.includes('Dominator')) { /** @@ -405,14 +411,37 @@ const getPointsEntry = (pt, line, warId, warDate) => { }; }; -const getBudgetEntry = (budg, warId, warDate) => { - return { +const getBudgetEntry = (line, budg, warId, warDate) => { + const timestamp = getFullTimeDate(warDate, budg[5]); + const oldBudget = transformMoneyString(budg[9]); + const newBudget = transformMoneyString(budg[12]); + const fraction = budg[7] === 'NATO' ? 'BLUFOR' : 'OPFOR'; + + const budgetEntry = { war: warId, - time: getFullTimeDate(warDate, budg[5]), - fraction: budg[7] === 'NATO' ? 'BLUFOR' : 'OPFOR', - oldBudget: transformMoneyString(budg[9]), - newBudget: transformMoneyString(budg[12]), + time: timestamp, + fraction: fraction, + oldBudget: oldBudget, + newBudget: newBudget, + buy: oldBudget <= newBudget, }; + + const budgetRespawnMatch = budgetRespawnNameRegex.exec(line); + if (budgetRespawnMatch && budgetRespawnMatch.length > 1) { + budgetEntry.player = budgetRespawnMatch[1]; + budgetEntry.item = "Respawn"; + } else { + const itemNameMatch = budgetItemNameRegex.exec(line); + const playerNameMatch = budgetPlayerNameRegex.exec(line); + if (playerNameMatch && playerNameMatch.length > 1) { + budgetEntry.player = playerNameMatch[1]; + } + if (itemNameMatch && itemNameMatch.length > 1) { + budgetEntry.item = itemNameMatch[1]; + } + } + + return budgetEntry; }; const getPlayerInfoFromString = (inputString) => {