Add playercount for log parsing
parent
dad3cbe067
commit
8c9151b351
|
@ -28,13 +28,13 @@ const WarSchema = new Schema({
|
|||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
default: 0
|
||||
},
|
||||
playersOpfor: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
default: 0
|
||||
},
|
||||
bestPlayerId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
|
|
|
@ -51,11 +51,11 @@ wars.route('/')
|
|||
const war = new WarModel(body);
|
||||
|
||||
if (req.file) {
|
||||
war.save((err, item) => {
|
||||
war.save((err, war) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
const folderName = __dirname + '/../resource/logs/' + item._id;
|
||||
const folderName = __dirname + '/../resource/logs/' + war._id;
|
||||
mkdirp(folderName, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
|
@ -65,7 +65,7 @@ wars.route('/')
|
|||
return next(err);
|
||||
}
|
||||
//TODO: combine run and clean in one script, so log file gets touched only once
|
||||
exec(__dirname + '/../war-parser/run.sh ' + folderName + ' ' + item._id, (error, stdout) => {
|
||||
exec(__dirname + '/../war-parser/run.sh ' + folderName + ' ' + war._id, (error, stdout) => {
|
||||
if (error) {
|
||||
return next(error);
|
||||
}
|
||||
|
@ -74,14 +74,33 @@ wars.route('/')
|
|||
return next(error);
|
||||
}
|
||||
let obj = JSON.parse(`${stdout}`);
|
||||
PlayerModel.create(obj, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
if (obj[i].fraction === 'BLUFOR') {
|
||||
war.playersBlufor++;
|
||||
} else {
|
||||
war.playersOpfor++;
|
||||
}
|
||||
res.status(codes.created);
|
||||
res.locals.items = item;
|
||||
return next();
|
||||
});
|
||||
}
|
||||
|
||||
WarModel.findByIdAndUpdate(war._id, war, {new: true}, (err, item) => {
|
||||
if (err) {
|
||||
err.status = codes.wrongrequest;
|
||||
}
|
||||
else if (!item) {
|
||||
err = new Error("item not found");
|
||||
err.status = codes.notfound;
|
||||
}
|
||||
else {
|
||||
PlayerModel.create(obj, function (err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.status(codes.created);
|
||||
res.locals.items = war;
|
||||
return next();
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
Schlacht Statistik
|
||||
Statistik
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu scrollable-menu">
|
||||
|
|
|
@ -55,7 +55,7 @@ export class WarSubmitComponent {
|
|||
this.router.navigate([war._id], {relativeTo: this.route});
|
||||
},
|
||||
error => {
|
||||
this.error = error._body;
|
||||
this.error = error._body.error.message;
|
||||
this.showErrorLabel = true;
|
||||
this.loading = false;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue