create player list & kill log parse

pull/15/head
Florian Hartwich 2017-10-21 11:32:25 +02:00
parent db48cd8ef6
commit 2d9167b172
2 changed files with 53 additions and 46 deletions

View File

@ -1,6 +1,6 @@
"use strict";
const arrayContains = require('../middleware/util').arrayContains;
const arrayContains = require('./util').arrayContains;
const parseWarLog = (lineArray, war) => {
const clean = [];
@ -11,21 +11,34 @@ const parseWarLog = (lineArray, war) => {
const revive = [];
const flag = [];
const transport = [];
const playerNames = [];
const addPlayerIfNotExists = (playerName) => {
if (playerName !== 'Error: No unit' && !arrayContains(playerNames, playerName)) {
playerNames.push(playerName);
const players = [];
const addPlayersIfNotExists = (inputPlayers) => {
inputPlayers.forEach(player => {
if (player && player.name !== 'Error: No unit' && !arrayContains(players, player)) {
player['warId'] = 'asd78zr3h8szfd7';
players.push(player);
}
})
};
lineArray.forEach(line => {
if (line.includes("Abschuss")) {
if (line.includes("Abschuss") && !line.includes('Fahrzeug')) {
clean.push(line);
// const kill = line.split(" ");
// for (let i=0; i< kill.length; i++ ) {
// console.log(i + " +++ " + kill[i]);
// }
const shooterString = line.substring(line.lastIndexOf(" von: ") + 6, line.lastIndexOf(". :OPT LOG END"));
const shooter = getPlayerAndFractionFromString(shooterString);
const targetString = line.substring(line.lastIndexOf(" || ") + 4, line.lastIndexOf(' von:'));
const target = getPlayerAndFractionFromString(targetString);
kills.push({
warId: 'asdfaew34tg',
time: getDateTime(line.split(" ")[5]),
shooter: shooter ? shooter.name : null,
target: target ? target.name : null,
friendlyFire: target && shooter ? target.fraction === shooter.fraction : false
});
addPlayersIfNotExists([shooter, target]);
}
if (line.includes("Budget")) {
@ -55,7 +68,6 @@ const parseWarLog = (lineArray, war) => {
flagFraction: flagFraction,
capture: capture
});
addPlayerIfNotExists(playerName);
}
if (line.includes("Punkte")) {
@ -74,66 +86,51 @@ const parseWarLog = (lineArray, war) => {
clean.push(line);
const resp = line.split(" ");
const playerName = line.substring(line.lastIndexOf("Spieler:") + 9, line.lastIndexOf("-") - 1);
respawn.push(getRespawnEntry(resp, playerName));
addPlayerIfNotExists(playerName);
}
if (line.includes("Revive")) {
clean.push(line);
const stabilized = !!line.includes('stabilisiert');
const medicName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
const medicNameArray = medicName.split(" ");
const medicFraction = medicNameArray[medicNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const sanitizedMedicName = medicName.substring(0, medicName.indexOf(medicNameArray[medicNameArray.length - 1]) - 1);
const medic = getPlayerAndFractionFromString(medicName);
const patientName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
const patientNameArray = patientName.split(" ");
const patientFraction = patientNameArray[patientNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const sanitizedPatientName = patientName.substring(0, patientName.indexOf(patientNameArray[patientNameArray.length - 1]) - 1);
const patient = getPlayerAndFractionFromString(patientName);
revive.push({
warId: 'asfddf',
time: getDateTime(line.split(" ")[5]),
stabilized: stabilized,
medic: sanitizedMedicName,
patient: sanitizedPatientName
medic: medic.name,
patient: patientName
});
addPlayerIfNotExists(sanitizedMedicName);
addPlayerIfNotExists(sanitizedPatientName);
addPlayersIfNotExists([medic, patient]);
}
if (line.includes("Transport ||")) {
clean.push(line);
const driverName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(" eingeflogen"));
const driverNameArray = driverName.split(" ");
const driverFraction = driverNameArray[driverNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const sanitizedDriverName = driverName.substring(0, driverName.indexOf(driverNameArray[driverNameArray.length - 1]) - 1);
const passengerName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
const passengerNameArray = passengerName.split(" ");
const passengerFraction = passengerNameArray[passengerNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const sanitizedPassengerName = passengerName.substring(0, passengerName.indexOf(passengerNameArray[passengerNameArray.length - 1]) - 1);
const driverString = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(" eingeflogen"));
const driver = getPlayerAndFractionFromString(driverString);
const passengerString = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
const passenger = getPlayerAndFractionFromString(passengerString);
const distance = parseInt(line.substring(line.lastIndexOf("eingeflogen (") + 13, line.lastIndexOf("m)") - 1));
transport.push({
war: "blablub7z8",
time: getDateTime(line.split(" ")[5]),
driver: sanitizedDriverName,
passenger: sanitizedPassengerName,
driver: driver.name,
passenger: passenger.name,
distance: distance
});
addPlayerIfNotExists(sanitizedDriverName);
addPlayerIfNotExists(sanitizedPassengerName);
addPlayersIfNotExists([driver, passenger]);
}
});
//
// revive.forEach(budg => console.log(budg));
// console.log(revive.length)
players.forEach(player => console.log(player))
console.log(players.length)
};
function getRespawnEntry(respawn, playerName) {
@ -163,6 +160,16 @@ function getBudgetEntry(budg) {
}
}
function getPlayerAndFractionFromString(nameAndFractionString) {
const nameArray = nameAndFractionString.split(" ");
const fraction = nameArray[nameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
// do not return player for "Selbstverschulden"
if (name) {
return {name: name, fraction: fraction};
}
}
const transformMoneyString = (budgetString) => {
if (!budgetString.includes("e+")) {
return parseInt(budgetString);

View File

@ -11,11 +11,11 @@ const sortCollectionBy = (collection, key) => {
return collection;
};
const arrayContains = (arr, user) => {
const playerArrayContains = (arr, item) => {
let i = 0, count = arr.length, matchFound = false;
for(; i < count; i++) {
if (arr[i] === user) {
if (arr[i].name === item.name && arr[i].fraction === item.fraction) {
matchFound = true;
break;
}
@ -25,4 +25,4 @@ const arrayContains = (arr, user) => {
};
exports.sortCollection = sortCollectionBy;
exports.arrayContains = arrayContains;
exports.arrayContains = playerArrayContains;