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),
|
||||
required: true
|
||||
},
|
||||
vehicle: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
},
|
||||
death: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
|
|
|
@ -27,6 +27,7 @@ const CampaignModel = require('../models/campaign');
|
|||
const WarModel = require('../models/war');
|
||||
const PlayerModel = require('../models/player');
|
||||
const LogKillModel = require('../models/logs/kill');
|
||||
const LogVehicleKillModel = require('../models/logs/vehicle');
|
||||
const LogRespawnModel = require('../models/logs/respawn');
|
||||
const LogReviveModel = require('../models/logs/revive');
|
||||
const LogTransportModel = require('../models/logs/transport');
|
||||
|
@ -92,6 +93,8 @@ wars.route('/')
|
|||
return next(err);
|
||||
}
|
||||
LogKillModel.create(statsResult.kills, function () {
|
||||
LogVehicleKillModel.create(statsResult.vehicles, function () {
|
||||
|
||||
LogRespawnModel.create(statsResult.respawn, function () {
|
||||
LogReviveModel.create(statsResult.revive, function () {
|
||||
LogFlagModel.create(statsResult.flag, function () {
|
||||
|
@ -129,6 +132,7 @@ wars.route('/')
|
|||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
} else {
|
||||
|
|
|
@ -13,6 +13,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
budget: [],
|
||||
points: [],
|
||||
kills: [],
|
||||
vehicles: [],
|
||||
respawn: [],
|
||||
revive: [],
|
||||
flag: [],
|
||||
|
@ -40,13 +41,26 @@ const parseWarLog = (lineArray, war) => {
|
|||
/**
|
||||
* KILLS
|
||||
*/
|
||||
if (line.includes('(Abschuss)') && !line.includes('Fahrzeug')) {
|
||||
if (line.includes('(Abschuss)')) {
|
||||
stats.clean.push(line);
|
||||
|
||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
||||
const shooter = getPlayerAndFractionFromString(shooterString);
|
||||
const targetString = line.substring(line.lastIndexOf(' --- ') + 5, line.lastIndexOf(' von:'));
|
||||
const target = getPlayerAndFractionFromString(targetString);
|
||||
|
||||
if (line.includes('Fahrzeug')) {
|
||||
const target = getVehicleAndFractionFromString(targetString);
|
||||
if (target && shooter && target.fraction !== shooter.fraction) {
|
||||
stats.vehicles.push({
|
||||
war: war._id,
|
||||
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
||||
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]),
|
||||
|
@ -56,6 +70,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
fraction: shooter ? shooter.fraction : 'NONE'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BUDGET
|
||||
|
@ -181,6 +196,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
const playerName = stats.players[i].name;
|
||||
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]['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]['death'] = stats.kills.filter(kill => kill.target === playerName).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) => {
|
||||
if (!budgetString.includes('e+')) {
|
||||
return parseInt(budgetString);
|
||||
|
|
Loading…
Reference in New Issue