Skip to content

Commit

Permalink
Fix SessionStats sometimes breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherPillow committed Jan 25, 2023
1 parent 6fc4bb2 commit 84e4a8f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function runTail(path) {
})
})
}
} else if (/^\[\d\d:\d\d:\d\d\] \[Client thread\/INFO\]: \[CHAT\] .+ (was .+ by|by|with) .+$/.test(data)) {
} else if (/^\[\d\d:\d\d:\d\d\] \[Client thread\/INFO\]: \[CHAT\] .+ (was .+ by|by|with|died in) .+$/.test(data)) {
foundKill(data,IGN);
}
if (players.length >= 1) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"productName": "Opal Overlay",
"name": "opal-overlay",
"version": "0.1.6",
"version": "0.1.7",
"author": "AnotherPillow",
"repository": {
"type": "git",
Expand Down
40 changes: 25 additions & 15 deletions renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,16 @@ const generateRow = (user,re=false) => {
`<td> - &nbsp</td>`+
`<td>NICK</td>`
)
if (re) row.onload = () => {resize()}
if (re) row.onload = () => {setTimeout(()=>{resize()},100)}
return row;
}
const addBwPlayer = (bwStats) => {
const table = document.getElementById('user-table');
table.appendChild(generateRow(bwStats,true));
resize();
}
const nullSession = {

let sessionStats = {
kills:0,
deaths:0,
fkdr:0,
Expand All @@ -291,8 +292,7 @@ const nullSession = {
final_deaths:0,
beds_broken:0,
beds_lost:0,
}
let sessionStats = nullSession;
};
const handleStats = (stats) => {
let row = document.getElementById('sessionTR');
const sessionDiv = document.getElementById('sessionDiv');
Expand All @@ -313,13 +313,9 @@ const handleStats = (stats) => {

row.innerHTML = ''

sessionStats.fkdr = (sessionStats.final_kills/sessionStats.final_deaths).toFixed(2) || 0;
sessionStats.bblr = (sessionStats.beds_broken/sessionStats.beds_lost).toFixed(2) || 0;
sessionStats.kdr = (sessionStats.kills/sessionStats.deaths).toFixed(2) || 0;

sessionStats.fkdr = checkForNaNInfity(sessionStats.fkdr)
sessionStats.bblr = checkForNaNInfity(sessionStats.bblr)
sessionStats.kdr = checkForNaNInfity(sessionStats.kdr)
sessionStats.fkdr = calcRatio(sessionStats.final_kills, sessionStats.final_deaths); //calc fkdr
sessionStats.kdr = calcRatio(sessionStats.kills, sessionStats.deaths); //calc kdr
sessionStats.bblr = calcRatio(sessionStats.beds_broken, sessionStats.beds_lost);

//check if infinity

Expand All @@ -330,12 +326,26 @@ const handleStats = (stats) => {
resize();
}

const checkForNaNInfity = (num) => {
if (num === Infinity || num === NaN) return 0;
else return num;
const calcRatio = (finals, deaths) => {
if (finals === 0 && deaths === 0) return 0;
let tempRatio = (finals/deaths).toFixed(2);
if (!isFinite(tempRatio)) {
return finals.toFixed(2);
}
return tempRatio;
}
const clearSession = () => {
sessionStats = nullSession;
sessionStats = {
kills:0,
deaths:0,
fkdr:0,
bblr:0,
kdr:0,
final_kills:0,
final_deaths:0,
beds_broken:0,
beds_lost:0,
};
const sessionDiv = document.getElementById('sessionDiv');
const row = document.getElementById('sessionTR');
row.innerHTML = '';
Expand Down

0 comments on commit 84e4a8f

Please sign in to comment.