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