Compare commits
2 Commits
35f6ac04b3
...
91ebda52b0
Author | SHA1 | Date |
---|---|---|
Florian Hartwich | 91ebda52b0 | |
Florian Hartwich | 1acaba5a60 |
|
@ -63,25 +63,31 @@ wars.route('/')
|
|||
})
|
||||
|
||||
.post(apiAuthenticationMiddleware, checkMT, upload.single('log'), (req, res, next) => {
|
||||
let body = req.body;
|
||||
const bodyWar = new WarModel(body);
|
||||
const body = req.body;
|
||||
const warBody = 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");
|
||||
res.locals.items = parseWarLog(lineArray, bodyWar);
|
||||
res.locals.processed = true;
|
||||
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;
|
||||
next();
|
||||
});
|
||||
// })
|
||||
})
|
||||
});
|
||||
|
||||
} else {
|
||||
const err = new Error('no Logfile provided');
|
||||
err.status = codes.wrongmediasend;
|
||||
|
|
|
@ -18,7 +18,7 @@ const parseWarLog = (lineArray, war) => {
|
|||
|
||||
const addPlayersIfNotExists = (inputPlayers) => {
|
||||
inputPlayers.forEach(player => {
|
||||
if (player && !arrayContains(stats.players, player)) {
|
||||
if (player && player.name && player.fraction && !arrayContains(stats.players, player)) {
|
||||
player['warId'] = war._id;
|
||||
stats.players.push(player);
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ 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);
|
||||
|
||||
|
@ -58,6 +57,7 @@ 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,7 +114,8 @@ 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);
|
||||
|
@ -153,11 +154,20 @@ 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) => {
|
||||
|
@ -189,10 +199,10 @@ const getBudgetEntry = (budg, warId) => {
|
|||
|
||||
const getPlayerAndFractionFromString = (nameAndFractionString) => {
|
||||
const nameArray = nameAndFractionString.split(' ');
|
||||
const fraction = nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR';
|
||||
const fraction = nameArray[nameArray.length - 1] !== '(ENEMY)' ? nameArray[nameArray.length - 1] === '(WEST)' ? 'BLUFOR' : 'OPFOR' : undefined;
|
||||
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};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "opt-cc",
|
||||
"version": "1.5.4",
|
||||
"version": "1.6.0",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
|
|
@ -12,36 +12,6 @@
|
|||
<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"
|
||||
|
|
|
@ -14,7 +14,7 @@ import {CampaignService} from "../../services/campaign-service/campaign.service"
|
|||
})
|
||||
export class WarSubmitComponent {
|
||||
|
||||
war: War = {date: new Date().toISOString().slice(0, 10), players: []};
|
||||
war: War = {players: []};
|
||||
|
||||
fileList: FileList;
|
||||
|
||||
|
|
Loading…
Reference in New Issue