refactor/improve charts + limit combatRatingHistory length to 8
This commit is contained in:
4 files changed
+27
-9
No files matched your search
@@ -170,7 +170,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
const chartURL = `https://quickchart.io/chart?c=${encodedChart}`;
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`;
|
||||||
|
|
||||||
statsEmbed.setImage(chartURL);
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
@@ -199,31 +199,45 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
const chartURL = `https://quickchart.io/chart?c=${encodedChart}`;
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`;
|
||||||
|
|
||||||
statsEmbed.setImage(chartURL);
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
} else if (category == 'combatRating') {
|
} else if (category == 'combatRating') {
|
||||||
|
|
||||||
|
let data = query.combatRatingHistory;
|
||||||
|
|
||||||
statsEmbed.addFields({ name: 'Combat Rating', value: `${query.combatRating}`, inline: true });
|
statsEmbed.addFields({ name: 'Combat Rating', value: `${query.combatRating}`, inline: true });
|
||||||
|
|
||||||
if (query.combatRatingHistory.length == 1) query.combatRatingHistory.push(query.combatRating) // Make array 2 long for a straight line in the graph
|
if (data.length == 1) data.push(query.combatRating) // Make array 2 long for a straight line in the graph
|
||||||
|
|
||||||
const chart = {
|
const chart = {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
labels: new Array(query.combatRatingHistory.length).fill(' ', 0, query.combatRating.length),
|
labels: new Array(data.length).fill(' ', 0, data.length),
|
||||||
datasets: [{
|
datasets: [{
|
||||||
data: query.combatRatingHistory,
|
data: data,
|
||||||
label: 'Combat Rating Over Time',
|
label: 'Combat Rating Over Time',
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
|
scales: {
|
||||||
|
// Gives comfortable margin to the top of the y-axis
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
min: 0,
|
||||||
|
max: Math.round(Math.max(...data)/100)*100 + (Math.round(Math.max(...data)/100)*100 % 200 == 0 ? 400 : 500), // Keeps the max y-axis as a step of 200
|
||||||
|
step: 200,
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
// Gives a margin to the right of the whole graph
|
||||||
layout: {
|
layout: {
|
||||||
padding: {
|
padding: {
|
||||||
right: 40,
|
right: 40,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// Labels points on the graph to show evolution of combat rating
|
||||||
plugins: {
|
plugins: {
|
||||||
datalabels: {
|
datalabels: {
|
||||||
display: true,
|
display: true,
|
||||||
@@ -247,10 +261,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
const chartURL = `https://quickchart.io/chart?c=${encodedChart}`;
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`;
|
||||||
|
|
||||||
statsEmbed.setImage(chartURL);
|
statsEmbed.setImage(chartURL);
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
const encodedChart = encodeURIComponent(JSON.stringify(chart));
|
||||||
const chartURL = `https://quickchart.io/chart?c=${encodedChart}`;
|
const chartURL = `https://quickchart.io/chart?bkg=${encodeURIComponent("#ded8d7")}&c=${encodedChart}}`;
|
||||||
|
|
||||||
stats.setImage(chartURL);
|
stats.setImage(chartURL);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dayzr-bot",
|
"name": "dayzr-bot",
|
||||||
"version": "12.2.11",
|
"version": "12.2.12",
|
||||||
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
"description": "A General Purpose Discord Bot for DayZ Nitrado Servers.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"nodemonConfig": {
|
"nodemonConfig": {
|
||||||
|
|||||||
@@ -191,6 +191,10 @@ module.exports = {
|
|||||||
let victimOldRating = victimStat.combatRating;
|
let victimOldRating = victimStat.combatRating;
|
||||||
killerStat.combatRating = calculateNewCombatRating(killerStat.combatRating, victimStat.combatRating, 1);
|
killerStat.combatRating = calculateNewCombatRating(killerStat.combatRating, victimStat.combatRating, 1);
|
||||||
victimStat.combatRating = calculateNewCombatRating(victimStat.combatRating, killerStat.combatRating, 0);
|
victimStat.combatRating = calculateNewCombatRating(victimStat.combatRating, killerStat.combatRating, 0);
|
||||||
|
if (killerStat.combatRatingHistory.length == 8) killerStat.combatRatingHistory = killerStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 8)
|
||||||
|
if (victimStat.combatRatingHistory.length == 8) victimStat.combatRatingHistory = victimStat.combatRatingHistory.slice(1); // Remove first element (limits history to length 8)
|
||||||
|
killerStat.combatRatingHistory.push(killerStat.combatRating);
|
||||||
|
victimStat.combatRatingHistory.push(victimStat.combatRating);
|
||||||
let kdiff = killerStat.combatRating - killerOldRating;
|
let kdiff = killerStat.combatRating - killerOldRating;
|
||||||
let vdiff = victimStat.combatRating - victimOldRating;
|
let vdiff = victimStat.combatRating - victimOldRating;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user