Compare commits

..

No commits in common. "91ebda52b01284830e9e1b40014d102abeb79bb9" and "35f6ac04b3455fa82aa8a2d149d6ccf02294e6f1" have entirely different histories.

5 changed files with 50 additions and 36 deletions

View File

@ -63,31 +63,25 @@ wars.route('/')
})
.post(apiAuthenticationMiddleware, checkMT, upload.single('log'), (req, res, next) => {
const body = req.body;
const warBody = new WarModel(body);
let body = req.body;
const bodyWar = new WarModel(body);
if (req.file) {
// bodyWar.save((err, war) => {
// if (err) {
// return next(err);
// }
fs.readFile(req.file.buffer, (file, err) => {
if (err) {
return next(err);
}
const lineArray = file.toString().split("\n");
const statsResult = parseWarLog(lineArray, warBody);
statsResult.war.save((err, war) => {
if (err) {
return next(err);
}
PlayerModel.create(statsResult.players, function (err) {
if (err) {
return next(err);
}
res.status(codes.created);
res.locals.items = war;
res.locals.items = parseWarLog(lineArray, bodyWar);
res.locals.processed = true;
next();
});
})
});
// })
} else {
const err = new Error('no Logfile provided');
err.status = codes.wrongmediasend;

View File

@ -18,7 +18,7 @@ const parseWarLog = (lineArray, war) => {
const addPlayersIfNotExists = (inputPlayers) => {
inputPlayers.forEach(player => {
if (player && player.name && player.fraction && !arrayContains(stats.players, player)) {
if (player && !arrayContains(stats.players, player)) {
player['warId'] = war._id;
stats.players.push(player);
}
@ -33,6 +33,7 @@ const parseWarLog = (lineArray, war) => {
stats.clean.push(line);
const shooterString = line.substring(line.lastIndexOf(' von: ') + 6, line.lastIndexOf('. :OPT LOG END'));
const shooter = getPlayerAndFractionFromString(shooterString);
const targetString = line.substring(line.lastIndexOf(' || ') + 4, line.lastIndexOf(' von:'));
const target = getPlayerAndFractionFromString(targetString);
@ -57,7 +58,6 @@ const parseWarLog = (lineArray, war) => {
stats.war['endBudgetBlufor'] = transformMoneyString(budg[11]);
stats.war['endBudgetOpfor'] = transformMoneyString(budg[14]);
} else if (line.includes('Startbudget')) {
stats.war.date = new Date(budg[0].substr(0, budg[0].length - 1).split('/').join('-') + 'T22:00:00.000+02:00');
stats.war['budgetBlufor'] = transformMoneyString(budg[11]);
stats.war['budgetOpfor'] = transformMoneyString(budg[14]);
} else {
@ -114,8 +114,7 @@ const parseWarLog = (lineArray, war) => {
if (line.includes('Revive')) {
stats.clean.push(line);
const stabilized = !!line.includes('stabilisiert');
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10,
line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
const medicName = line.substring(line.lastIndexOf('wurde von ') + 10, line.lastIndexOf(stabilized ? ' stabilisiert' : ' wiederbelebt'));
const medic = getPlayerAndFractionFromString(medicName);
const patientName = line.substring(line.lastIndexOf('|| ') + 3, line.lastIndexOf(' wurde von'));
const patient = getPlayerAndFractionFromString(patientName);
@ -154,20 +153,11 @@ 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;
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;
}
stats.war.playersBlufor = stats.players.filter(player => player.fraction === 'BLUFOR').length;
stats.war.playersOpfor = stats.players.filter(player => player.fraction === 'OPFOR').length;
return stats;
};
const getRespawnEntry = (respawn, playerName, warId) => {
@ -199,10 +189,10 @@ const getBudgetEntry = (budg, warId) => {
const getPlayerAndFractionFromString = (nameAndFractionString) => {
const nameArray = nameAndFractionString.split(' ');
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ? nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR' : undefined;
const fraction = nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR';
const name = nameAndFractionString.substring(0, nameAndFractionString.indexOf(nameArray[nameArray.length - 1]) - 1);
// do not return player for 'Selbstverschulden'
if (name && name !== 'Error: No unit') {
if (name || name === 'Error: No unit') {
return {name: name, fraction: fraction};
}
};

View File

@ -1,6 +1,6 @@
{
"name": "opt-cc",
"version": "1.6.0",
"version": "1.5.4",
"license": "MIT",
"private": true,
"scripts": {

View File

@ -12,6 +12,36 @@
<show-error text="Name" path="title"></show-error>
</div>
<div class="form-group">
<label for="date">Datum</label>
<input type="date" class="form-control"
[(ngModel)]="war.date"
name="date"
id="date"
required/>
<show-error text="Datum" path="date"></show-error>
</div>
<div class="form-group">
<label for="ptblu">Punkte NATO</label>
<input type="number" class="form-control" step="1"
[(ngModel)]="war.ptBlufor"
name="ptblu"
id="ptblu"
required/>
<show-error text="Punkte NATO" path="ptblu"></show-error>
</div>
<div class="form-group">
<label for="ptopf">Punkte CSAT</label>
<input type="number" class="form-control" step="1"
[(ngModel)]="war.ptOpfor"
name="ptopf"
id="ptopf"
required/>
<show-error text="Punkte CSAT" path="ptopf"></show-error>
</div>
<div class="form-group">
<label for="campaign">Kampagne</label>
<select class="form-control"

View File

@ -14,7 +14,7 @@ import {CampaignService} from "../../services/campaign-service/campaign.service"
})
export class WarSubmitComponent {
war: War = {players: []};
war: War = {date: new Date().toISOString().slice(0, 10), players: []};
fileList: FileList;