Fix basic player information parsing
parent
c14b33f9c5
commit
f3f5638667
|
@ -11,6 +11,14 @@ const VehicleClasses = Object.freeze({
|
|||
UNKNOWN: 'Unbekannt',
|
||||
});
|
||||
|
||||
const playerNameRegex = /^(.*?)\s\(/;
|
||||
|
||||
const sideRegex = /(side:\s(.*?)\))/;
|
||||
|
||||
const magazineRegex = /(magazine:\s(.*?)\))/;
|
||||
|
||||
const vehicleRegex = /(vehicle:\s(.*?)\))/;
|
||||
|
||||
const parseWarLog = (lineArray, war) => {
|
||||
const NAME_TOO_LONG_ERROR = 'Error: ENAMETOOLONG: name too long, open \'';
|
||||
|
||||
|
@ -39,6 +47,7 @@ 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;
|
||||
|
@ -61,7 +70,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
*/
|
||||
stats.clean.push(line);
|
||||
|
||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
||||
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.search(/$/) - 1);
|
||||
const shooter = getPlayerAndFractionFromString(shooterString);
|
||||
|
||||
if (line.includes('Fahrzeug:')) {
|
||||
|
@ -200,7 +209,8 @@ const parseWarLog = (lineArray, war) => {
|
|||
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((kill) => kill.shooter === playerName && !kill.friendlyFire).length;
|
||||
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(
|
||||
|
@ -224,7 +234,8 @@ const parseWarLog = (lineArray, war) => {
|
|||
|
||||
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 ][ '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' ];
|
||||
}
|
||||
|
||||
|
@ -262,16 +273,53 @@ const getBudgetEntry = (budg, warId, warDate) => {
|
|||
};
|
||||
};
|
||||
|
||||
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
||||
const nameArray = nameAndFractionString.split(WHITESPACE);
|
||||
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ?
|
||||
nameArray[nameArray.length - 1] === '(WEST)' ?
|
||||
const getPlayerAndFractionFromString = (inputString) => {
|
||||
const playerNameRegexMatch = playerNameRegex.exec(inputString);
|
||||
const sideMatch = sideRegex.exec(inputString);
|
||||
const magazineMatch = magazineRegex.exec(inputString);
|
||||
const vehicleMatch = vehicleRegex.exec(inputString);
|
||||
|
||||
let name;
|
||||
if (playerNameRegexMatch && playerNameRegexMatch.length >= 2) {
|
||||
// NAME
|
||||
name = playerNameRegexMatch[ 1 ];
|
||||
}
|
||||
|
||||
let side
|
||||
if (sideMatch && sideMatch.length >= 3) {
|
||||
// SIDE
|
||||
side = sideMatch[ 2 ];
|
||||
} else {
|
||||
const inputArray = inputString.split(WHITESPACE)
|
||||
if (inputArray && inputArray.length === 2) {
|
||||
side = inputArray[ 1 ].replace('(', '').replace(')', '');
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
let fraction;
|
||||
if (side) {
|
||||
fraction = side !== 'ENEMY' ? side === 'WEST' ?
|
||||
'BLUFOR' : 'OPFOR' :
|
||||
undefined;
|
||||
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
|
||||
// do not return player for 'Selbstverschulden' or 'Error: No unit'
|
||||
}
|
||||
|
||||
// do not return player for 'Error: No unit'
|
||||
if (name && name !== 'Error: No unit') {
|
||||
return {name: name, fraction: fraction};
|
||||
return {name: name.trim(), fraction: fraction};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue