-
+
+
diff --git a/public/script.js b/public/script.js
index 2279889d..bb136dc2 100644
--- a/public/script.js
+++ b/public/script.js
@@ -1,5 +1,5 @@
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, shouldSendOnEnter } from './scripts/RossAscends-mods.js';
-import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js';
+import { initStats } from './scripts/stats.js';
import {
generateKoboldWithStreaming,
kai_settings,
@@ -1348,14 +1348,16 @@ function verifyCharactersSearchSortRule() {
}
}
-/** @typedef {object} Character - A character */
-/** @typedef {object} Group - A group */
+/** @typedef {{name: string, avatar: string, fav: boolean}} Character - A character */
+/** @typedef {{id: string, name: string, avatar: string, fav: boolean}} Group - A group */
+/** @typedef {import('./scripts/tags.js').Tag} Tag */
+/** @typedef {import('./scripts/personas.js').Persona} Persona - A persona */
/**
* @typedef {object} Entity - Object representing a display entity
- * @property {Character|Group|import('./scripts/tags.js').Tag|*} item - The item
+ * @property {Character|Group|Tag|Persona} item - The item
* @property {string|number} id - The id
- * @property {string} type - The type of this entity (character, group, tag)
+ * @property {'character'|'group'|'tag'|'persona'} type - The type of this entity (character, group, tag, persona)
* @property {Entity[]} [entities] - An optional list of entities relevant for this item
* @property {number} [hidden] - An optional number representing how many hidden entities this entity contains
*/
@@ -1384,13 +1386,23 @@ export function groupToEntity(group) {
/**
* Converts the given tag to its entity representation
*
- * @param {import('./scripts/tags.js').Tag} tag - The tag
+ * @param {Tag} tag - The tag
* @returns {Entity} The entity for this tag
*/
export function tagToEntity(tag) {
return { item: structuredClone(tag), id: tag.id, type: 'tag', entities: [] };
}
+/**
+ * Converts the given persona based to its entity representation
+ *
+ * @param {Persona} persona - The avatar id for the persona
+ * @returns {Entity} The entity for this persona
+ */
+export function personaToEntity(persona) {
+ return { item: persona, id: persona.avatar, type: 'persona' };
+}
+
/**
* Builds the full list of all entities available
*
@@ -1449,6 +1461,23 @@ export function getEntitiesList({ doFilter = false, doSort = true } = {}) {
return entities;
}
+/**
+ * Get one character from the character list via its character key
+ *
+ * To retrieve/refresh it from the API, use `getOneCharacter` to update it first.
+ *
+ * @param {string} characterKey - The character key / avatar url
+ * @returns {object}
+ */
+export function getCharacter(characterKey) {
+ return characters.find(x => x.avatar === characterKey);
+}
+
+/**
+ * Gets one character from via API
+ *
+ * @param {string} avatarUrl - The avatar url / character key
+ */
export async function getOneCharacter(avatarUrl) {
const response = await fetch('/api/characters/get', {
method: 'POST',
@@ -4445,7 +4474,7 @@ export async function sendMessageAsUser(messageText, messageBias, insertAt = nul
}
await populateFileAttachment(message);
- statMesProcess(message, 'user', characters, this_chid, '');
+ // statMesProcess(message, 'user', characters, this_chid, '');
if (typeof insertAt === 'number' && insertAt >= 0 && insertAt <= chat.length) {
chat.splice(insertAt, 0, message);
@@ -5595,6 +5624,17 @@ export function getThumbnailUrl(type, file) {
return `/thumbnail?type=${type}&file=${encodeURIComponent(file)}`;
}
+/**
+ * Build an avatar list for entities inside a given html block element
+ *
+ * @param {JQuery} block - The block to build the avatar list in
+ * @param {Entity[]} entities - A list of entities for which to build the avatar for
+ * @param {object} options - Optional options
+ * @param {string} [options.templateId='inline_avatar_template'] - The template from which the inline avatars are built off
+ * @param {boolean} [options.empty=true] - Whether the block will be emptied before drawing the avatars
+ * @param {boolean} [options.selectable=false] - Whether the avatars should be selectable/clickable. If set, the click handler has to be implemented externally on the classes/items
+ * @param {boolean} [options.highlightFavs=true] - Whether favorites should be highlighted
+ */
export function buildAvatarList(block, entities, { templateId = 'inline_avatar_template', empty = true, selectable = false, highlightFavs = true } = {}) {
if (empty) {
block.empty();
@@ -5602,34 +5642,39 @@ export function buildAvatarList(block, entities, { templateId = 'inline_avatar_t
for (const entity of entities) {
const id = entity.id;
+ const item = entity.item;
// Populate the template
const avatarTemplate = $(`#${templateId} .avatar`).clone();
-
- let this_avatar = default_avatar;
- if (entity.item.avatar !== undefined && entity.item.avatar != 'none') {
- this_avatar = getThumbnailUrl('avatar', entity.item.avatar);
- }
-
avatarTemplate.attr('data-type', entity.type);
- avatarTemplate.attr({ 'chid': id, 'id': `CharID${id}` });
- avatarTemplate.find('img').attr('src', this_avatar).attr('alt', entity.item.name);
- avatarTemplate.attr('title', `[Character] ${entity.item.name}\nFile: ${entity.item.avatar}`);
- if (highlightFavs) {
- avatarTemplate.toggleClass('is_fav', entity.item.fav || entity.item.fav == 'true');
- avatarTemplate.find('.ch_fav').val(entity.item.fav);
+
+ switch (entity.type) {
+ case 'character':
+ avatarTemplate.attr({ 'chid': id, 'id': `CharID${id}` });
+ const charAvatar = item.avatar && item.avatar != 'none' ? getThumbnailUrl('avatar', item.avatar) : default_avatar;
+ avatarTemplate.find('img').attr('src', charAvatar).attr('alt', item.name);
+ avatarTemplate.attr('title', `[Character] ${item.name}\nFile: ${item.avatar}`);
+ break;
+ case 'group':
+ const grpTemplate = getGroupAvatar(item);
+ avatarTemplate.attr({ 'gid': id, 'id': `GroupID${id}` });
+ avatarTemplate.addClass(grpTemplate.attr('class'));
+ avatarTemplate.empty();
+ avatarTemplate.append(grpTemplate.children());
+ avatarTemplate.attr('title', `[Group] ${item.name}`);
+ break;
+ case 'persona':
+ avatarTemplate.attr({ 'pid': id, 'id': `PersonaID${id}` });
+ const personaAvatar = getUserAvatar(item.avatar)
+ avatarTemplate.find('img').attr('src', personaAvatar).attr('alt', item.name);
+ avatarTemplate.attr('title', `[Persona] ${item.name}`);
+ break;
}
- // If this is a group, we need to hack slightly. We still want to keep most of the css classes and layout, but use a group avatar instead.
- if (entity.type === 'group') {
- const grpTemplate = getGroupAvatar(entity.item);
-
- avatarTemplate.addClass(grpTemplate.attr('class'));
- avatarTemplate.empty();
- avatarTemplate.append(grpTemplate.children());
- avatarTemplate.attr('title', `[Group] ${entity.item.name}`);
+ if (highlightFavs && 'fav' in item) {
+ avatarTemplate.toggleClass('is_fav', item.fav);
+ avatarTemplate.find('.ch_fav').val(item.fav ? 'true' : 'false');
}
-
if (selectable) {
avatarTemplate.addClass('selectable');
avatarTemplate.toggleClass('character_select', entity.type === 'character');
@@ -6880,10 +6925,10 @@ function onScenarioOverrideRemoveClick() {
* @param {string} type
* @param {string} inputValue - Value to set the input to.
* @param {PopupOptions} options - Options for the popup.
- * @typedef {{okButton?: string, rows?: number, wide?: boolean, large?: boolean, allowHorizontalScrolling?: boolean, allowVerticalScrolling?: boolean, cropAspect?: number }} PopupOptions - Options for the popup.
+ * @typedef {{okButton?: string, rows?: number, wide?: boolean, wider?: boolean, large?: boolean, allowHorizontalScrolling?: boolean, allowVerticalScrolling?: boolean, cropAspect?: number }} PopupOptions - Options for the popup.
* @returns
*/
-export function callPopup(text, type, inputValue = '', { okButton, rows, wide, large, allowHorizontalScrolling, allowVerticalScrolling, cropAspect } = {}) {
+export function callPopup(text, type, inputValue = '', { okButton, rows, wide, wider, large, allowHorizontalScrolling, allowVerticalScrolling, cropAspect } = {}) {
function getOkButtonText() {
if (['avatarToCrop'].includes(popup_type)) {
return okButton ?? 'Accept';
@@ -6913,6 +6958,7 @@ export function callPopup(text, type, inputValue = '', { okButton, rows, wide, l
const $shadowPopup = $('#shadow_popup');
$dialoguePopup.toggleClass('wide_dialogue_popup', !!wide)
+ .toggleClass('wider_dialogue_popup', !!wider)
.toggleClass('large_dialogue_popup', !!large)
.toggleClass('horizontal_scrolling_dialogue_popup', !!allowHorizontalScrolling)
.toggleClass('vertical_scrolling_dialogue_popup', !!allowVerticalScrolling);
@@ -10202,10 +10248,6 @@ jQuery(async function () {
isManualInput = false;
});
- $('.user_stats_button').on('click', function () {
- userStatsHandler();
- });
-
$('#external_import_button').on('click', async () => {
const html = `
Enter the URL of the content to import
Supported sources:
diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js
index 33699b99..e53a74a6 100644
--- a/public/scripts/RossAscends-mods.js
+++ b/public/scripts/RossAscends-mods.js
@@ -81,19 +81,21 @@ observer.observe(document.documentElement, observerConfig);
/**
- * Converts generation time from milliseconds to a human-readable format.
+ * Converts a timespan from milliseconds to a human-readable format.
*
- * The function takes total generation time as an input, then converts it to a format
+ * The function takes a total timespan as an input, then converts it to a format
* of "_ Days, _ Hours, _ Minutes, _ Seconds". If the generation time does not exceed a
* particular measure (like days or hours), that measure will not be included in the output.
*
- * @param {number} total_gen_time - The total generation time in milliseconds.
- * @returns {string} - A human-readable string that represents the time spent generating characters.
+ * @param {number} timespan - The total timespan in milliseconds.
+ * @param {object} [options] - Optional parameters
+ * @param {boolean} [options.short=false] - Flag indicating whether short form should be used. ('2h' instead of '2 Hours')
+ * @param {number} [options.onlyHighest] - Number of maximum blocks to be returned. (If, and daya is the highest matching unit, only returns days and hours, cutting of minutes and seconds)
+ * @returns {string} - A human-readable string that represents the timespan.
*/
-export function humanizeGenTime(total_gen_time) {
-
+export function humanizeTimespan(timespan, { short = false, onlyHighest = 2 } = {}) {
//convert time_spent to humanized format of "_ Hours, _ Minutes, _ Seconds" from milliseconds
- let time_spent = total_gen_time || 0;
+ let time_spent = timespan || 0;
time_spent = Math.floor(time_spent / 1000);
let seconds = time_spent % 60;
time_spent = Math.floor(time_spent / 60);
@@ -102,12 +104,36 @@ export function humanizeGenTime(total_gen_time) {
let hours = time_spent % 24;
time_spent = Math.floor(time_spent / 24);
let days = time_spent;
- time_spent = '';
- if (days > 0) { time_spent += `${days} Days, `; }
- if (hours > 0) { time_spent += `${hours} Hours, `; }
- if (minutes > 0) { time_spent += `${minutes} Minutes, `; }
- time_spent += `${seconds} Seconds`;
- return time_spent;
+
+ let parts = [
+ { singular: 'Day', plural: 'Days', short: 'd', value: days },
+ { singular: 'Hour', plural: 'Hours', short: 'h', value: hours },
+ { singular: 'Minute', plural: 'Minutes', short: 'm', value: minutes },
+ { singular: 'Second', plural: 'Seconds', short: 's', value: seconds },
+ ];
+
+ // Build the final string based on the highest significant units and respecting zeros
+ let resultParts = [];
+ let count = 0;
+ for (let part of parts) {
+ if (part.value > 0) {
+ resultParts.push(part);
+ }
+
+ // If we got a match, we count from there. Take a maximum of X elements
+ if (resultParts.length) count++;
+ if (count >= onlyHighest) {
+ break;
+ }
+ }
+
+ if (!resultParts.length) {
+ return short ? '<1s' : 'Instant';
+ }
+
+ return resultParts.map(part => {
+ return short ? `${part.value}${part.short}` : `${part.value} ${part.value === 1 ? part.singular : part.plural}`;
+ }).join(short ? ' ' : ', ');
}
/**
diff --git a/public/scripts/personas.js b/public/scripts/personas.js
index 4b9f7ac7..59b62e40 100644
--- a/public/scripts/personas.js
+++ b/public/scripts/personas.js
@@ -35,6 +35,31 @@ function switchPersonaGridView() {
$('#user_avatar_block').toggleClass('gridView', state);
}
+/**
+ * @typedef {object} Persona - A persona
+ * @property {string} id - The id of the persona - currently same as avatar
+ * @property {string} name - The name of the persona
+ * @property {string} avatar - the avatar / avatar id representing the persona
+ * @property {boolean} fav - Whether this persona is favorited
+ * @property {{description: string, position: number}} description - The persona description, containing its text and the position where its placed
+ * */
+
+/**
+ * Builds an object represting the given persona
+ * @param {string} avatar - The avatar id
+ * @returns {Persona} The persona object, wit all its data
+ */
+export function getPersona(avatar) {
+ const persona = {
+ id: avatar,
+ name: power_user.personas[avatar],
+ avatar: avatar,
+ fav: false,
+ description: power_user.persona_descriptions[avatar]
+ };
+ return persona;
+}
+
/**
* Returns the URL of the avatar for the given user avatar Id.
* @param {string} avatarImg User avatar Id
diff --git a/public/scripts/stats.js b/public/scripts/stats.js
index 48983766..03a064bf 100644
--- a/public/scripts/stats.js
+++ b/public/scripts/stats.js
@@ -1,181 +1,522 @@
// statsHelper.js
-import { getRequestHeaders, callPopup, characters, this_chid } from '../script.js';
-import { humanizeGenTime } from './RossAscends-mods.js';
+import { getRequestHeaders, callPopup, characters, this_chid, buildAvatarList, characterToEntity, getOneCharacter, getCharacter, user_avatar, personaToEntity, getCurrentChatId } from '../script.js';
+import { humanizeTimespan } from './RossAscends-mods.js';
+import { getPersona } from './personas.js';
import { registerDebugFunction } from './power-user.js';
+import { humanFileSize, humanizedDuration, parseJson, sensibleRound, smartTruncate } from './utils.js';
-let charStats = {};
+
+/** @typedef {import('../script.js').Character} Character */
+/** @typedef {import('../../src/endpoints/stats.js').UserStatsCollection} UserStatsCollection */
+/** @typedef {import('../../src/endpoints/stats.js').CharacterStats} CharacterStats */
+/** @typedef {import('../../src/endpoints/stats.js').ChatStats} ChatStats */
+/** @typedef {import('../../src/endpoints/stats.js').MessageStats} MessageStats */
+/** @typedef {import('../../src/endpoints/stats.js').StatsRequestBody} StatsRequestBody */
/**
- * Creates an HTML stat block.
- *
- * @param {string} statName - The name of the stat to be displayed.
- * @param {number|string} statValue - The value of the stat to be displayed.
- * @returns {string} - An HTML string representing the stat block.
+ * @typedef {object} AggregateStat
+ * @property {number} count - The number of stats used for this aggregation - used for recalculating avg
+ * @property {number} total - Total / Sum
+ * @property {number} min - Minimum value
+ * @property {number} max - Maximum value
+ * @property {number} avg - Average value
+ * @property {number[]} values - All values listed and saved, so the aggregate stats can be updated if needed when elements get removed
+ * @property {number?} subCount - The number of stats used when this is aggregated over the totals of aggregated stats, meaning based on any amount of sub/inner values
*/
-function createStatBlock(statName, statValue) {
- return `
-
${statName}:
-
${statValue}
+
+/**
+ * @typedef {object} StatField A stat block value to print
+ * @property {any} value - The value to print
+ * @property {boolean} [isHeader=false] - Flag indicating whether this is a header
+ * @property {string|null} [info=null] - Optional text that will be shown as an info icon
+ * @property {string|'info'|null} [title=null] - Optional title for the value - if set to 'info', info will be used as title too
+ * @property {string[]|null} [classes=null] - Optional list of classes for the stat field
+ */
+
+/**
+ * @typedef {object} AggBuildOptions Blah
+ * @property {string | {singular: string, plural: string}} [options.basedOn='chat'] -
+ * @property {string | {singular: string, plural: string}} [options.basedOnSub='message'] -
+ * @property {boolean} [options.excludeTotal=false] - Exclude
+ * @property {((value: *) => string)} [options.transform=null] -
+ */
+
+/** @type {AggBuildOptions} */
+const DEFAULT_AGG_BUILD_OPTIONS = { basedOn: 'chat', basedOnSub: 'message', excludeTotal: false, transform: null };
+
+/**
+ * Gets the fields for an aggregated value
+ * @param {AggregateStat} agg -
+ * @param {AggBuildOptions} [options=DEFAULT_AGG_BUILD_OPTIONS] -
+ * @returns {StatField[]}
+ */
+function aggregateFields(agg, options = DEFAULT_AGG_BUILD_OPTIONS) {
+ options = { ...DEFAULT_AGG_BUILD_OPTIONS, ...options };
+ const basedOn = (typeof options.basedOn !== 'object' || options.basedOn === null) ? { singular: `${options.basedOn}`, plural: `${options.basedOn}s` } : options.basedOn;
+ const basedOnSub = (typeof options.basedOnSub !== 'object' || options.basedOnSub === null) ? { singular: `${options.basedOnSub}`, plural: `${options.basedOnSub}s` } : options.basedOnSub;
+
+ /** @param {*|number} val @param {string} name @returns {StatField} */
+ const build = (val, name) => {
+ // Apply transform and rounding
+ let value = options.transform ? options.transform(val) : val;
+ value = typeof value === 'number' ? sensibleRound(value) : value;
+
+ // Build title tooltip
+ let title = `${name}, based on ${agg.count} ${agg.count !== 1 ? basedOn.plural : basedOn.singular}`
+ if (agg.subCount) title += ` and ${agg.subCount} ${agg.subCount !== 1 ? basedOnSub.plural : basedOnSub.singular}`;
+
+ return { value: value, title: title };
+ };
+ return [options.excludeTotal ? null : build(agg.total, 'Total'), build(agg.min, 'Minimum'), build(agg.avg, 'Average'), build(agg.max, 'Maximum')];
+}
+
+/** Gets the stat field object for any value @param {StatField|any} x @returns {StatField} */
+function statField(x) { return (typeof x === 'object' && x !== null && Object.hasOwn(x, 'value')) ? x : { value: x }; }
+
+/**
+ * Creates an HTML stat block
+ *
+ * @param {StatField|any} name - The name content of the stat to be displayed
+ * @param {StatField[]|any[]} values - Value or values to be listed for the stat block
+ * @returns {string} - An HTML string representing the stat block
+ */
+function createStatBlock(name, ...values) {
+ /** @param {StatField} stat @returns {string} */
+ function buildField(stat) {
+ const classes = ['rm_stat_field', stat.isHeader ? 'rm_stat_header' : '', ...(stat.classes ?? [])].filter(x => x?.length);
+ return `
`;
+ }
+
+ const statName = statField(name);
+ const statValues = values.flat(Infinity).map(statField);
+
+ const isDataRow = !statName.isHeader && !statValues.some(x => x.isHeader);
+ const isRightSpacing = statValues.slice(-1)[0]?.classes?.includes('rm_stat_right_spacing');
+ // Hack right spacing, which is added via a value just having the class
+ if (isRightSpacing) {
+ statValues.pop();
+ }
+
+ const classes = ['rm_stat_block', isDataRow ? 'rm_stat_block_data_row' : null, isRightSpacing ? 'rm_stat_right_spacing' : null].filter(x => x?.length);
+ return `
+
${buildField(statName)}
+
${statValues.map(x => buildField(x)).join('')}
`;
}
/**
- * Verifies and returns a numerical stat value. If the provided stat is not a number, returns 0.
- *
- * @param {number|string} stat - The stat value to be checked and returned.
- * @returns {number} - The stat value if it is a number, otherwise 0.
+ * Show the stats popup for a given stats report
+ * @param {string} html - The html report that should be shown in the popup
*/
-function verifyStatValue(stat) {
- return isNaN(Number(stat)) ? 0 : Number(stat);
+function showStatsPopup(html) {
+ callPopup(html, 'text', '', { wider: true, allowVerticalScrolling: true });
}
-/**
- * Calculates total stats from character statistics.
- *
- * @returns {Object} - Object containing total statistics.
- */
-function calculateTotalStats() {
- let totalStats = {
- total_gen_time: 0,
- user_msg_count: 0,
- non_user_msg_count: 0,
- user_word_count: 0,
- non_user_word_count: 0,
- total_swipe_count: 0,
- date_last_chat: 0,
- date_first_chat: new Date('9999-12-31T23:59:59.999Z').getTime(),
- };
-
- for (let stats of Object.values(charStats)) {
- totalStats.total_gen_time += verifyStatValue(stats.total_gen_time);
- totalStats.user_msg_count += verifyStatValue(stats.user_msg_count);
- totalStats.non_user_msg_count += verifyStatValue(
- stats.non_user_msg_count,
- );
- totalStats.user_word_count += verifyStatValue(stats.user_word_count);
- totalStats.non_user_word_count += verifyStatValue(
- stats.non_user_word_count,
- );
- totalStats.total_swipe_count += verifyStatValue(
- stats.total_swipe_count,
- );
-
- if (verifyStatValue(stats.date_last_chat) != 0) {
- totalStats.date_last_chat = Math.max(
- totalStats.date_last_chat,
- stats.date_last_chat,
- );
- }
- if (verifyStatValue(stats.date_first_chat) != 0) {
- totalStats.date_first_chat = Math.min(
- totalStats.date_first_chat,
- stats.date_first_chat,
- );
- }
- }
-
- return totalStats;
-}
+const HMTL_STAT_SPACER = '';
+const VAL_RIGHT_SPACING = { value: null, classes: ['rm_stat_right_spacing'] };
+const BASED_ON_MES_PLUS_SWIPE = { singular: 'message and its swipes', plural: 'messages and their swipes' };
+const HOVER_TOOLTIP_SUFFIX = '\n\nHover over any value to see what it is based on.';
+const GEN_TOKEN_WARNING = '(Token count is only correct, if setting \'Message Token Count\' was turned on during generation)';
/**
- * Generates an HTML report of stats.
+ * Generates an HTML report of character stats ("User" or "Character")
*
- * This function creates an HTML report from the provided stats, including chat age,
- * chat time, number of user messages and character messages, word count, and swipe count.
- * The stat blocks are tailored depending on the stats type ("User" or "Character").
- *
- * @param {string} statsType - The type of stats (e.g., "User", "Character").
- * @param {Object} stats - The stats data. Expected keys in this object include:
- * total_gen_time - total generation time
- * date_first_chat - timestamp of the first chat
- * date_last_chat - timestamp of the most recent chat
- * user_msg_count - count of user messages
- * non_user_msg_count - count of non-user messages
- * user_word_count - count of words used by the user
- * non_user_word_count - count of words used by the non-user
- * total_swipe_count - total swipe count
+ * @param {'user'|'character'} statsType - The type of stats (e.g., "User", "Character")
+ * @param {CharacterStats} stats - The stats data
+ * @returns {string} The html
*/
-function createHtml(statsType, stats) {
- // Get time string
- let timeStirng = humanizeGenTime(stats.total_gen_time);
- let chatAge = 'Never';
- if (stats.date_first_chat < Date.now()) {
- chatAge = moment
- .duration(stats.date_last_chat - stats.date_first_chat)
- .humanize();
- }
+function createCharacterStatsHtml(statsType, stats) {
+ const NOW = Date.now();
+ const isChar = statsType === 'character';
+
+ // some pre calculations
+ const mostUsedModel = findHighestModel(stats.genModels);
+ const charactersCount = !isChar ? (new Set(stats.chatsStats.map(x => x.charName))).size : null;
+
+ let subHeader = (() => {
+ switch (statsType) {
+ case 'character': return `Overall character stats based on all chats for ${stats.charName}`;
+ case 'user': return `Global stats based on all chats of ${charactersCount} characters`;
+ default: return '';
+ };
+ })();
// Create popup HTML with stats
- let html = `
${statsType} Stats
`;
- if (statsType === 'User') {
- html += createStatBlock('Chatting Since', `${chatAge} ago`);
- } else {
- html += createStatBlock('First Interaction', `${chatAge} ago`);
- }
- html += createStatBlock('Chat Time', timeStirng);
- html += createStatBlock('User Messages', stats.user_msg_count);
- html += createStatBlock(
- 'Character Messages',
- stats.non_user_msg_count - stats.total_swipe_count,
- );
- html += createStatBlock('User Words', stats.user_word_count);
- html += createStatBlock('Character Words', stats.non_user_word_count);
- html += createStatBlock('Swipes', stats.total_swipe_count);
+ let html = `
`;
+ html += `${subHeader}`;
- callPopup(html, 'text');
+ // Overview
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: isChar ? 'Character Overview' : 'Overview', isHeader: true });
+ html += createStatBlock({ value: 'Chats', info: `Number of existing chats with ${stats.charName}\nFor the sake of statistics, Branches count as chats and all their messages will be included.` },
+ stats.chats, VAL_RIGHT_SPACING);
+ html += createStatBlock({ value: 'File Size', info: 'Chat file sizes on disk calculated and summed\nThis value might not represent the exact same value your operating system uses.' },
+ humanFileSize(stats.chatSize), VAL_RIGHT_SPACING);
+ html += createStatBlock({ value: 'Most Used Model', info: 'Most used model for generations, both messages and swipes\n(Does not include internal generation commands like /gen or /impersonate)\n\nHover over the value to see the numbers behind.' },
+ { value: smartTruncate(mostUsedModel.model, 32), title: 'info', info: `${mostUsedModel.model}\nUsed ${mostUsedModel.count} times to generate ${mostUsedModel.tokens} tokens\n\n${GEN_TOKEN_WARNING}` }, VAL_RIGHT_SPACING);
+
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock('',
+ { value: 'First', isHeader: true, info: `Data corresponding to the first chat with ${stats.charName}`, title: 'info' },
+ { value: 'Last', isHeader: true, info: `Data corresponding to the last chat with ${stats.charName}`, title: 'info' },
+ VAL_RIGHT_SPACING,
+ );
+ html += createStatBlock({ value: 'New Chat', info: 'First/Last time when a new chat was started' },
+ { value: humanizedDuration(stats.firstCreateDate, NOW, { wrapper: x => `${x} ago` }), title: stats.firstCreateDate },
+ { value: humanizedDuration(stats.lastCreateDate, NOW, { wrapper: x => `${x} ago` }), title: stats.lastCreateDate },
+ VAL_RIGHT_SPACING,
+ );
+ html += createStatBlock({ value: 'Chat Ended', info: 'First/Last time when the interaction was done in a chat' },
+ { value: humanizedDuration(stats.firstlastInteractionDate, NOW, { wrapper: x => `${x} ago` }), title: stats.firstlastInteractionDate },
+ { value: humanizedDuration(stats.lastLastInteractionDate, NOW, { wrapper: x => `${x} ago` }), title: stats.lastLastInteractionDate },
+ VAL_RIGHT_SPACING,
+ );
+
+ // Aggregated Stats
+ html += HMTL_STAT_SPACER;
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Aggregated Stats', isHeader: true, info: 'Values per chat, aggregated over all chats\n\n • Total: Total summed value over all chats\n • Min: Minium value for any chat\n • Avg: Average value over all chats\n • Max: Maximum value for any chat' });
+ html += createStatBlock(null,
+ { value: 'Total', isHeader: true, info: 'Total summed value over all chats', title: 'info' },
+ { value: 'Min', isHeader: true, info: 'Minium value for any chat', title: 'info' },
+ { value: 'Avg', isHeader: true, info: 'Average value over all chats', title: 'info' },
+ { value: 'Max', isHeader: true, info: 'Maximum value for any chat', title: 'info' }
+ );
+ html += createStatBlock({ value: 'Chatting Time', info: 'Chatting time per chat\nCalculated based on chat creation and the last interaction in that chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.chattingTime, { transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Generation Time', info: 'Generation time per chat\nSummed generation times of all messages and swipes.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.genTime, { basedOnSub: BASED_ON_MES_PLUS_SWIPE, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Generated Tokens', info: `Generated tokens per chat\nSummed token counts of all messages and swipes.\n${GEN_TOKEN_WARNING}` + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.genTokenCount, { basedOnSub: BASED_ON_MES_PLUS_SWIPE }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Swiping Time', info: 'Swiping time per chat\nSummed time spend on generation alternative swipes. Excludes the final message that was chosen to continue the chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.swipeGenTime, { basedOnSub: BASED_ON_MES_PLUS_SWIPE, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Swipes', info: 'Swipes per chat\nCounts all generated messages/swipes that were not chosen to continue the chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.swipes, { basedOnSub: BASED_ON_MES_PLUS_SWIPE }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'User Response Time', info: 'User response time per chat\nCalculated based on the time between the last action of the message before and the next user message.\nAs \'action\' counts both the message send time and when the last generation of it ended, even if that swipe wasn\'t chosen.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.userResponseTime, { transform: time => humanizeTimespan(time, { short: true }) }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Messages', info: 'Messages per chat (excluding swipes)' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.messages));
+ html += createStatBlock({ value: 'System Messages', info: 'Sytem messages per chat' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.systemMessages));
+ html += createStatBlock({ value: 'Messages (User / Char)', classes: ['rm_stat_field_smaller'], info: 'Messages per chat (excluding swipes)\nSplit into user and character, and showing a bar graph with percentages.' + HOVER_TOOLTIP_SUFFIX },
+ ...buildBarDescsFromAggregates(stats.userMessages, stats.charMessages));
+ html += createStatBlock({ value: '', info: '' },
+ ...buildBarsFromAggregates(stats.userName, stats.userMessages, stats.charName, stats.charMessages));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Words', info: 'Word count per chat (excluding swipes)' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.words));
+ html += createStatBlock({ value: 'Words (User / Char)', classes: ['rm_stat_field_smaller'], info: 'Word count per chat (excluding swipes)\nSplit into user and character, and showing a bar graph with percentages.' + HOVER_TOOLTIP_SUFFIX },
+ ...buildBarDescsFromAggregates(stats.userWords, stats.charWords));
+ html += createStatBlock({ value: '', info: '' },
+ ...buildBarsFromAggregates(stats.userName, stats.userWords, stats.charName, stats.charWords));
+
+ // Per Message Stats
+ html += HMTL_STAT_SPACER;
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Per Message Stats', isHeader: true, info: 'Values per message, aggregated over all chats\n\n • Min: Minium value for any message\n • Avg: Average value over all messages\n • Max: Maximum value for any message' });
+ html += createStatBlock('',
+ null,
+ { value: 'Min', isHeader: true, info: 'Minium value for any message', title: 'info' },
+ { value: 'Avg', isHeader: true, info: 'Average value over all messages', title: 'info' },
+ { value: 'Max', isHeader: true, info: 'Maximum value for any message', title: 'info' }
+ );
+ html += createStatBlock({ value: 'Generation Time', info: 'Generation time per message\nSummed generation times of the message and all swipes.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.perMessageGenTime, { basedOn: BASED_ON_MES_PLUS_SWIPE, excludeTotal: true, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Generated Tokens', info: `Generated tokens per message\nSummed token counts of the message and all swipes.\n${GEN_TOKEN_WARNING}` + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.perMessageGenTokenCount, { basedOn: BASED_ON_MES_PLUS_SWIPE, excludeTotal: true }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Swiping Time', info: 'Swiping time per message\nSummed time spend on generation alternative swipes. Excludes the final message that was chosen to continue the chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.perMessageSwipeGenTime, { basedOn: BASED_ON_MES_PLUS_SWIPE, excludeTotal: true, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Swipes', info: 'Swipes per message\nCounts all generated messages/swipes that were not chosen to continue the chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.perMessageSwipeCount, { basedOn: BASED_ON_MES_PLUS_SWIPE, excludeTotal: true }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'User Response Time', info: 'User response time per message\nCalculated based on the time between the last action of the message before and the next user message.\nAs \'action\' counts both the message send time and when the last generation of it ended, even if that swipe wasn\'t chosen.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.perMessageUserResponseTime, { basedOn: 'message', excludeTotal: true, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Words', info: 'Word count per message (excluding swipes)' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.perMessageWords, { basedOn: 'message', excludeTotal: true }));
+ html += createStatBlock({ value: 'Words (User / Char)', classes: ['rm_stat_field_smaller'], info: 'Word count per message (excluding swipes)\nSplit into user and character, and showing a bar graph with percentages.' + HOVER_TOOLTIP_SUFFIX },
+ ...buildBarDescsFromAggregates(stats.perMessageUserWords, stats.perMessageCharWords, { basedOn: 'message', excludeTotal: true }));
+ html += createStatBlock({ value: '', info: '' },
+ ...buildBarsFromAggregates(stats.userName, stats.perMessageUserWords, stats.charName, stats.perMessageCharWords, { basedOn: 'message', excludeTotal: true }));
+
+ html += HMTL_STAT_SPACER;
+ html += ``;
+
+ const avatarBlock = buildAvatarBlock(statsType == 'character' ? stats.characterKey : null);
+ if (avatarBlock) {
+ html = avatarBlock + html;
+ }
+
+ return html;
+}
+
+/**
+ * Generates an HTML report of chat stats
+ *
+ * @param {ChatStats} stats - The stats data
+ * @returns {string} The html
+ */
+function createChatStatsHtml(stats) {
+ const NOW = Date.now();
+
+ // some pre calculations
+ const mostUsedModel = findHighestModel(stats.genModels);
+
+ // Create popup HTML with stats
+ let html = `
Chat Stats
`;
+ html += `Chat stats for chat '${stats.chatName}' `;
+
+ // Chat Overview
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Chat Overview', isHeader: true });
+ html += createStatBlock({ value: 'File Size', info: 'Chat file size on disk\nThis value might not represent the exact same value your operating system uses.' },
+ humanFileSize(stats.chatSize), VAL_RIGHT_SPACING);
+ html += createStatBlock({ value: 'Most Used Model', info: 'Most used model for generations, both messages and swipes\n(Does not include internal generation commands like /gen or /impersonate)\n\nHover over the value to see the numbers behind.' },
+ { value: smartTruncate(mostUsedModel.model, 32), title: 'info', info: `${mostUsedModel.model}\nUsed ${mostUsedModel.count} times to generate ${mostUsedModel.tokens} tokens\n\n${GEN_TOKEN_WARNING}` }, VAL_RIGHT_SPACING);
+
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Chat Created', info: 'Time when this chat was created' },
+ { value: humanizedDuration(stats.createDate, NOW, { wrapper: x => `${x} ago` }), title: stats.createDate }, VAL_RIGHT_SPACING);
+ html += createStatBlock({ value: 'Chat Ended', info: 'Time when the last interaction was done in this chat' },
+ { value: humanizedDuration(stats.lastInteractionDate, NOW, { wrapper: x => `${x} ago` }), title: stats.lastInteractionDate }, VAL_RIGHT_SPACING);
+
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Chatting Time', info: 'Chatting time in this chat\nCalculated based on chat creation and the last interaction in that chat.' },
+ humanizeTimespan(stats.chattingTime, { short: true }), VAL_RIGHT_SPACING);
+
+ // Chat Details
+ html += HMTL_STAT_SPACER;
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Chat Details', isHeader: true });
+ html += createStatBlock(null,
+ { value: 'Messages', isHeader: true, info: 'Messages in this chat (excluding swipes)', title: 'info' },
+ { value: 'Words', isHeader: true, info: 'Words in this chat (excluding swipes)', title: 'info' }
+ );
+ html += createStatBlock({ value: 'Total', info: 'Messages/words in this chat (excluding swipes)' },
+ stats.messages, stats.words.total);
+ html += createStatBlock({ value: 'System', info: 'Sytem messages in this chat (not counted for words)' },
+ stats.systemMessages, '-');
+ html += createStatBlock({ value: '(User / Char)', classes: ['rm_stat_field_smaller'], info: 'Messages/words in this chat (excluding swipes)\nSplit into user and character, and showing a bar graph with percentages.' },
+ ...buildBarDescs(stats.userMessages, stats.charMessages), ...buildBarDescs(stats.userWords.total, stats.charWords.total));
+ html += createStatBlock({ value: '', info: '' },
+ buildBar(stats.userName, stats.userMessages, stats.charName, stats.charMessages), buildBar(stats.userName, stats.userWords.total, stats.charName, stats.charWords.total));
+
+ // Aggregated Stats
+ html += HMTL_STAT_SPACER;
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Aggregated Stats', isHeader: true, info: 'Values aggregated over this chat, per message\n\n • Total: Total summed value over this chat\n • Min: Minium value for any message\n • Avg: Average value over all messages\n • Max: Maximum value for any message' });
+ html += createStatBlock('',
+ { value: 'Total', isHeader: true, info: 'Total summed value for this chat', title: 'info' },
+ { value: 'Min', isHeader: true, info: 'Minium value for any message', title: 'info' },
+ { value: 'Avg', isHeader: true, info: 'Average value over all messages', title: 'info' },
+ { value: 'Max', isHeader: true, info: 'Maximum value for any message', title: 'info' }
+ );
+ html += createStatBlock({ value: 'Generation Time', info: 'Generation time per message\nSummed generation times of the message and all swipes.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.genTime, { basedOn: BASED_ON_MES_PLUS_SWIPE, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Generated Tokens', info: `Generated tokens per message\nSummed token counts of the message and all swipes.\n${GEN_TOKEN_WARNING}` + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.genTokenCount, { basedOn: BASED_ON_MES_PLUS_SWIPE }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Swiping Time', info: 'Swiping time per message\nSummed time spend on generation alternative swipes. Excludes the final message that was chosen to continue the chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.swipeGenTime, { basedOn: BASED_ON_MES_PLUS_SWIPE, transform: time => humanizeTimespan(time, { short: true }) }));
+ html += createStatBlock({ value: 'Swipes', info: 'Swipes per message\nCounts all generated messages/swipes that were not chosen to continue the chat.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.swipes, { basedOn: BASED_ON_MES_PLUS_SWIPE }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'User Response Time', info: 'User response time per message\nCalculated based on the time between the last action of the message before and the next user message.\nAs \'action\' counts both the message send time and when the last generation of it ended, even if that swipe wasn\'t chosen.' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.userResponseTime, { basedOn: 'message', transform: time => humanizeTimespan(time, { short: true }) }));
+ html += HMTL_STAT_SPACER;
+ html += createStatBlock({ value: 'Words', info: 'Word count per message (excluding swipes)' + HOVER_TOOLTIP_SUFFIX },
+ ...aggregateFields(stats.words, { basedOn: 'message' }));
+ html += createStatBlock({ value: 'Words (User / Char)', classes: ['rm_stat_field_smaller'], info: 'Word count per message (excluding swipes)\nSplit into user and character, and showing a bar graph with percentages.' + HOVER_TOOLTIP_SUFFIX },
+ ...buildBarDescsFromAggregates(stats.userWords, stats.charWords, { basedOn: 'message' }));
+ html += createStatBlock({ value: '', info: '' },
+ ...buildBarsFromAggregates(stats.userName, stats.userWords, stats.charName, stats.charWords, { basedOn: 'message' }));
+
+ html += HMTL_STAT_SPACER;
+ html += ``;
+
+ const avatarBlock = buildAvatarBlock(stats.characterKey);
+ if (avatarBlock) {
+ html = avatarBlock + html;
+ }
+
+ return html;
+}
+
+/** Builds the avatar block for a given character, or user avatar if none is given. @param {string?} [characterKey=null] @returns {string} */
+function buildAvatarBlock(characterKey = null) {
+ // Hijack avatar list function to draw the user avatar
+ let entity = null;
+ if (characterKey) {
+ const character = getCharacter(characterKey);
+ const cid = characters.indexOf(x => x === character);
+ entity = characterToEntity(character, cid);
+ } else {
+ const persona = getPersona(user_avatar);
+ entity = personaToEntity(persona);
+ }
+ if (entity) {
+ const placeHolder = $('');
+ buildAvatarList(placeHolder, [entity]);
+ return placeHolder.prop('outerHTML');
+ }
+ return '';
+}
+
+/**
+ * Finds the model with the highest count and returns its name and values.
+ *
+ * @param {{[model: string]: { count: number, tokens: number }}} genModels - Object containing model usages
+ * @returns {{ model: string, count: number, tokens: number }} - Object containing the name and values of the model with the highest count
+ */
+function findHighestModel(genModels) {
+ return Object.entries(genModels).reduce((acc, [model, values]) => {
+ return values.count > acc.count ? { model: model, count: values.count, tokens: values.tokens } : acc;
+ }, { model: '', count: 0, tokens: 0 });
+}
+
+/** @param {string} userName @param {AggregateStat} aggUser @param {string} charName @param {AggregateStat} aggChar @param {AggBuildOptions} options @returns {StatField[]} */
+function buildBarsFromAggregates(userName, aggUser, charName, aggChar, options = DEFAULT_AGG_BUILD_OPTIONS) {
+ options = { ...DEFAULT_AGG_BUILD_OPTIONS, ...options };
+ const fUser = aggregateFields(aggUser, options);
+ const fChar = aggregateFields(aggChar, options);
+ const bars = fUser.map((_, i) => buildBar(userName, fUser[i]?.value, charName, fChar[i]?.value));
+ return bars;
+}
+/** @param {string} userName @param {number} userVal @param {string} charName @param {number} charVal @returns {StatField} */
+function buildBar(userName, userVal, charName, charVal) {
+ const percentUser = (userVal / (userVal + charVal)) * 100;
+ const percentChar = 100 - percentUser;
+ const bar = `
+
+
+
`;
+ return statField(bar);
+}
+/** @param {AggregateStat} agg1 @param {AggregateStat} agg2 @param {AggBuildOptions} options @returns {StatField[]} */
+function buildBarDescsFromAggregates(agg1, agg2, options = DEFAULT_AGG_BUILD_OPTIONS) {
+ options = { ...DEFAULT_AGG_BUILD_OPTIONS, ...options };
+ const f1 = aggregateFields(agg1, options);
+ const f2 = aggregateFields(agg2, options);
+ const values = [f1[0], f2[0], f1[1], f2[1], f1[2], f2[2], f1[3], f2[3]];
+ return buildBarDescs(values);
+}
+/** @param {any[]} values @returns {StatField[]} */
+function buildBarDescs(...values) {
+ return values.flat(Infinity).map(statField).map((x, i) => i % 2 == 0 ? { classes: [...(x.classes ?? []), 'rm_stat_field_lefty'], ...x } : x);
}
/**
* Handles the user stats by getting them from the server, calculating the total and generating the HTML report.
*/
-async function userStatsHandler() {
+export async function showUserStatsPopup() {
// Get stats from server
- await getStats();
-
- // Calculate total stats
- let totalStats = calculateTotalStats();
+ const userStats = await getUserStats();
// Create HTML with stats
- createHtml('User', totalStats);
+ const html = createCharacterStatsHtml('user', userStats);
+ showStatsPopup(html);
}
/**
* Handles the character stats by getting them from the server and generating the HTML report.
*
- * @param {Object} characters - Object containing character data.
- * @param {string} this_chid - The character id.
+ * @param {string} characterKey - The character key for the character to request stats from
*/
-async function characterStatsHandler(characters, this_chid) {
+export async function showCharacterStatsPopup(characterKey) {
// Get stats from server
- await getStats();
- // Get character stats
- let myStats = charStats[characters[this_chid].avatar];
- if (myStats === undefined) {
- myStats = {
- total_gen_time: 0,
- user_msg_count: 0,
- non_user_msg_count: 0,
- user_word_count: 0,
- non_user_word_count: countWords(characters[this_chid].first_mes),
- total_swipe_count: 0,
- date_last_chat: 0,
- date_first_chat: new Date('9999-12-31T23:59:59.999Z').getTime(),
- };
- charStats[characters[this_chid].avatar] = myStats;
- updateStats();
+ const charStats = await getCharacterStats(characterKey);
+ if (charStats === null) {
+ toastr.info(`No stats exist for character ${getCharacter(characterKey)?.name}.`);
+ return;
}
+
// Create HTML with stats
- createHtml('Character', myStats);
+ const html = createCharacterStatsHtml('character', charStats);
+ showStatsPopup(html);
+}
+
+/**
+ * Handles the chats stats by getting them from the server and generating the HTML report.
+ *
+ * @param {string} characterKey - The character key for the character to request stats from
+ * @param {string} chatName - The name of the chat file
+ */
+export async function showChatStatsPopup(characterKey, chatName) {
+ // Get stats from server
+ const chatStats = await getChatStats(characterKey, chatName);
+ if (chatStats === null) {
+ toastr.info(`No stats exist for chat '${chatName}' with character ${getCharacter(characterKey)?.name}.`);
+ return;
+ }
+
+ // Create HTML with stats
+ const html = createChatStatsHtml(chatStats);
+ showStatsPopup(html);
+}
+
+/**
+ * Fetches the user stats (global stats) from the server.
+ * @returns {Promise}
+ */
+async function getUserStats() {
+ const stats = await callGetStats({ global: true });
+ return stats;
+}
+
+/**
+ * Fetches the char stats for a specific character from the server.
+ * @param {string} characterKey - The character key for the character to request stats from
+ * @returns {Promise}
+ */
+async function getCharacterStats(characterKey) {
+ const stats = await callGetStats({ characterKey: characterKey });
+ return stats;
+}
+
+/**
+ * Fetches the chat stats for a specific character chat from the server.
+ * @param {string} characterKey - The character key for the character to request stats from
+ * @param {string} chatName - The name of the chat file
+ * @returns {Promise}
+ */
+async function getChatStats(characterKey, chatName) {
+ const stats = await callGetStats({ characterKey: characterKey, chatName: chatName });
+ return stats;
+}
+
+/**
+ * Fetches the full stat collection from the server.
+ * @returns {Promise}
+ */
+async function getFullStatsCollection() {
+ const stats = await callGetStats();
+ return stats;
}
/**
* Fetches the character stats from the server.
+ * For retrieving, use the more specific functions `getCharacterStats`, `getUserStats`, `getChatStats` and `getFullStatsCollection`.
+ * @param {StatsRequestBody} [params={}] Optional parameter for the get request
+ * @returns {Promise