diff --git a/chart.js b/charts/chart.js similarity index 100% rename from chart.js rename to charts/chart.js diff --git a/echoChart.js b/charts/echoChart.js similarity index 100% rename from echoChart.js rename to charts/echoChart.js diff --git a/foxtrotChart.js b/charts/foxtrotChart.js similarity index 100% rename from foxtrotChart.js rename to charts/foxtrotChart.js diff --git a/index.js b/index.js index 31b983f..66897a5 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,11 @@ require('dotenv').config() const Gamedig = require('gamedig'); const mongoose = require('mongoose') const fs = require('fs') -const ServerState = require('./stateModel') +const ServerState = require('./models/stateModel') const nodeCron = require('node-cron') const logger = require('skinwalker') const express = require('express'); -const AttendanceModel = require('./attendanceModel') +const AttendanceModel = require('./models/attendanceModel') const app = express() logger.init(process.env.LOG_LEVEL, { @@ -16,7 +16,7 @@ logger.init(process.env.LOG_LEVEL, { app.set('view engine', 'ejs'); logger.info('Set view engine to ejs', 'webserver') -app.use(express.static('./')) +app.use('/', express.static('./charts')) app.use('/assets', express.static('./assets')) logger.info('Served static files', 'webserver') @@ -281,7 +281,7 @@ app.get('/echo', async (req, res) => { }) temp.players = tempPlayers temp.squadCount = tempPlayers.length - temp.attendance = ((temp.squadCount / echotSquad.length) * 100) + temp.attendance = ((temp.squadCount / echotSquad.length) * 100).toFixed(2) serverLogs.unshift(temp) }) logger.trace('serverLogs: ' + JSON.stringify(serverLogs), 'webserver/echo') @@ -303,8 +303,37 @@ app.get('/echo', async (req, res) => { }) logger.trace('chartData: ' + JSON.stringify(chartData), 'webserver/echo') + var individualAttendance = [] + + echotSquad.forEach(player => { + var temp = { + playerName: String, + attendance: Number + } + temp.playerName = player + + logger.trace('Calculating attendance for player ' + player, 'webserver/echo') + var attended = 0 + + dbState.forEach(element => { + logger.trace('Checking attendance for ' + player + ' in operation ' + element.missionName, 'webserver/echo') + if(element.players.toString().replaceAll(/\s*\[.*?]/g, '').includes(player)){ + logger.trace('Bumping attendance counter for player ' + player, 'webserver/echo') + attended++ + } + }) + + logger.trace('Attended OPs for player ' + player + ' calculated to ' + attended, 'webserver/echo') + var att = ((attended / dbState.length) * 100).toFixed(2) + logger.trace('Attendedance for player ' + player + ' calculated to ' + att + '%', 'webserver/echo') + temp.attendance = att + individualAttendance.unshift(temp) + }) + logger.trace('individualAttendance: ' + JSON.stringify(individualAttendance), 'webserver/echo') + res.render('echo', { serverLogs: serverLogs, + individualAttendance: individualAttendance, chartData: JSON.stringify(chartData) }) @@ -343,7 +372,7 @@ app.get('/foxtrot', async (req, res) => { }) temp.players = tempPlayers temp.squadCount = tempPlayers.length - temp.attendance = ((temp.squadCount / foxtrotSquad.length) * 100) + temp.attendance = ((temp.squadCount / foxtrotSquad.length) * 100).toFixed(2) serverLogs.unshift(temp) }) logger.trace('serverLogs: ' + JSON.stringify(serverLogs), 'webserver/foxtrot') @@ -365,8 +394,37 @@ app.get('/foxtrot', async (req, res) => { }) logger.trace('chartData' + JSON.stringify(chartData), 'webserver/foxtrot') + var individualAttendance = [] + + foxtrotSquad.forEach(player => { + var temp = { + playerName: String, + attendance: Number + } + temp.playerName = player + + logger.trace('Calculating attendance for player ' + player, 'webserver/foxtrot') + var attended = 0 + + dbState.forEach(element => { + logger.trace('Checking attendance for ' + player + ' in operation ' + element.missionName, 'webserver/foxtrot') + if(element.players.toString().replaceAll(/\s*\[.*?]/g, '').includes(player)){ + logger.trace('Bumping attendance counter for player ' + player, 'webserver/foxtrot') + attended++ + } + }) + + logger.trace('Attended OPs for player ' + player + ' calculated to ' + attended, 'webserver/foxtrot') + var att = ((attended / dbState.length) * 100).toFixed(2) + logger.trace('Attendedance for player ' + player + ' calculated to ' + att + '%', 'webserver/foxtrot') + temp.attendance = att + individualAttendance.unshift(temp) + }) + logger.trace('individualAttendance: ' + JSON.stringify(individualAttendance), 'webserver/foxtrot') + res.render('foxtrot', { serverLogs: serverLogs, + individualAttendance, individualAttendance, chartData: JSON.stringify(chartData) }) diff --git a/attendanceModel.js b/models/attendanceModel.js similarity index 100% rename from attendanceModel.js rename to models/attendanceModel.js diff --git a/stateModel.js b/models/stateModel.js similarity index 100% rename from stateModel.js rename to models/stateModel.js diff --git a/views/echo.ejs b/views/echo.ejs index c45dce6..f9dba67 100644 --- a/views/echo.ejs +++ b/views/echo.ejs @@ -58,34 +58,51 @@
-
- - - - - - - - - - - - - - <% serverLogs.forEach(log => { %> - - - - - - - - - - <% }) %> - - -
Mission nameDatePlayer countSquad countAttendancePlayers
<%= log.missionName %> <%= log.date %> <%= log.playerCount %> <%= log.squadCount %> <%= log.attendance %> % <%= log.players %>
+
+ + + + + + + + + + + + + <% serverLogs.forEach(log => { %> + + + + + + + + + <% }) %> + +
Mission nameDatePlayer countSquad countAttendancePlayers
<%= log.missionName %> <%= log.date %> <%= log.playerCount %> <%= log.squadCount %> <%= log.attendance %> % <%= log.players %>
+ +
+

