Add player count for log parsing

pull/51/head
HardiReady 2019-02-09 11:54:16 +01:00
parent 712071865f
commit 2538f1838a
4 changed files with 82 additions and 20 deletions

View File

@ -0,0 +1,34 @@
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const LogPlayerCountSchema = new Schema({
war: {
type: mongoose.Schema.Types.ObjectId,
ref: 'War',
required: true,
},
time: {
type: Date,
required: true,
},
countBlufor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
required: true,
},
countOpfor: {
type: Number,
get: (v) => Math.round(v),
set: (v) => Math.round(v),
required: true,
},
}, {
collection: 'logPlayerCount',
});
// optional more indices
LogPlayerCountSchema.index({war: 1});
module.exports = mongoose.model('LogPlayerCount', LogPlayerCountSchema);

View File

@ -15,6 +15,7 @@ const LogVehicleModel = require('../models/logs/vehicle');
const LogTransportModel = require('../models/logs/transport');
const LogFlagModel = require('../models/logs/flag');
const LogPointsModel = require('../models/logs/points');
const LogPlayerCountModel = require('../models/logs/player-count');
const logsRouter = new express.Router();
@ -45,6 +46,7 @@ logsRouter.route('/:warId')
const vehicleObjects = LogVehicleModel.find(filter, {}, sort);
const transportObjects = LogTransportModel.find(filter, {}, sort);
const flagObjects = LogFlagModel.find(filter, {}, sort);
const playerCountObjects = LogPlayerCountModel.find(filter, {}, sort);
const resources = {
points: pointsObjects.exec.bind(pointsObjects),
budget: budgetObjects.exec.bind(budgetObjects),
@ -54,6 +56,7 @@ logsRouter.route('/:warId')
vehicle: killObjects.exec.bind(vehicleObjects),
transport: transportObjects.exec.bind(transportObjects),
flag: flagObjects.exec.bind(flagObjects),
playerCount: playerCountObjects.exec.bind(playerCountObjects),
};
async.parallel(resources, (error, results) => {

View File

@ -33,6 +33,7 @@ const LogTransportModel = require('../models/logs/transport');
const LogFlagModel = require('../models/logs/flag');
const LogBudgetModel = require('../models/logs/budget');
const LogPointsModel = require('../models/logs/points');
const LogPlayerCountModel = require('../models/logs/player-count');
// util
const genericPatch = require('./_generic').genericPatch;
@ -76,6 +77,8 @@ wars.route('/')
if (err) {
return next(err);
}
console.log(statsResult.playerCount)
LogKillModel.create(statsResult.kills, () => {
LogVehicleKillModel.create(statsResult.vehicles, () => {
LogRespawnModel.create(statsResult.respawn, () => {
@ -83,6 +86,7 @@ wars.route('/')
LogFlagModel.create(statsResult.flag, () => {
LogBudgetModel.create(statsResult.budget, () => {
LogTransportModel.create(statsResult.transport, () => {
LogPlayerCountModel.create(statsResult.playerCount, () => {
LogPointsModel.create(statsResult.points, () => {
const folderName = resourceLocation.concat(war._id);
mkdirp(folderName, (err) => {
@ -117,6 +121,7 @@ wars.route('/')
});
});
});
});
} else {
const err = new Error('no Logfile provided');
err.status = codes.wrongmediasend;

View File

@ -23,6 +23,12 @@ const vehicleRegex = /(vehicle:\s(.*?)\))/;
const categoryRegex = /(category:\s(.*?)\))/;
const bluforPlayerCountRegex = /NATO\s(\d*)/;
const opforPlayerCountRegex = /CSAT\s(\d*)/;
const timestampRegex= /LOG:\s(\d*:\d*:\d*)\s---/;
const parseWarLog = (lineArray, war) => {
let flagBlufor = true;
let flagOpfor = true;
@ -41,6 +47,7 @@ const parseWarLog = (lineArray, war) => {
flag: [],
transport: [],
players: [],
playerCount: [],
};
const VEHICLE_BLACKLIST = [
@ -245,6 +252,19 @@ const parseWarLog = (lineArray, war) => {
fraction: driver ? driver.fraction : 'NONE',
distance: distance,
});
} else if (line.includes('(Spieleranzahl)')) {
stats.clean.push(line);
const timestamp = (timestampRegex.exec(line))[1];
const countBlufor = (bluforPlayerCountRegex.exec(line))[1];
const countOpfor = (opforPlayerCountRegex.exec(line))[1];
stats.playerCount.push({
war: war.id,
time: getFullTimeDate(war.date, timestamp),
countBlufor: countBlufor,
countOpfor: countOpfor,
});
} else if (line.includes('(Fraktionsuebersicht)') || line.includes('Fraktionsübersicht')) {
/**
* PLAYERS