Modify parsing and models to catch vehicle kills
parent
237926fdf6
commit
d18986cb1f
|
@ -0,0 +1,34 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
const Schema = mongoose.Schema;
|
||||||
|
|
||||||
|
const LogVehicleKillSchema = new Schema({
|
||||||
|
war: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: 'War',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
time: {
|
||||||
|
type: Date,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
shooter: {
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
target: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
fraction: {
|
||||||
|
type: String,
|
||||||
|
enum: ['BLUFOR', 'OPFOR', 'NONE'],
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
collection: 'logVehicle'
|
||||||
|
});
|
||||||
|
// optional more indices
|
||||||
|
LogVehicleKillSchema.index({war: 1, shooter: 1, target: 1});
|
||||||
|
|
||||||
|
module.exports = mongoose.model('LogVehicle', LogVehicleKillSchema);
|
|
@ -24,6 +24,12 @@ const PlayerSchema = new Schema({
|
||||||
set: v => Math.round(v),
|
set: v => Math.round(v),
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
vehicle: {
|
||||||
|
type: Number,
|
||||||
|
get: v => Math.round(v),
|
||||||
|
set: v => Math.round(v),
|
||||||
|
required: true
|
||||||
|
},
|
||||||
death: {
|
death: {
|
||||||
type: Number,
|
type: Number,
|
||||||
get: v => Math.round(v),
|
get: v => Math.round(v),
|
||||||
|
|
|
@ -27,6 +27,7 @@ const CampaignModel = require('../models/campaign');
|
||||||
const WarModel = require('../models/war');
|
const WarModel = require('../models/war');
|
||||||
const PlayerModel = require('../models/player');
|
const PlayerModel = require('../models/player');
|
||||||
const LogKillModel = require('../models/logs/kill');
|
const LogKillModel = require('../models/logs/kill');
|
||||||
|
const LogVehicleKillModel = require('../models/logs/vehicle');
|
||||||
const LogRespawnModel = require('../models/logs/respawn');
|
const LogRespawnModel = require('../models/logs/respawn');
|
||||||
const LogReviveModel = require('../models/logs/revive');
|
const LogReviveModel = require('../models/logs/revive');
|
||||||
const LogTransportModel = require('../models/logs/transport');
|
const LogTransportModel = require('../models/logs/transport');
|
||||||
|
@ -92,33 +93,36 @@ wars.route('/')
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
LogKillModel.create(statsResult.kills, function () {
|
LogKillModel.create(statsResult.kills, function () {
|
||||||
LogRespawnModel.create(statsResult.respawn, function () {
|
LogVehicleKillModel.create(statsResult.vehicles, function () {
|
||||||
LogReviveModel.create(statsResult.revive, function () {
|
|
||||||
LogFlagModel.create(statsResult.flag, function () {
|
|
||||||
LogBudgetModel.create(statsResult.budget, function () {
|
|
||||||
LogTransportModel.create(statsResult.transport, function () {
|
|
||||||
LogPointsModel.create(statsResult.points, function () {
|
|
||||||
const folderName = __dirname + '/../resource/logs/' + war._id;
|
|
||||||
mkdirp(folderName, function (err) {
|
|
||||||
if (err) return next(err);
|
|
||||||
|
|
||||||
// save clean log file
|
LogRespawnModel.create(statsResult.respawn, function () {
|
||||||
const cleanFile = fs.createWriteStream(folderName + '/clean.log');
|
LogReviveModel.create(statsResult.revive, function () {
|
||||||
statsResult.clean.forEach(cleanLine => {
|
LogFlagModel.create(statsResult.flag, function () {
|
||||||
cleanFile.write(cleanLine + '\n\n')
|
LogBudgetModel.create(statsResult.budget, function () {
|
||||||
});
|
LogTransportModel.create(statsResult.transport, function () {
|
||||||
cleanFile.end();
|
LogPointsModel.create(statsResult.points, function () {
|
||||||
|
const folderName = __dirname + '/../resource/logs/' + war._id;
|
||||||
|
mkdirp(folderName, function (err) {
|
||||||
|
if (err) return next(err);
|
||||||
|
|
||||||
// save raw log file
|
// save clean log file
|
||||||
const rawFile = fs.createWriteStream(folderName + '/war.log');
|
const cleanFile = fs.createWriteStream(folderName + '/clean.log');
|
||||||
lineArray.forEach(rawLine => {
|
statsResult.clean.forEach(cleanLine => {
|
||||||
rawFile.write(rawLine + '\n')
|
cleanFile.write(cleanLine + '\n\n')
|
||||||
});
|
});
|
||||||
rawFile.end();
|
cleanFile.end();
|
||||||
|
|
||||||
res.status(codes.created);
|
// save raw log file
|
||||||
res.locals.items = war;
|
const rawFile = fs.createWriteStream(folderName + '/war.log');
|
||||||
next();
|
lineArray.forEach(rawLine => {
|
||||||
|
rawFile.write(rawLine + '\n')
|
||||||
|
});
|
||||||
|
rawFile.end();
|
||||||
|
|
||||||
|
res.status(codes.created);
|
||||||
|
res.locals.items = war;
|
||||||
|
next();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,6 +13,7 @@ const parseWarLog = (lineArray, war) => {
|
||||||
budget: [],
|
budget: [],
|
||||||
points: [],
|
points: [],
|
||||||
kills: [],
|
kills: [],
|
||||||
|
vehicles: [],
|
||||||
respawn: [],
|
respawn: [],
|
||||||
revive: [],
|
revive: [],
|
||||||
flag: [],
|
flag: [],
|
||||||
|
@ -40,21 +41,35 @@ const parseWarLog = (lineArray, war) => {
|
||||||
/**
|
/**
|
||||||
* KILLS
|
* KILLS
|
||||||
*/
|
*/
|
||||||
if (line.includes('(Abschuss)') && !line.includes('Fahrzeug')) {
|
if (line.includes('(Abschuss)')) {
|
||||||
stats.clean.push(line);
|
stats.clean.push(line);
|
||||||
|
|
||||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
||||||
const shooter = getPlayerAndFractionFromString(shooterString);
|
const shooter = getPlayerAndFractionFromString(shooterString);
|
||||||
const targetString = line.substring(line.lastIndexOf(' --- ') + 5, line.lastIndexOf(' von:'));
|
const targetString = line.substring(line.lastIndexOf(' --- ') + 5, line.lastIndexOf(' von:'));
|
||||||
const target = getPlayerAndFractionFromString(targetString);
|
|
||||||
|
|
||||||
stats.kills.push({
|
if (line.includes('Fahrzeug')) {
|
||||||
war: war._id,
|
const target = getVehicleAndFractionFromString(targetString);
|
||||||
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
if (target && shooter && target.fraction !== shooter.fraction) {
|
||||||
shooter: shooter ? shooter.name : null,
|
stats.vehicles.push({
|
||||||
target: target ? target.name : null,
|
war: war._id,
|
||||||
friendlyFire: shooter ? target.fraction === shooter.fraction : false,
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
||||||
fraction: shooter ? shooter.fraction : 'NONE'
|
shooter: shooter ? shooter.name : null,
|
||||||
});
|
target: target ? target.name : null,
|
||||||
|
fraction: shooter ? shooter.fraction : 'NONE'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const target = getPlayerAndFractionFromString(targetString);
|
||||||
|
stats.kills.push({
|
||||||
|
war: war._id,
|
||||||
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
||||||
|
shooter: shooter ? shooter.name : null,
|
||||||
|
target: target ? target.name : null,
|
||||||
|
friendlyFire: shooter ? target.fraction === shooter.fraction : false,
|
||||||
|
fraction: shooter ? shooter.fraction : 'NONE'
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,6 +196,7 @@ const parseWarLog = (lineArray, war) => {
|
||||||
const playerName = stats.players[i].name;
|
const playerName = stats.players[i].name;
|
||||||
stats.players[i]['respawn'] = stats.respawn.filter(res => res.player === playerName).length;
|
stats.players[i]['respawn'] = stats.respawn.filter(res => res.player === playerName).length;
|
||||||
stats.players[i]['kill'] = stats.kills.filter(kill => kill.shooter === playerName && !kill.friendlyFire).length;
|
stats.players[i]['kill'] = stats.kills.filter(kill => kill.shooter === playerName && !kill.friendlyFire).length;
|
||||||
|
stats.players[i]['vehicle'] = stats.vehicles.filter(vehicle => vehicle.shooter === playerName).length;
|
||||||
stats.players[i]['friendlyFire'] = stats.kills.filter(kill => kill.shooter === playerName && kill.friendlyFire).length;
|
stats.players[i]['friendlyFire'] = stats.kills.filter(kill => kill.shooter === playerName && kill.friendlyFire).length;
|
||||||
stats.players[i]['death'] = stats.kills.filter(kill => kill.target === playerName).length;
|
stats.players[i]['death'] = stats.kills.filter(kill => kill.target === playerName).length;
|
||||||
stats.players[i]['revive'] = stats.revive.filter(rev => rev.medic === playerName && !rev.stabilized).length;
|
stats.players[i]['revive'] = stats.revive.filter(rev => rev.medic === playerName && !rev.stabilized).length;
|
||||||
|
@ -233,6 +249,21 @@ const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getVehicleAndFractionFromString = (nameAndFractionString) => {
|
||||||
|
const nameArray = nameAndFractionString.trim().split(WHITESPACE);
|
||||||
|
const fractionPart = nameArray[nameArray.length - 1];
|
||||||
|
|
||||||
|
// escape it is some parachute fraction identifier
|
||||||
|
if (fractionPart === 'OPF_F' || fractionPart === 'BLU_F') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fraction = fractionPart === '(OPT_NATO)' || fractionPart === '(OPT_NATO_T)' ? 'BLUFOR' : 'OPFOR';
|
||||||
|
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(fractionPart) - 1);
|
||||||
|
|
||||||
|
return {name: name, fraction: fraction};
|
||||||
|
};
|
||||||
|
|
||||||
const transformMoneyString = (budgetString) => {
|
const transformMoneyString = (budgetString) => {
|
||||||
if (!budgetString.includes('e+')) {
|
if (!budgetString.includes('e+')) {
|
||||||
return parseInt(budgetString);
|
return parseInt(budgetString);
|
||||||
|
|
Loading…
Reference in New Issue