mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Require single quotes
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
// statsHelper.js
|
||||
import { getRequestHeaders, callPopup, characters, this_chid } from "../script.js";
|
||||
import { humanizeGenTime } from "./RossAscends-mods.js";
|
||||
import {registerDebugFunction,} from "./power-user.js";
|
||||
import { getRequestHeaders, callPopup, characters, this_chid } from '../script.js';
|
||||
import { humanizeGenTime } from './RossAscends-mods.js';
|
||||
import {registerDebugFunction,} from './power-user.js';
|
||||
|
||||
let charStats = {};
|
||||
|
||||
@ -43,7 +43,7 @@ function calculateTotalStats() {
|
||||
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(),
|
||||
date_first_chat: new Date('9999-12-31T23:59:59.999Z').getTime(),
|
||||
};
|
||||
|
||||
for (let stats of Object.values(charStats)) {
|
||||
@ -98,7 +98,7 @@ function calculateTotalStats() {
|
||||
function createHtml(statsType, stats) {
|
||||
// Get time string
|
||||
let timeStirng = humanizeGenTime(stats.total_gen_time);
|
||||
let chatAge = "Never";
|
||||
let chatAge = 'Never';
|
||||
if (stats.date_first_chat < Date.now()) {
|
||||
chatAge = moment
|
||||
.duration(stats.date_last_chat - stats.date_first_chat)
|
||||
@ -107,22 +107,22 @@ function createHtml(statsType, stats) {
|
||||
|
||||
// Create popup HTML with stats
|
||||
let html = `<h3>${statsType} Stats</h3>`;
|
||||
if (statsType === "User") {
|
||||
html += createStatBlock("Chatting Since", `${chatAge} ago`);
|
||||
if (statsType === 'User') {
|
||||
html += createStatBlock('Chatting Since', `${chatAge} ago`);
|
||||
} else {
|
||||
html += createStatBlock("First Interaction", `${chatAge} ago`);
|
||||
html += createStatBlock('First Interaction', `${chatAge} ago`);
|
||||
}
|
||||
html += createStatBlock("Chat Time", timeStirng);
|
||||
html += createStatBlock("User Messages", stats.user_msg_count);
|
||||
html += createStatBlock('Chat Time', timeStirng);
|
||||
html += createStatBlock('User Messages', stats.user_msg_count);
|
||||
html += createStatBlock(
|
||||
"Character Messages",
|
||||
'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);
|
||||
html += createStatBlock('User Words', stats.user_word_count);
|
||||
html += createStatBlock('Character Words', stats.non_user_word_count);
|
||||
html += createStatBlock('Swipes', stats.total_swipe_count);
|
||||
|
||||
callPopup(html, "text");
|
||||
callPopup(html, 'text');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,7 +138,7 @@ async function userStatsHandler() {
|
||||
let totalStats = calculateTotalStats(charStats);
|
||||
|
||||
// Create HTML with stats
|
||||
createHtml("User", totalStats);
|
||||
createHtml('User', totalStats);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,13 +162,13 @@ async function characterStatsHandler(characters, this_chid) {
|
||||
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(),
|
||||
date_first_chat: new Date('9999-12-31T23:59:59.999Z').getTime(),
|
||||
};
|
||||
charStats[characters[this_chid].avatar] = myStats;
|
||||
updateStats();
|
||||
}
|
||||
// Create HTML with stats
|
||||
createHtml("Character", myStats);
|
||||
createHtml('Character', myStats);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,16 +178,16 @@ async function characterStatsHandler(characters, this_chid) {
|
||||
* @returns {Object} - Object containing fetched character statistics.
|
||||
*/
|
||||
async function getStats() {
|
||||
const response = await fetch("/getstats", {
|
||||
method: "POST",
|
||||
const response = await fetch('/getstats', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({}),
|
||||
cache: "no-cache",
|
||||
cache: 'no-cache',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
toastr.error("Stats could not be loaded. Try reloading the page.");
|
||||
throw new Error("Error getting stats");
|
||||
toastr.error('Stats could not be loaded. Try reloading the page.');
|
||||
throw new Error('Error getting stats');
|
||||
}
|
||||
charStats = await response.json();
|
||||
}
|
||||
@ -201,19 +201,19 @@ async function getStats() {
|
||||
* @throws {Error} If the request to recreate stats is unsuccessful.
|
||||
*/
|
||||
async function recreateStats() {
|
||||
const response = await fetch("/recreatestats", {
|
||||
method: "POST",
|
||||
const response = await fetch('/recreatestats', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify({}),
|
||||
cache: "no-cache",
|
||||
cache: 'no-cache',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
toastr.error("Stats could not be loaded. Try reloading the page.");
|
||||
throw new Error("Error getting stats");
|
||||
toastr.error('Stats could not be loaded. Try reloading the page.');
|
||||
throw new Error('Error getting stats');
|
||||
}
|
||||
else {
|
||||
toastr.success("Stats file recreated successfully!");
|
||||
toastr.success('Stats file recreated successfully!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,14 +240,14 @@ function calculateGenTime(gen_started, gen_finished) {
|
||||
* @param {Object} stats - The stats data to update.
|
||||
*/
|
||||
async function updateStats() {
|
||||
const response = await fetch("/updatestats", {
|
||||
method: "POST",
|
||||
const response = await fetch('/updatestats', {
|
||||
method: 'POST',
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify(charStats),
|
||||
});
|
||||
|
||||
if (response.status !== 200) {
|
||||
console.error("Failed to update stats");
|
||||
console.error('Failed to update stats');
|
||||
console.log(response).status;
|
||||
}
|
||||
}
|
||||
@ -299,38 +299,38 @@ async function statMesProcess(line, type, characters, this_chid, oldMesssage) {
|
||||
line.gen_finished
|
||||
);
|
||||
if (line.is_user) {
|
||||
if (type != "append" && type != "continue" && type != "appendFinal") {
|
||||
if (type != 'append' && type != 'continue' && type != 'appendFinal') {
|
||||
stat.user_msg_count++;
|
||||
stat.user_word_count += countWords(line.mes);
|
||||
} else {
|
||||
let oldLen = oldMesssage.split(" ").length;
|
||||
let oldLen = oldMesssage.split(' ').length;
|
||||
stat.user_word_count += countWords(line.mes) - oldLen;
|
||||
}
|
||||
} else {
|
||||
// if continue, don't add a message, get the last message and subtract it from the word count of
|
||||
// the new message
|
||||
if (type != "append" && type != "continue" && type != "appendFinal") {
|
||||
if (type != 'append' && type != 'continue' && type != 'appendFinal') {
|
||||
stat.non_user_msg_count++;
|
||||
stat.non_user_word_count += countWords(line.mes);
|
||||
} else {
|
||||
let oldLen = oldMesssage.split(" ").length;
|
||||
let oldLen = oldMesssage.split(' ').length;
|
||||
stat.non_user_word_count += countWords(line.mes) - oldLen;
|
||||
}
|
||||
}
|
||||
|
||||
if (type === "swipe") {
|
||||
if (type === 'swipe') {
|
||||
stat.total_swipe_count++;
|
||||
}
|
||||
stat.date_last_chat = Date.now();
|
||||
stat.date_first_chat = Math.min(
|
||||
stat.date_first_chat ?? new Date("9999-12-31T23:59:59.999Z").getTime(),
|
||||
stat.date_first_chat ?? new Date('9999-12-31T23:59:59.999Z').getTime(),
|
||||
Date.now()
|
||||
);
|
||||
updateStats();
|
||||
}
|
||||
|
||||
export function initStats() {
|
||||
$(".rm_stats_button").on('click', function () {
|
||||
$('.rm_stats_button').on('click', function () {
|
||||
characterStatsHandler(characters, this_chid);
|
||||
});
|
||||
// Wait for debug functions to load, then add the refresh stats function
|
||||
|
Reference in New Issue
Block a user