Update heatmap embed to show min and max vals

This commit is contained in:
Ean Milligan (Bastion) 2022-06-26 23:18:44 -04:00
parent 51924b7f14
commit 6adf18008a
2 changed files with 12 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import {
import config from '../../config.ts';
import { failColor, infoColor2 } from '../commandUtils.ts';
import utils from '../utils.ts';
import intervals from '../intervals.ts';
export const heatmap = async (message: DiscordenoMessage) => {
// Light telemetry to see how many times a command is being run
@ -15,14 +16,17 @@ export const heatmap = async (message: DiscordenoMessage) => {
const m = await message.send({
embeds: [{
title: 'Roll Heatmap',
description: `Least Rolls: ${intervals.getMinRollCnt()}
Most Rolls: ${intervals.getMaxRollCnt()}`,
footer: {
text: 'Data is shown in US Eastern Time. | This heatmap uses data starting 6/26/2022.',
},
color: infoColor2,
image: {
url: `${config.api.publicDomain}api/heatmap.png`,
},
}],
}).catch((e) => utils.commonLoggers.messageSendError('heatmap.ts:21', message, e));
console.log(m);
} else {
message.send({
embeds: [{

View File

@ -150,6 +150,8 @@ const hourPixels: Array<Array<number>> = [
];
// updateHeatmap() returns nothing, creates new heatmap.png
// Updates the heatmap image with latest data from the db
let minRollCnt: number;
let maxRollCnt: number;
const updateHeatmapPng = async () => {
const baseHeatmap = Deno.readFileSync('./src/endpoints/gets/heatmap-base.png');
const heatmap = await is.decode(baseHeatmap);
@ -159,8 +161,8 @@ const updateHeatmapPng = async () => {
// Get latest data from DB
const heatmapData = await dbClient.query('SELECT * FROM roll_time_heatmap ORDER BY hour;').catch((e) => utils.commonLoggers.dbError('intervals.ts:148', 'query', e));
let minRollCnt = Infinity;
let maxRollCnt = 0;
minRollCnt = Infinity;
maxRollCnt = 0;
// determine min and max values
for (const hour of heatmapData) {
for (const day of weekDays) {
@ -202,4 +204,6 @@ export default {
updateListStatistics,
updateHourlyRates,
updateHeatmapPng,
getMinRollCnt: () => minRollCnt,
getMaxRollCnt: () => maxRollCnt,
};