create player list & kill log parse
parent
db48cd8ef6
commit
2d9167b172
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const arrayContains = require('../middleware/util').arrayContains;
|
const arrayContains = require('./util').arrayContains;
|
||||||
|
|
||||||
const parseWarLog = (lineArray, war) => {
|
const parseWarLog = (lineArray, war) => {
|
||||||
const clean = [];
|
const clean = [];
|
||||||
|
@ -11,21 +11,34 @@ const parseWarLog = (lineArray, war) => {
|
||||||
const revive = [];
|
const revive = [];
|
||||||
const flag = [];
|
const flag = [];
|
||||||
const transport = [];
|
const transport = [];
|
||||||
const playerNames = [];
|
const players = [];
|
||||||
const addPlayerIfNotExists = (playerName) => {
|
const addPlayersIfNotExists = (inputPlayers) => {
|
||||||
if (playerName !== 'Error: No unit' && !arrayContains(playerNames, playerName)) {
|
inputPlayers.forEach(player => {
|
||||||
playerNames.push(playerName);
|
if (player && player.name !== 'Error: No unit' && !arrayContains(players, player)) {
|
||||||
|
player['warId'] = 'asd78zr3h8szfd7';
|
||||||
|
players.push(player);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
lineArray.forEach(line => {
|
lineArray.forEach(line => {
|
||||||
if (line.includes("Abschuss")) {
|
if (line.includes("Abschuss") && !line.includes('Fahrzeug')) {
|
||||||
clean.push(line);
|
clean.push(line);
|
||||||
// const kill = line.split(" ");
|
const shooterString = line.substring(line.lastIndexOf(" von: ") + 6, line.lastIndexOf(". :OPT LOG END"));
|
||||||
// for (let i=0; i< kill.length; i++ ) {
|
const shooter = getPlayerAndFractionFromString(shooterString);
|
||||||
// console.log(i + " +++ " + kill[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
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")) {
|
if (line.includes("Budget")) {
|
||||||
|
@ -55,7 +68,6 @@ const parseWarLog = (lineArray, war) => {
|
||||||
flagFraction: flagFraction,
|
flagFraction: flagFraction,
|
||||||
capture: capture
|
capture: capture
|
||||||
});
|
});
|
||||||
addPlayerIfNotExists(playerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes("Punkte")) {
|
if (line.includes("Punkte")) {
|
||||||
|
@ -74,66 +86,51 @@ const parseWarLog = (lineArray, war) => {
|
||||||
clean.push(line);
|
clean.push(line);
|
||||||
const resp = line.split(" ");
|
const resp = line.split(" ");
|
||||||
const playerName = line.substring(line.lastIndexOf("Spieler:") + 9, line.lastIndexOf("-") - 1);
|
const playerName = line.substring(line.lastIndexOf("Spieler:") + 9, line.lastIndexOf("-") - 1);
|
||||||
|
|
||||||
respawn.push(getRespawnEntry(resp, playerName));
|
respawn.push(getRespawnEntry(resp, playerName));
|
||||||
addPlayerIfNotExists(playerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes("Revive")) {
|
if (line.includes("Revive")) {
|
||||||
clean.push(line);
|
clean.push(line);
|
||||||
|
|
||||||
const stabilized = !!line.includes('stabilisiert');
|
const stabilized = !!line.includes('stabilisiert');
|
||||||
|
|
||||||
const medicName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
const medicName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
||||||
const medicNameArray = medicName.split(" ");
|
const medic = getPlayerAndFractionFromString(medicName);
|
||||||
const medicFraction = medicNameArray[medicNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
|
||||||
const sanitizedMedicName = medicName.substring(0, medicName.indexOf(medicNameArray[medicNameArray.length - 1]) - 1);
|
|
||||||
|
|
||||||
const patientName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
|
const patientName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
|
||||||
const patientNameArray = patientName.split(" ");
|
const patient = getPlayerAndFractionFromString(patientName);
|
||||||
const patientFraction = patientNameArray[patientNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
|
||||||
const sanitizedPatientName = patientName.substring(0, patientName.indexOf(patientNameArray[patientNameArray.length - 1]) - 1);
|
|
||||||
|
|
||||||
revive.push({
|
revive.push({
|
||||||
warId: 'asfddf',
|
warId: 'asfddf',
|
||||||
time: getDateTime(line.split(" ")[5]),
|
time: getDateTime(line.split(" ")[5]),
|
||||||
stabilized: stabilized,
|
stabilized: stabilized,
|
||||||
medic: sanitizedMedicName,
|
medic: medic.name,
|
||||||
patient: sanitizedPatientName
|
patient: patientName
|
||||||
});
|
});
|
||||||
|
|
||||||
addPlayerIfNotExists(sanitizedMedicName);
|
addPlayersIfNotExists([medic, patient]);
|
||||||
addPlayerIfNotExists(sanitizedPatientName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes("Transport ||")) {
|
if (line.includes("Transport ||")) {
|
||||||
clean.push(line);
|
clean.push(line);
|
||||||
const driverName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(" eingeflogen"));
|
const driverString = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(" eingeflogen"));
|
||||||
const driverNameArray = driverName.split(" ");
|
const driver = getPlayerAndFractionFromString(driverString);
|
||||||
const driverFraction = driverNameArray[driverNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
|
const passengerString = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
|
||||||
const sanitizedDriverName = driverName.substring(0, driverName.indexOf(driverNameArray[driverNameArray.length - 1]) - 1);
|
const passenger = getPlayerAndFractionFromString(passengerString);
|
||||||
|
|
||||||
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 distance = parseInt(line.substring(line.lastIndexOf("eingeflogen (") + 13, line.lastIndexOf("m)") - 1));
|
const distance = parseInt(line.substring(line.lastIndexOf("eingeflogen (") + 13, line.lastIndexOf("m)") - 1));
|
||||||
|
|
||||||
transport.push({
|
transport.push({
|
||||||
war: "blablub7z8",
|
war: "blablub7z8",
|
||||||
time: getDateTime(line.split(" ")[5]),
|
time: getDateTime(line.split(" ")[5]),
|
||||||
driver: sanitizedDriverName,
|
driver: driver.name,
|
||||||
passenger: sanitizedPassengerName,
|
passenger: passenger.name,
|
||||||
distance: distance
|
distance: distance
|
||||||
});
|
});
|
||||||
|
|
||||||
addPlayerIfNotExists(sanitizedDriverName);
|
addPlayersIfNotExists([driver, passenger]);
|
||||||
addPlayerIfNotExists(sanitizedPassengerName);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//
|
|
||||||
// revive.forEach(budg => console.log(budg));
|
players.forEach(player => console.log(player))
|
||||||
// console.log(revive.length)
|
console.log(players.length)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getRespawnEntry(respawn, playerName) {
|
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) => {
|
const transformMoneyString = (budgetString) => {
|
||||||
if (!budgetString.includes("e+")) {
|
if (!budgetString.includes("e+")) {
|
||||||
return parseInt(budgetString);
|
return parseInt(budgetString);
|
||||||
|
|
|
@ -11,11 +11,11 @@ const sortCollectionBy = (collection, key) => {
|
||||||
return collection;
|
return collection;
|
||||||
};
|
};
|
||||||
|
|
||||||
const arrayContains = (arr, user) => {
|
const playerArrayContains = (arr, item) => {
|
||||||
let i = 0, count = arr.length, matchFound = false;
|
let i = 0, count = arr.length, matchFound = false;
|
||||||
|
|
||||||
for(; i < count; i++) {
|
for(; i < count; i++) {
|
||||||
if (arr[i] === user) {
|
if (arr[i].name === item.name && arr[i].fraction === item.fraction) {
|
||||||
matchFound = true;
|
matchFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,4 @@ const arrayContains = (arr, user) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.sortCollection = sortCollectionBy;
|
exports.sortCollection = sortCollectionBy;
|
||||||
exports.arrayContains = arrayContains;
|
exports.arrayContains = playerArrayContains;
|
Loading…
Reference in New Issue