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,6 +93,8 @@ wars.route('/')
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
LogKillModel.create(statsResult.kills, function () {
|
LogKillModel.create(statsResult.kills, function () {
|
||||||
|
LogVehicleKillModel.create(statsResult.vehicles, function () {
|
||||||
|
|
||||||
LogRespawnModel.create(statsResult.respawn, function () {
|
LogRespawnModel.create(statsResult.respawn, function () {
|
||||||
LogReviveModel.create(statsResult.revive, function () {
|
LogReviveModel.create(statsResult.revive, function () {
|
||||||
LogFlagModel.create(statsResult.flag, function () {
|
LogFlagModel.create(statsResult.flag, function () {
|
||||||
|
@ -129,6 +132,7 @@ wars.route('/')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,6 +13,7 @@ const parseWarLog = (lineArray, war) => {
|
||||||
budget: [],
|
budget: [],
|
||||||
points: [],
|
points: [],
|
||||||
kills: [],
|
kills: [],
|
||||||
|
vehicles: [],
|
||||||
respawn: [],
|
respawn: [],
|
||||||
revive: [],
|
revive: [],
|
||||||
flag: [],
|
flag: [],
|
||||||
|
@ -40,13 +41,26 @@ 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);
|
|
||||||
|
|
||||||
|
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({
|
stats.kills.push({
|
||||||
war: war._id,
|
war: war._id,
|
||||||
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
|
||||||
|
@ -56,6 +70,7 @@ const parseWarLog = (lineArray, war) => {
|
||||||
fraction: shooter ? shooter.fraction : 'NONE'
|
fraction: shooter ? shooter.fraction : 'NONE'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BUDGET
|
* BUDGET
|
||||||
|
@ -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