Add mongoose schemas for logs
parent
91ebda52b0
commit
443184027e
|
@ -0,0 +1,39 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogBudgetSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
fraction: {
|
||||
type: String,
|
||||
enum: ['BLUFOR', 'OPFOR'],
|
||||
required: true
|
||||
},
|
||||
oldBudget: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
},
|
||||
newBudget: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logBudget'
|
||||
});
|
||||
// optional more indices
|
||||
LogBudgetSchema.index({war: 1});
|
||||
|
||||
module.exports = mongoose.model('LogBudget', LogBudgetSchema);
|
|
@ -0,0 +1,35 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogFlagSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
player: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
flagFraction: {
|
||||
type: String,
|
||||
enum: ['BLUFOR', 'OPFOR'],
|
||||
required: true
|
||||
},
|
||||
capture: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logFlag'
|
||||
});
|
||||
// optional more indices
|
||||
LogFlagSchema.index({war: 1, player: 1});
|
||||
|
||||
module.exports = mongoose.model('LogFlag', LogFlagSchema);
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogKillSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
shooter: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
target: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
friendlyFire: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logKill'
|
||||
});
|
||||
// optional more indices
|
||||
LogKillSchema.index({war: 1, shooter: 1, target: 1});
|
||||
|
||||
module.exports = mongoose.model('LogKill', LogKillSchema);
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogKillSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
ptBlufor: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
},
|
||||
ptOpfor: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logKill'
|
||||
});
|
||||
// optional more indices
|
||||
LogKillSchema.index({war: 1, shooter: 1, target: 1});
|
||||
|
||||
module.exports = mongoose.model('LogKill', LogKillSchema);
|
|
@ -0,0 +1,26 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogRespawnSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
player: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logRespawn'
|
||||
});
|
||||
// optional more indices
|
||||
LogRespawnSchema.index({war: 1, player: 1});
|
||||
|
||||
module.exports = mongoose.model('LogRespawn', LogRespawnSchema);
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogReviveSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
medic: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
patient: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
stabilized: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logRevive'
|
||||
});
|
||||
// optional more indices
|
||||
LogReviveSchema.index({war: 1, medic: 1});
|
||||
|
||||
module.exports = mongoose.model('LogRevive', LogReviveSchema);
|
|
@ -0,0 +1,36 @@
|
|||
"use strict";
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const LogTransportSchema = new Schema({
|
||||
war: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'War',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Date,
|
||||
required: true
|
||||
},
|
||||
driver: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
passenger: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
distance: {
|
||||
type: Number,
|
||||
get: v => Math.round(v),
|
||||
set: v => Math.round(v),
|
||||
required: true
|
||||
}
|
||||
}, {
|
||||
collection: 'logTransport'
|
||||
});
|
||||
// optional more indices
|
||||
LogTransportSchema.index({war: 1});
|
||||
|
||||
module.exports = mongoose.model('LogTransport', LogTransportSchema);
|
|
@ -23,6 +23,12 @@ const parseWarLog = require('../tools/log-parse-tool');
|
|||
const CampaignModel = require('../models/campaign');
|
||||
const WarModel = require('../models/war');
|
||||
const PlayerModel = require('../models/player');
|
||||
const LogKillModel = require('../models/logs/kill');
|
||||
const LogRespawnModel = require('../models/logs/respawn');
|
||||
const LogReviveModel = require('../models/logs/revive');
|
||||
const LogTransportModel = require('../models/logs/transport');
|
||||
const LogFlagModel = require('../models/logs/flag');
|
||||
const LogBudgetModel = require('../models/logs/budget');
|
||||
|
||||
const wars = express.Router();
|
||||
|
||||
|
@ -67,26 +73,38 @@ wars.route('/')
|
|||
const warBody = new WarModel(body);
|
||||
|
||||
if (req.file) {
|
||||
fs.readFile(req.file.buffer, (file, 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);
|
||||
}
|
||||
const lineArray = file.toString().split("\n");
|
||||
const statsResult = parseWarLog(lineArray, warBody);
|
||||
statsResult.war.save((err, war) => {
|
||||
PlayerModel.create(statsResult.players, function (err) {
|
||||
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();
|
||||
});
|
||||
})
|
||||
});
|
||||
LogKillModel.create(statsResult.kills, function (err) {
|
||||
LogRespawnModel.create(statsResult.respawn, function (err) {
|
||||
LogReviveModel.create(statsResult.revive, function (err) {
|
||||
LogFlagModel.create(statsResult.flag, function (err) {
|
||||
LogBudgetModel.create(statsResult.budget, function (err) {
|
||||
LogTransportModel.create(statsResult.transport, function (err) {
|
||||
res.status(codes.created);
|
||||
res.locals.items = war;
|
||||
next();
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
} else {
|
||||
const err = new Error('no Logfile provided');
|
||||
|
|
|
@ -180,7 +180,7 @@ const getRespawnEntry = (respawn, playerName, warId) => {
|
|||
|
||||
const getPointsEntry = (pt, warId) => {
|
||||
return {
|
||||
warId: warId,
|
||||
war: warId,
|
||||
time: getDateTime(pt[5]),
|
||||
ptBlufor: parseInt(pt[12]),
|
||||
ptOpfor: parseInt(pt[15].slice(0, -1))
|
||||
|
@ -189,7 +189,7 @@ const getPointsEntry = (pt, warId) => {
|
|||
|
||||
const getBudgetEntry = (budg, warId) => {
|
||||
return {
|
||||
warId: warId,
|
||||
war: warId,
|
||||
time: getDateTime(budg[5]),
|
||||
fraction: budg[9] === 'NATO' ? 'BLUFOR' : 'OPFOR',
|
||||
oldBudget: transformMoneyString(budg[11]),
|
||||
|
|
Loading…
Reference in New Issue