2017-10-21 12:11:32 +02:00
|
|
|
'use strict';
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-28 12:58:40 +02:00
|
|
|
const playerArrayContains = require('./util').playerArrayContains;
|
2017-10-20 23:42:41 +02:00
|
|
|
|
|
|
|
const parseWarLog = (lineArray, war) => {
|
2017-10-22 14:13:58 +02:00
|
|
|
const nameToLongError = 'Error: ENAMETOOLONG: name too long, open \'';
|
2017-10-21 12:11:32 +02:00
|
|
|
const stats = {
|
|
|
|
war: war,
|
|
|
|
clean: [],
|
|
|
|
budget: [],
|
|
|
|
points: [],
|
|
|
|
kills: [],
|
|
|
|
respawn: [],
|
|
|
|
revive: [],
|
|
|
|
flag: [],
|
|
|
|
transport: [],
|
|
|
|
players: []
|
|
|
|
};
|
|
|
|
|
2017-11-06 14:22:18 +01:00
|
|
|
const addPlayerIfNotExists = (inputPlayer) => {
|
|
|
|
const player = getPlayerAndFractionFromString(inputPlayer);
|
|
|
|
if (player && player.name && player.fraction && !playerArrayContains(stats.players, player)) {
|
|
|
|
player['warId'] = war._id;
|
|
|
|
stats.players.push(player);
|
|
|
|
}
|
2017-10-20 23:42:41 +02:00
|
|
|
};
|
|
|
|
|
2017-10-22 14:13:58 +02:00
|
|
|
lineArray.some(line => {
|
|
|
|
/**
|
2017-11-02 11:17:16 +01:00
|
|
|
* sanitize nameTooLongError coming up in first line
|
2017-10-22 14:13:58 +02:00
|
|
|
*/
|
|
|
|
if (line.includes(nameToLongError)) {
|
|
|
|
line = line.substring(line.indexOf(nameToLongError) + nameToLongError.length);
|
|
|
|
}
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
/**
|
|
|
|
* KILLS
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
if (line.includes('(Abschuss)') && !line.includes('Fahrzeug')) {
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-01-16 19:46:28 +01:00
|
|
|
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('."'));
|
2017-10-21 11:32:25 +02:00
|
|
|
const shooter = getPlayerAndFractionFromString(shooterString);
|
2018-01-16 19:46:28 +01:00
|
|
|
const targetString = line.substring(line.lastIndexOf(' --- ') + 5, line.lastIndexOf(' von:'));
|
2017-10-21 11:32:25 +02:00
|
|
|
const target = getPlayerAndFractionFromString(targetString);
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.kills.push({
|
|
|
|
war: war._id,
|
2017-10-29 17:36:55 +01:00
|
|
|
time: getFullTimeDate(war.date, line.split(' ')[5]),
|
2017-10-21 11:32:25 +02:00
|
|
|
shooter: shooter ? shooter.name : null,
|
2018-01-16 19:46:28 +01:00
|
|
|
target: target ? target.name : null,
|
2017-10-21 19:49:24 +02:00
|
|
|
friendlyFire: shooter ? target.fraction === shooter.fraction : false,
|
|
|
|
fraction: shooter ? shooter.fraction : 'NONE'
|
2017-10-21 11:32:25 +02:00
|
|
|
});
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
/**
|
|
|
|
* BUDGET
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
else if (line.includes('(Budget)')) {
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
|
|
|
const budg = line.split(' ');
|
2017-12-10 15:43:30 +01:00
|
|
|
if (line.includes('Startbudget')) {
|
2018-01-16 19:46:28 +01:00
|
|
|
stats.war['budgetBlufor'] = transformMoneyString(budg[9]);
|
|
|
|
stats.war['budgetOpfor'] = transformMoneyString(budg[12].slice(0,-1));
|
2017-11-02 18:54:26 +01:00
|
|
|
// this date needs to be assigned in first place !important
|
2018-01-16 19:46:28 +01:00
|
|
|
stats.war.date = new Date(budg[0].slice(0,-1).split('/').join('-'));
|
2017-12-10 15:43:30 +01:00
|
|
|
} else if (line.includes('Endbudget')) {
|
2018-01-16 19:46:28 +01:00
|
|
|
stats.war['endBudgetBlufor'] = transformMoneyString(budg[9].substr(1));
|
|
|
|
stats.war['endBudgetOpfor'] = transformMoneyString(budg[12].slice(0,-1));
|
2017-12-10 15:43:30 +01:00
|
|
|
stats.war.endDate = getFullTimeDate(war.date, budg[5]);
|
2017-10-20 23:42:41 +02:00
|
|
|
} else {
|
2017-10-29 17:36:55 +01:00
|
|
|
stats.budget.push(getBudgetEntry(budg, war._id, war.date));
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
/**
|
|
|
|
* FLAG
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
else if (line.includes('(Fahne)') && !line.includes('Dominator')) {
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-01-16 19:46:28 +01:00
|
|
|
const playerName = line.substring(line.lastIndexOf('rt von ') + 7).slice(0, -2);
|
2017-10-21 10:41:49 +02:00
|
|
|
const flagFraction = line.includes('NATO Flagge') ? 'BLUFOR' : 'OPFOR';
|
|
|
|
const capture = !!line.includes('Flagge erobert');
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.flag.push({
|
|
|
|
war: war._id,
|
2017-10-29 17:36:55 +01:00
|
|
|
time: getFullTimeDate(war.date, line.split(' ')[5]),
|
2017-10-21 10:41:49 +02:00
|
|
|
player: playerName,
|
|
|
|
flagFraction: flagFraction,
|
|
|
|
capture: capture
|
|
|
|
});
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
/**
|
|
|
|
* POINTS
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
else if (line.includes('(Punkte)')) {
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
|
|
|
const pt = line.split(' ');
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
if (line.includes('Endpunktestand')) {
|
2018-01-16 19:46:28 +01:00
|
|
|
stats.war['ptBlufor'] = parseInt(pt[9]);
|
|
|
|
stats.war['ptOpfor'] = parseInt(pt[12].slice(0, -1));
|
2017-11-02 18:54:26 +01:00
|
|
|
// EXIT LOOP
|
2017-10-22 14:13:58 +02:00
|
|
|
return true;
|
2017-10-20 23:42:41 +02:00
|
|
|
} else {
|
2017-10-29 17:36:55 +01:00
|
|
|
stats.points.push(getPointsEntry(pt, line, war._id, war.date))
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
}
|
2018-01-16 19:46:28 +01:00
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * RESPAWN
|
|
|
|
// */
|
|
|
|
// else if (line.includes('Respawn')) {
|
|
|
|
// stats.clean.push(line);
|
|
|
|
// const resp = line.split(' ');
|
|
|
|
// const playerName = line.substring(line.lastIndexOf('Spieler:') + 9, line.lastIndexOf('-') - 1);
|
|
|
|
// stats.respawn.push(getRespawnEntry(resp, playerName, war._id, war.date));
|
|
|
|
// }
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
/**
|
|
|
|
* REVIVE
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
else if (line.includes('(Revive)')) {
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.clean.push(line);
|
2018-01-16 19:46:28 +01:00
|
|
|
const stabilized = !!line.includes('stabilisiert."');
|
2017-10-21 14:54:58 +02:00
|
|
|
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
|
|
|
|
line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
|
2017-10-21 11:32:25 +02:00
|
|
|
const medic = getPlayerAndFractionFromString(medicName);
|
2018-01-16 19:46:28 +01:00
|
|
|
const patientName = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(' wurde von'));
|
2017-10-21 11:32:25 +02:00
|
|
|
const patient = getPlayerAndFractionFromString(patientName);
|
2017-10-21 10:41:49 +02:00
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.revive.push({
|
|
|
|
war: war._id,
|
2017-10-29 17:36:55 +01:00
|
|
|
time: getFullTimeDate(war.date, line.split(' ')[5]),
|
2017-10-21 10:41:49 +02:00
|
|
|
stabilized: stabilized,
|
2017-10-21 11:32:25 +02:00
|
|
|
medic: medic.name,
|
2017-10-21 19:49:24 +02:00
|
|
|
patient: patient.name,
|
|
|
|
fraction: medic.fraction
|
2017-10-21 10:41:49 +02:00
|
|
|
});
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
|
2018-01-16 19:46:28 +01:00
|
|
|
// /**
|
|
|
|
// * TRANSPORT
|
|
|
|
// */
|
|
|
|
// else if (line.includes('Transport ||')) {
|
|
|
|
// stats.clean.push(line);
|
|
|
|
// const driverString = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(' eingeflogen'));
|
|
|
|
// const driver = getPlayerAndFractionFromString(driverString);
|
|
|
|
// const passengerString = line.substring(line.lastIndexOf('|| ') + 3, line.lastIndexOf(' wurde von'));
|
|
|
|
// const passenger = getPlayerAndFractionFromString(passengerString);
|
|
|
|
// const distance = parseInt(line.substring(line.lastIndexOf('eingeflogen (') + 13, line.lastIndexOf('m)') - 1));
|
|
|
|
//
|
|
|
|
// stats.transport.push({
|
|
|
|
// war: war._id,
|
|
|
|
// time: getFullTimeDate(war.date, line.split(' ')[5]),
|
|
|
|
// driver: driver.name,
|
|
|
|
// passenger: passenger ? passenger.name : null,
|
|
|
|
// fraction: driver.fraction,
|
|
|
|
// distance: distance
|
|
|
|
// });
|
|
|
|
// }
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-11-06 14:22:18 +01:00
|
|
|
/**
|
|
|
|
* PLAYERS
|
|
|
|
*/
|
2018-01-16 19:46:28 +01:00
|
|
|
else if (line.includes('(Fraktionsuebersicht)')) {
|
|
|
|
const playerString = line.substring(line.lastIndexOf('--- ') + 4, line.lastIndexOf(', PUID'));
|
2017-11-06 14:22:18 +01:00
|
|
|
addPlayerIfNotExists(playerString)
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
|
|
|
});
|
2017-10-21 11:32:25 +02:00
|
|
|
|
2017-10-21 14:54:58 +02:00
|
|
|
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;
|
|
|
|
stats.players[i]['kill'] = stats.kills.filter(kill => kill.shooter === playerName && !kill.friendlyFire).length;
|
|
|
|
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]['revive'] = stats.revive.filter(rev => rev.medic === playerName && !rev.stabilized).length;
|
|
|
|
stats.players[i]['flagTouch'] = stats.flag.filter(flag => flag.player === playerName).length;
|
2017-10-22 14:13:58 +02:00
|
|
|
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']
|
2017-10-21 14:54:58 +02:00
|
|
|
}
|
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
stats.war.playersBlufor = stats.players.filter(player => player.fraction === 'BLUFOR').length;
|
|
|
|
stats.war.playersOpfor = stats.players.filter(player => player.fraction === 'OPFOR').length;
|
|
|
|
|
|
|
|
return stats;
|
2017-10-20 23:42:41 +02:00
|
|
|
};
|
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getRespawnEntry = (respawn, playerName, warId, warDate) => {
|
2017-10-20 23:42:41 +02:00
|
|
|
return {
|
2017-10-21 12:11:32 +02:00
|
|
|
war: warId,
|
2017-10-29 17:36:55 +01:00
|
|
|
time: getFullTimeDate(warDate, respawn[5]),
|
2017-10-20 23:42:41 +02:00
|
|
|
player: playerName
|
|
|
|
}
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getPointsEntry = (pt, line, warId, warDate) => {
|
2017-10-20 23:42:41 +02:00
|
|
|
return {
|
2017-10-21 18:23:04 +02:00
|
|
|
war: warId,
|
2017-10-29 17:36:55 +01:00
|
|
|
time: getFullTimeDate(warDate, pt[5]),
|
2018-01-16 19:46:28 +01:00
|
|
|
ptBlufor: parseInt(pt[10]),
|
|
|
|
ptOpfor: parseInt(pt[13].slice(0, -3)),
|
|
|
|
fraction: line.includes('Kein Dominator') ? 'NONE' : line.includes('NATO +1') ? 'BLUFOR' : 'OPFOR'
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getBudgetEntry = (budg, warId, warDate) => {
|
2017-10-20 23:42:41 +02:00
|
|
|
return {
|
2017-10-21 18:23:04 +02:00
|
|
|
war: warId,
|
2017-10-29 17:36:55 +01:00
|
|
|
time: getFullTimeDate(warDate, budg[5]),
|
2018-01-16 19:46:28 +01:00
|
|
|
fraction: budg[7] === 'NATO' ? 'BLUFOR' : 'OPFOR',
|
|
|
|
oldBudget: transformMoneyString(budg[9]),
|
|
|
|
newBudget: transformMoneyString(budg[12])
|
2017-10-20 23:42:41 +02:00
|
|
|
}
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-21 12:11:32 +02:00
|
|
|
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
|
|
|
const nameArray = nameAndFractionString.split(' ');
|
2017-10-21 14:54:58 +02:00
|
|
|
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ? nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR' : undefined;
|
2017-10-21 11:32:25 +02:00
|
|
|
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
|
2017-10-21 19:49:24 +02:00
|
|
|
// do not return player for 'Selbstverschulden' or 'Error: No unit'
|
2017-10-21 14:54:58 +02:00
|
|
|
if (name && name !== 'Error: No unit') {
|
2017-10-21 11:32:25 +02:00
|
|
|
return {name: name, fraction: fraction};
|
|
|
|
}
|
2017-10-21 12:11:32 +02:00
|
|
|
};
|
2017-10-21 11:32:25 +02:00
|
|
|
|
2017-10-20 23:42:41 +02:00
|
|
|
const transformMoneyString = (budgetString) => {
|
2017-10-21 12:11:32 +02:00
|
|
|
if (!budgetString.includes('e+')) {
|
2017-10-20 23:42:41 +02:00
|
|
|
return parseInt(budgetString);
|
|
|
|
}
|
2017-10-21 12:11:32 +02:00
|
|
|
const budget = budgetString.split('e+');
|
2017-10-20 23:42:41 +02:00
|
|
|
return Math.round(parseFloat(budget[0]) * Math.pow(10, parseInt(budget[1])));
|
2017-10-29 17:36:55 +01:00
|
|
|
};
|
2017-10-20 23:42:41 +02:00
|
|
|
|
2017-10-29 17:36:55 +01:00
|
|
|
const getFullTimeDate = (date, timeString) => {
|
|
|
|
const returnDate = new Date(date);
|
|
|
|
const time = timeString.split(':');
|
|
|
|
returnDate.setHours(time[0]);
|
|
|
|
returnDate.setMinutes(time[1]);
|
|
|
|
return returnDate;
|
2017-10-20 23:42:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = parseWarLog;
|