Individual Attendance

+
+ + + + + + + + + <% individualAttendance.forEach(log => { %> + + + + + <% }) %> + +
Player nameAttendance(%)
<%= log.playerName %> <%= log.attendance %>
diff --git a/views/foxtrot.ejs b/views/foxtrot.ejs index e079771..6a2067b 100644 --- a/views/foxtrot.ejs +++ b/views/foxtrot.ejs @@ -58,36 +58,55 @@
-
- - - - - - - - - - - - - - <% serverLogs.forEach(log => { %> - - - - - - - - - - <% }) %> - - -
Mission nameDatePlayer countSquad countAttendancePlayers
<%= log.missionName %> <%= log.date %> <%= log.playerCount %> <%= log.squadCount %> <%= log.attendance %> % <%= log.players %>
+
+ + + + + + + + + + + + + <% serverLogs.forEach(log => { %> + + + + + + + + + <% }) %> + +
Mission nameDatePlayer countSquad countAttendancePlayers
<%= log.missionName %> <%= log.date %> <%= log.playerCount %> <%= log.squadCount %> <%= log.attendance %> % <%= log.players %>
-
+
+

Individual Attendance

+
+ + + + + + + + + + <% individualAttendance.forEach(log => { %> + + + + + + <% }) %> + +
Player nameAttendance(%)
<%= log.playerName %> <%= log.attendance %>
+ +
diff --git a/views/index.ejs b/views/index.ejs index 68828a3..7965d0d 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -58,33 +58,29 @@
-
- - - - - - - - - - - - <% serverLogs.forEach(log => { %> - - - - - - - - - <% }) %> - - -
Mission nameDatePlayer countPlayers
<%= log.missionName %> <%= log.date %> <%= log.playerCount %> <%= log.players %>
+
+ + + + + + + + + + + <% serverLogs.forEach(log => { %> + + + + + + + <% }) %> + +
Mission nameDatePlayer countPlayers
<%= log.missionName %> <%= log.date %> <%= log.playerCount %> <%= log.players %>
-
+