Fix vehicle kill parsing

pull/35/head
HardiReady 2018-06-06 18:45:25 +02:00
parent f3f5638667
commit 58d0c781a2
2 changed files with 95 additions and 81 deletions

View File

@ -13,11 +13,15 @@ const VehicleClasses = Object.freeze({
const playerNameRegex = /^(.*?)\s\(/; const playerNameRegex = /^(.*?)\s\(/;
const vehicleNameEndRegex = /\s\(\w+:/;
const sideRegex = /(side:\s(.*?)\))/; const sideRegex = /(side:\s(.*?)\))/;
const magazineRegex = /(magazine:\s(.*?)\))/; // const magazineRegex = /(magazine:\s(.*?)\))/;
const vehicleRegex = /(vehicle:\s(.*?)\))/; // const vehicleRegex = /(vehicle:\s(.*?)\))/;
const categoryRegex = /(category:\s(.*?)\))/;
const parseWarLog = (lineArray, war) => { const parseWarLog = (lineArray, war) => {
const NAME_TOO_LONG_ERROR = 'Error: ENAMETOOLONG: name too long, open \''; const NAME_TOO_LONG_ERROR = 'Error: ENAMETOOLONG: name too long, open \'';
@ -47,11 +51,10 @@ const parseWarLog = (lineArray, war) => {
]; ];
const addPlayerIfNotExists = (inputPlayer, steamUUID) => { const addPlayerIfNotExists = (inputPlayer, steamUUID) => {
console.log(inputPlayer)
const player = getPlayerAndFractionFromString(inputPlayer); const player = getPlayerAndFractionFromString(inputPlayer);
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) { if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
player[ 'warId' ] = war._id; player['warId'] = war._id;
player[ 'steamUUID' ] = steamUUID; player['steamUUID'] = steamUUID;
stats.players.push(player); stats.players.push(player);
} }
}; };
@ -79,7 +82,7 @@ const parseWarLog = (lineArray, war) => {
if (target && shooter && target.fraction !== shooter.fraction) { if (target && shooter && target.fraction !== shooter.fraction) {
stats.vehicles.push({ stats.vehicles.push({
war: war._id, war: war._id,
time: getFullTimeDate(war.date, line.split(WHITESPACE)[ 5 ]), time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
shooter: shooter ? shooter.name : null, shooter: shooter ? shooter.name : null,
target: target ? target.name : null, target: target ? target.name : null,
fraction: shooter ? shooter.fraction : 'NONE', fraction: shooter ? shooter.fraction : 'NONE',
@ -91,7 +94,7 @@ const parseWarLog = (lineArray, war) => {
const target = getPlayerAndFractionFromString(targetString); 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]),
shooter: shooter ? shooter.name : null, shooter: shooter ? shooter.name : null,
target: target ? target.name : null, target: target ? target.name : null,
friendlyFire: shooter ? target.fraction === shooter.fraction : false, friendlyFire: shooter ? target.fraction === shooter.fraction : false,
@ -105,16 +108,16 @@ const parseWarLog = (lineArray, war) => {
stats.clean.push(line); stats.clean.push(line);
const budg = line.split(WHITESPACE); const budg = line.split(WHITESPACE);
if (line.includes('Startbudget')) { if (line.includes('Startbudget')) {
stats.war[ 'budgetBlufor' ] = transformMoneyString(budg[ 9 ]); stats.war['budgetBlufor'] = transformMoneyString(budg[9]);
stats.war[ 'budgetOpfor' ] = transformMoneyString(budg[ 12 ].slice(0, -1)); stats.war['budgetOpfor'] = transformMoneyString(budg[12].slice(0, -1));
// this date needs to be assigned in first place !important // this date needs to be assigned in first place !important
const dateString = budg[ 0 ].slice(0, -1).split('/').map((s) => parseInt(s)); const dateString = budg[0].slice(0, -1).split('/').map((s) => parseInt(s));
stats.war.date = new Date(dateString[ 0 ], dateString[ 1 ] - 1, dateString[ 2 ]); stats.war.date = new Date(dateString[0], dateString[1] - 1, dateString[2]);
} else if (line.includes('Endbudget')) { } else if (line.includes('Endbudget')) {
stats.war[ 'endBudgetBlufor' ] = transformMoneyString(budg[ 9 ]); stats.war['endBudgetBlufor'] = transformMoneyString(budg[9]);
stats.war[ 'endBudgetOpfor' ] = transformMoneyString(budg[ 12 ].slice(0, -2)); stats.war['endBudgetOpfor'] = transformMoneyString(budg[12].slice(0, -2));
stats.war.endDate = getFullTimeDate(war.date, budg[ 5 ]); stats.war.endDate = getFullTimeDate(war.date, budg[5]);
} else { } else {
if (line.includes('Respawn von ')) { if (line.includes('Respawn von ')) {
/** /**
@ -136,7 +139,7 @@ const parseWarLog = (lineArray, war) => {
stats.flag.push({ stats.flag.push({
war: war._id, war: war._id,
time: getFullTimeDate(war.date, line.split(WHITESPACE)[ 5 ]), time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
player: playerName, player: playerName,
flagFraction: flagFraction, flagFraction: flagFraction,
capture: capture, capture: capture,
@ -149,8 +152,8 @@ const parseWarLog = (lineArray, war) => {
const pt = line.split(WHITESPACE); const pt = line.split(WHITESPACE);
if (line.includes('Endpunktestand')) { if (line.includes('Endpunktestand')) {
stats.war[ 'ptBlufor' ] = parseInt(pt[ 9 ]); stats.war['ptBlufor'] = parseInt(pt[9]);
stats.war[ 'ptOpfor' ] = parseInt(pt[ 12 ].slice(0, -1)); stats.war['ptOpfor'] = parseInt(pt[12].slice(0, -1));
// EXIT LOOP // EXIT LOOP
return true; return true;
} else { } else {
@ -170,7 +173,7 @@ const parseWarLog = (lineArray, war) => {
stats.revive.push({ stats.revive.push({
war: war._id, war: war._id,
time: getFullTimeDate(war.date, line.split(WHITESPACE)[ 5 ]), time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
stabilized: stabilized, stabilized: stabilized,
medic: medic.name, medic: medic.name,
patient: patient.name, patient: patient.name,
@ -189,7 +192,7 @@ const parseWarLog = (lineArray, war) => {
stats.transport.push({ stats.transport.push({
war: war._id, war: war._id,
time: getFullTimeDate(war.date, line.split(WHITESPACE)[ 5 ]), time: getFullTimeDate(war.date, line.split(WHITESPACE)[5]),
driver: driver ? driver.name : null, driver: driver ? driver.name : null,
passenger: passenger ? passenger.name : null, passenger: passenger ? passenger.name : null,
fraction: driver ? driver.fraction : 'NONE', fraction: driver ? driver.fraction : 'NONE',
@ -206,37 +209,37 @@ const parseWarLog = (lineArray, war) => {
}); });
for (let i = 0; i < stats.players.length; i++) { for (let i = 0; i < stats.players.length; i++) {
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( stats.players[i]['kill'] = stats.kills.filter(
(kill) => kill.shooter === playerName && !kill.friendlyFire).length; (kill) => kill.shooter === playerName && !kill.friendlyFire).length;
// TODO: use vehicle class description from enum // TODO: use vehicle class description from enum
stats.players[ i ][ 'vehicleLight' ] = stats.vehicles.filter( stats.players[i]['vehicleLight'] = stats.vehicles.filter(
(vehicle) => vehicle.shooter === playerName && vehicle.vehicleClass === 'LIGHT' && (vehicle) => vehicle.shooter === playerName && vehicle.vehicleClass === 'LIGHT' &&
VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length; VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length;
stats.players[ i ][ 'vehicleHeavy' ] = stats.vehicles.filter( stats.players[i]['vehicleHeavy'] = stats.vehicles.filter(
(vehicle) => vehicle.shooter === playerName && vehicle.vehicleClass === 'HEAVY' && (vehicle) => vehicle.shooter === playerName && vehicle.vehicleClass === 'HEAVY' &&
VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length; VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length;
stats.players[ i ][ 'vehicleAir' ] = stats.vehicles.filter( stats.players[i]['vehicleAir'] = stats.vehicles.filter(
(vehicle) => vehicle.shooter === playerName && vehicle.vehicleClass === 'AIR' && (vehicle) => vehicle.shooter === playerName && vehicle.vehicleClass === 'AIR' &&
VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length; VEHICLE_BLACKLIST.indexOf(vehicle.target) < 0).length;
stats.players[ i ][ 'friendlyFire' ] = stats.kills.filter( stats.players[i]['friendlyFire'] = stats.kills.filter(
(kill) => kill.shooter === playerName && kill.friendlyFire).length; (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;
stats.players[ i ][ 'flagTouch' ] = stats.flag.filter((flag) => flag.player === playerName).length; stats.players[i]['flagTouch'] = stats.flag.filter((flag) => flag.player === playerName).length;
stats.players[ i ][ 'sort' ] = stats.players[ i ][ 'kill' ] + stats.players[ i ][ 'revive' ] + stats.players[i]['sort'] = stats.players[i]['kill'] + stats.players[i]['revive'] +
stats.players[ i ][ 'flagTouch' ] stats.players[i]['flagTouch']
- stats.players[ i ][ 'friendlyFire' ] - stats.players[ i ][ 'death' ] - stats.players[ i ][ 'respawn' ]; - stats.players[i]['friendlyFire'] - stats.players[i]['death'] - stats.players[i]['respawn'];
} }
stats.war.playersBlufor = stats.players.filter((player) => player.fraction === 'BLUFOR').length; stats.war.playersBlufor = stats.players.filter((player) => player.fraction === 'BLUFOR').length;
@ -248,7 +251,7 @@ const parseWarLog = (lineArray, war) => {
const getRespawnEntry = (respawn, playerName, warId, warDate) => { const getRespawnEntry = (respawn, playerName, warId, warDate) => {
return { return {
war: warId, war: warId,
time: getFullTimeDate(warDate, respawn[ 5 ]), time: getFullTimeDate(warDate, respawn[5]),
player: playerName, player: playerName,
}; };
}; };
@ -256,9 +259,9 @@ const getRespawnEntry = (respawn, playerName, warId, warDate) => {
const getPointsEntry = (pt, line, warId, warDate) => { const getPointsEntry = (pt, line, warId, warDate) => {
return { return {
war: warId, war: warId,
time: getFullTimeDate(warDate, pt[ 5 ]), time: getFullTimeDate(warDate, pt[5]),
ptBlufor: parseInt(pt[ 10 ]), ptBlufor: parseInt(pt[10]),
ptOpfor: parseInt(pt[ 13 ].slice(0, -3)), ptOpfor: parseInt(pt[13].slice(0, -3)),
fraction: line.includes('Kein Dominator') ? 'NONE' : line.includes('NATO +1') ? 'BLUFOR' : 'OPFOR', fraction: line.includes('Kein Dominator') ? 'NONE' : line.includes('NATO +1') ? 'BLUFOR' : 'OPFOR',
}; };
}; };
@ -266,49 +269,49 @@ const getPointsEntry = (pt, line, warId, warDate) => {
const getBudgetEntry = (budg, warId, warDate) => { const getBudgetEntry = (budg, warId, warDate) => {
return { return {
war: warId, war: warId,
time: getFullTimeDate(warDate, budg[ 5 ]), time: getFullTimeDate(warDate, budg[5]),
fraction: budg[ 7 ] === 'NATO' ? 'BLUFOR' : 'OPFOR', fraction: budg[7] === 'NATO' ? 'BLUFOR' : 'OPFOR',
oldBudget: transformMoneyString(budg[ 9 ]), oldBudget: transformMoneyString(budg[9]),
newBudget: transformMoneyString(budg[ 12 ]), newBudget: transformMoneyString(budg[12]),
}; };
}; };
const getPlayerAndFractionFromString = (inputString) => { const getPlayerAndFractionFromString = (inputString) => {
const playerNameRegexMatch = playerNameRegex.exec(inputString); const playerNameRegexMatch = playerNameRegex.exec(inputString);
const sideMatch = sideRegex.exec(inputString); const sideMatch = sideRegex.exec(inputString);
const magazineMatch = magazineRegex.exec(inputString); // const magazineMatch = magazineRegex.exec(inputString);
const vehicleMatch = vehicleRegex.exec(inputString); // const vehicleMatch = vehicleRegex.exec(inputString);
let name; let name;
if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) { if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) {
// NAME // NAME
name = playerNameRegexMatch[ 1 ]; name = playerNameRegexMatch[1];
} }
let side let side;
if (sideMatch && sideMatch.length >= 3) { if (sideMatch && sideMatch.length >= 3) {
// SIDE // SIDE
side = sideMatch[ 2 ]; side = sideMatch[2];
} else { } else {
const inputArray = inputString.split(WHITESPACE) const inputArray = inputString.split(WHITESPACE);
if (inputArray && inputArray.length === 2) { if (inputArray) {
side = inputArray[ 1 ].replace('(', '').replace(')', ''); side = inputArray[inputArray.length - 1].replace('(', '').replace(')', '');
} }
} }
if (magazineMatch && magazineMatch.length >= 3) { // if (magazineMatch && magazineMatch.length >= 3) {
// MAGAZINE // MAGAZINE
// console.log(magazineMatch[2]) // console.log(magazineMatch[2])
} // }
if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[ 2 ]) { // if (vehicleMatch && vehicleMatch.length >= 3 && vehicleMatch[2]) {
let vehicle = vehicleMatch[ 2 ]; // let vehicle = vehicleMatch[2];
if (new RegExp("\\(.*$").test(vehicle)) { // if (new RegExp("\\(.*$").test(vehicle)) {
vehicle = vehicle.concat(")"); // vehicle = vehicle.concat(")");
} // }
// VEHICLE // VEHICLE
// console.log(vehicle) // console.log(vehicle)
} // }
let fraction; let fraction;
if (side) { if (side) {
@ -324,34 +327,45 @@ const getPlayerAndFractionFromString = (inputString) => {
}; };
const getVehicleAndFractionFromString = (nameClassFractionString) => { const getVehicleAndFractionFromString = (nameClassFractionString) => {
const nameArray = nameClassFractionString.trim().split(WHITESPACE); const sideMatch = sideRegex.exec(nameClassFractionString);
const vehicleFraction = nameArray[ nameArray.length - 1 ].slice(0, -1); const categoryMatch = categoryRegex.exec(nameClassFractionString);
nameArray.pop();
nameArray.pop(); // NAME
const vehicleClassString = nameArray[ nameArray.length - 1 ].replace('(', '').replace(')', ''); const vehicleName = nameClassFractionString.substring(0,
nameArray.pop(); nameClassFractionString.indexOf(vehicleNameEndRegex.exec(nameClassFractionString)));
nameArray.pop();
const vehicleName = nameArray.join(WHITESPACE); let fraction;
if (sideMatch && sideMatch.length >= 3) {
// SIDE
const side = sideMatch[2];
fraction = side === 'OPT_NATO' || side === 'OPT_NATO_T' || side === 'WEST' ? 'BLUFOR' : 'OPFOR';
}
let vehicleClassString;
if (categoryMatch && categoryMatch.length >= 3) {
// CATEGORY
vehicleClassString = categoryMatch[2];
}
// skip logging here - this is some basic equipment identifier (i.e. parachute) // skip logging here - this is some basic equipment identifier (i.e. parachute)
if (vehicleFraction === 'OPF_F' || vehicleFraction === 'BLU_F' || vehicleClassString === VehicleClasses.UNKNOWN) { if (fraction === 'OPF_F' || fraction === 'BLU_F' || vehicleClassString === VehicleClasses.UNKNOWN) {
return; return;
} }
const fraction = vehicleFraction === '(OPT_NATO)' || vehicleFraction === '(OPT_NATO_T)' ? 'BLUFOR' : 'OPFOR';
let vehicleClass; let vehicleClass;
for (const key in VehicleClasses) { for (const key in VehicleClasses) {
if (VehicleClasses.hasOwnProperty(key) && VehicleClasses[ key ] === vehicleClassString) { if (VehicleClasses.hasOwnProperty(key) && VehicleClasses[key] === vehicleClassString) {
vehicleClass = key; vehicleClass = key;
} }
} }
if (vehicleName && fraction && vehicleClass) {
return { return {
name: vehicleName, name: vehicleName,
fraction: fraction, fraction: fraction,
vehicleClass: vehicleClass, vehicleClass: vehicleClass,
}; };
}
}; };
const transformMoneyString = (budgetString) => { const transformMoneyString = (budgetString) => {
@ -359,14 +373,14 @@ const transformMoneyString = (budgetString) => {
return parseInt(budgetString); return parseInt(budgetString);
} }
const budget = budgetString.split('e+'); const budget = budgetString.split('e+');
return Math.round(parseFloat(budget[ 0 ]) * Math.pow(10, parseInt(budget[ 1 ]))); return Math.round(parseFloat(budget[0]) * Math.pow(10, parseInt(budget[1])));
}; };
const getFullTimeDate = (date, timeString) => { const getFullTimeDate = (date, timeString) => {
const returnDate = new Date(date); const returnDate = new Date(date);
const time = timeString.split(':'); const time = timeString.split(':');
returnDate.setHours(time[ 0 ]); returnDate.setHours(time[0]);
returnDate.setMinutes(time[ 1 ]); returnDate.setMinutes(time[1]);
return returnDate; return returnDate;
}; };

View File

@ -1,4 +1,4 @@
<code_scheme name="OPT-CC" version="173"> <code_scheme name="OPT-CC copy" version="173">
<option name="FORMATTER_TAGS_ENABLED" value="true" /> <option name="FORMATTER_TAGS_ENABLED" value="true" />
<JSCodeStyleSettings> <JSCodeStyleSettings>
<option name="USE_CHAINED_CALLS_GROUP_INDENTS" value="true" /> <option name="USE_CHAINED_CALLS_GROUP_INDENTS" value="true" />