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