Add revive and flag parsing

pull/15/head
Florian Hartwich 2017-10-21 10:41:49 +02:00
parent f1449e5047
commit db48cd8ef6
1 changed files with 41 additions and 7 deletions

View File

@ -12,7 +12,6 @@ const parseWarLog = (lineArray, war) => {
const flag = []; const flag = [];
const transport = []; const transport = [];
const playerNames = []; const playerNames = [];
const addPlayerIfNotExists = (playerName) => { const addPlayerIfNotExists = (playerName) => {
if (playerName !== 'Error: No unit' && !arrayContains(playerNames, playerName)) { if (playerName !== 'Error: No unit' && !arrayContains(playerNames, playerName)) {
playerNames.push(playerName); playerNames.push(playerName);
@ -45,7 +44,18 @@ const parseWarLog = (lineArray, war) => {
if (line.includes("Fahne")) { if (line.includes("Fahne")) {
clean.push(line); clean.push(line);
const playerName = line.substring(line.lastIndexOf("t von ") + 6, line.lastIndexOf(" :OPT LOG END"));
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
const capture = !!line.includes('Flagge erobert');
flag.push({
warId: 'sdf89uiz786',
time: getDateTime(line.split(" ")[5]),
player: playerName,
flagFraction: flagFraction,
capture: capture
});
addPlayerIfNotExists(playerName);
} }
if (line.includes("Punkte")) { if (line.includes("Punkte")) {
@ -71,24 +81,47 @@ const parseWarLog = (lineArray, war) => {
if (line.includes("Revive")) { if (line.includes("Revive")) {
clean.push(line); clean.push(line);
//console.log(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 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);
revive.push({
warId: 'asfddf',
time: getDateTime(line.split(" ")[5]),
stabilized: stabilized,
medic: sanitizedMedicName,
patient: sanitizedPatientName
});
addPlayerIfNotExists(sanitizedMedicName);
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 driverName = line.substring(line.lastIndexOf("wurde von ") + 10, line.lastIndexOf(" eingeflogen"));
const driverNameArray = driverName.split(" "); const driverNameArray = driverName.split(" ");
const driverFraction = driverNameArray[driverNameArray.length-1] === "(WEST)" ? "BLUFOR" : "OPFOR"; const driverFraction = driverNameArray[driverNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const sanitizedDriverName = driverName.substring(0, driverName.indexOf(driverNameArray[driverNameArray.length-1])-1); const sanitizedDriverName = driverName.substring(0, driverName.indexOf(driverNameArray[driverNameArray.length - 1]) - 1);
const passengerName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von")); const passengerName = line.substring(line.lastIndexOf("|| ") + 3, line.lastIndexOf(" wurde von"));
const passengerNameArray = passengerName.split(" "); const passengerNameArray = passengerName.split(" ");
const passengerFraction = passengerNameArray[passengerNameArray.length-1] === "(WEST)" ? "BLUFOR" : "OPFOR"; const passengerFraction = passengerNameArray[passengerNameArray.length - 1] === "(WEST)" ? "BLUFOR" : "OPFOR";
const sanitizedPassengerName = passengerName.substring(0, passengerName.indexOf(passengerNameArray[passengerNameArray.length-1])-1); 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]),
driver: sanitizedDriverName, driver: sanitizedDriverName,
passenger: sanitizedPassengerName, passenger: sanitizedPassengerName,
distance: distance distance: distance
@ -99,7 +132,8 @@ const parseWarLog = (lineArray, war) => {
} }
}); });
// //
playerNames.forEach(budg => console.log(budg)); // revive.forEach(budg => console.log(budg));
// console.log(revive.length)
}; };
function getRespawnEntry(respawn, playerName) { function getRespawnEntry(respawn, playerName) {