mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Change the way we count non-user msgs
This commit is contained in:
@@ -1309,7 +1309,7 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
|
|||||||
const momentDate = timestampToMoment(mes.send_date);
|
const momentDate = timestampToMoment(mes.send_date);
|
||||||
const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : '';
|
const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : '';
|
||||||
|
|
||||||
statMesProcess(mes, type);
|
|
||||||
|
|
||||||
|
|
||||||
if (mes?.extra?.display_text) {
|
if (mes?.extra?.display_text) {
|
||||||
@@ -3712,15 +3712,17 @@ function calculateGenTime(gen_started, gen_finished) {
|
|||||||
return endDate - startDate;
|
return endDate - startDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStats() {
|
async function updateStats() {
|
||||||
const response = fetch('/updatestats', {
|
const response = await fetch('/updatestats', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify(charStats),
|
body: JSON.stringify(charStats),
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
console.error('Failed to update stats');
|
console.error('Failed to update stats');
|
||||||
|
console.log(response).status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3756,7 +3758,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
chat[chat.length - 1]['is_user'])) {
|
chat[chat.length - 1]['is_user'])) {
|
||||||
type = 'normal';
|
type = 'normal';
|
||||||
}
|
}
|
||||||
console.log(chat);
|
|
||||||
const generationFinished = new Date();
|
const generationFinished = new Date();
|
||||||
const img = extractImageFromMessage(getMessage);
|
const img = extractImageFromMessage(getMessage);
|
||||||
getMessage = img.getMessage;
|
getMessage = img.getMessage;
|
||||||
@@ -3852,6 +3854,7 @@ function saveReply(type, getMessage, this_mes_is_name, title) {
|
|||||||
extra: JSON.parse(JSON.stringify(chat[chat.length - 1]["extra"])),
|
extra: JSON.parse(JSON.stringify(chat[chat.length - 1]["extra"])),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
statMesProcess(chat[chat.length - 1], type);
|
||||||
return { type, getMessage };
|
return { type, getMessage };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,6 +13,7 @@ import {
|
|||||||
menu_type,
|
menu_type,
|
||||||
max_context,
|
max_context,
|
||||||
saveSettingsDebounced,
|
saveSettingsDebounced,
|
||||||
|
charStats,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
|
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ const observer = new MutationObserver(function (mutations) {
|
|||||||
RA_checkOnlineStatus();
|
RA_checkOnlineStatus();
|
||||||
} else if (mutation.target.parentNode === SelectedCharacterTab) {
|
} else if (mutation.target.parentNode === SelectedCharacterTab) {
|
||||||
setTimeout(RA_CountCharTokens, 200);
|
setTimeout(RA_CountCharTokens, 200);
|
||||||
|
setTimeout(AA_CountCharTime, 200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -107,8 +109,9 @@ function waitForElement(querySelector, timeout) {
|
|||||||
|
|
||||||
//humanize character generation time
|
//humanize character generation time
|
||||||
export function humanizeGenTime(character) {
|
export function humanizeGenTime(character) {
|
||||||
|
let stat = charStats[character.avatar]
|
||||||
//convert time_spent to humanized format of "_ Hours, _ Minutes, _ Seconds" from milliseconds
|
//convert time_spent to humanized format of "_ Hours, _ Minutes, _ Seconds" from milliseconds
|
||||||
let time_spent = character.total_gen_time
|
let time_spent = stat.total_gen_time
|
||||||
time_spent = Math.floor(time_spent / 1000);
|
time_spent = Math.floor(time_spent / 1000);
|
||||||
let seconds = time_spent % 60;
|
let seconds = time_spent % 60;
|
||||||
time_spent = Math.floor(time_spent / 60);
|
time_spent = Math.floor(time_spent / 60);
|
||||||
@@ -144,8 +147,9 @@ export function AA_CountCharTime(chid){
|
|||||||
//get character stats from the server
|
//get character stats from the server
|
||||||
|
|
||||||
//get total word counts
|
//get total word counts
|
||||||
let user_words = selected_character.stats.user_word_count;
|
let stat = charStats[selected_character.avatar]
|
||||||
let char_words = selected_character.stats.word_count;
|
let user_words = stat.user_word_count;
|
||||||
|
let char_words = stat.non_user_word_count;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -155,6 +159,7 @@ export function AA_CountCharTime(chid){
|
|||||||
$("#result_info").append(`<div class="result_info_item"><span class="result_info_item_title"></span><small class="result_info_item_value">Total words: ${user_words} / ${char_words}</small></div>`);
|
$("#result_info").append(`<div class="result_info_item"><span class="result_info_item_title"></span><small class="result_info_item_value">Total words: ${user_words} / ${char_words}</small></div>`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else { console.debug("AA_CountCharTime -- no valid char found, closing."); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device detection
|
// Device detection
|
||||||
|
@@ -1297,6 +1297,7 @@ app.post("/getstats", jsonParser, function (request, response) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
app.post("/updatestats", jsonParser, function (request, response) {
|
app.post("/updatestats", jsonParser, function (request, response) {
|
||||||
|
console.log(request.body)
|
||||||
if (!request.body) return response.sendStatus(400);
|
if (!request.body) return response.sendStatus(400);
|
||||||
statsHelpers.setCharStats(request.body);
|
statsHelpers.setCharStats(request.body);
|
||||||
return response.sendStatus(200);
|
return response.sendStatus(200);
|
||||||
|
@@ -18,6 +18,7 @@ const crypto = require('crypto');
|
|||||||
|
|
||||||
|
|
||||||
let charStats = {};
|
let charStats = {};
|
||||||
|
let lastSaveTimestamp = 0;
|
||||||
const statsFilePath = 'public/stats.json';
|
const statsFilePath = 'public/stats.json';
|
||||||
|
|
||||||
|
|
||||||
@@ -34,7 +35,8 @@ async function collectAndCreateStats(chatsPath, charactersPath) {
|
|||||||
for (let stat of statsArr) {
|
for (let stat of statsArr) {
|
||||||
finalStats = { ...finalStats, ...stat }
|
finalStats = { ...finalStats, ...stat }
|
||||||
}
|
}
|
||||||
|
// tag with timestamp on when stats were generated
|
||||||
|
finalStats.timestamp = Date.now();
|
||||||
return finalStats;
|
return finalStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,9 +59,15 @@ async function loadStatsFile(chatsPath, charactersPath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to save the stats to file
|
// Function to save the stats to file
|
||||||
|
|
||||||
async function saveStatsToFile() {
|
async function saveStatsToFile() {
|
||||||
|
if (charStats.timestamp > lastSaveTimestamp) {
|
||||||
console.debug('Saving stats to file...');
|
console.debug('Saving stats to file...');
|
||||||
await writeFile(statsFilePath, JSON.stringify(charStats));
|
await writeFile(statsFilePath, JSON.stringify(charStats));
|
||||||
|
lastSaveTimestamp = Date.now();
|
||||||
|
} else {
|
||||||
|
//console.debug('Stats have not changed since last save. Skipping file write.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeStatsToFileAndExit(charStats) {
|
async function writeStatsToFileAndExit(charStats) {
|
||||||
@@ -170,6 +178,7 @@ function getCharStats() {
|
|||||||
|
|
||||||
function setCharStats(stats) {
|
function setCharStats(stats) {
|
||||||
charStats = stats;
|
charStats = stats;
|
||||||
|
charStats.timestamp = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -219,27 +228,20 @@ function calculateTotalGenTimeAndWordCount(char_dir, chat, uniqueGenStartTimes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (json.mes) {
|
if (json.mes) {
|
||||||
if (!firstNonUserMsgSkipped || json.is_user) {
|
|
||||||
let wordCount = countWordsInString(json.mes);
|
let wordCount = countWordsInString(json.mes);
|
||||||
json.is_user ? userWordCount += wordCount : nonUserWordCount += wordCount;
|
json.is_user ? userWordCount += wordCount : nonUserWordCount += wordCount;
|
||||||
json.is_user ? userMsgCount++ : nonUserMsgCount++;
|
json.is_user ? userMsgCount++ : nonUserMsgCount++;
|
||||||
}
|
}
|
||||||
if (!json.is_user) {
|
|
||||||
firstNonUserMsgSkipped = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json.swipes && json.swipes.length > 1) {
|
if (json.swipes && json.swipes.length > 1) {
|
||||||
totalSwipeCount += json.swipes.length - 1; // Subtract 1 to not count the first swipe
|
totalSwipeCount += json.swipes.length - 1; // Subtract 1 to not count the first swipe
|
||||||
for (let i = 1; i < json.swipes.length; i++) { // Start from the second swipe
|
for (let i = 1; i < json.swipes.length; i++) { // Start from the second swipe
|
||||||
let swipeText = json.swipes[i];
|
let swipeText = json.swipes[i];
|
||||||
if (!firstNonUserMsgSkipped || json.is_user) {
|
|
||||||
let wordCount = countWordsInString(swipeText);
|
let wordCount = countWordsInString(swipeText);
|
||||||
json.is_user ? userWordCount += wordCount : nonUserWordCount += wordCount;
|
json.is_user ? userWordCount += wordCount : nonUserWordCount += wordCount;
|
||||||
}
|
json.is_user ? userMsgCount++ : nonUserMsgCount++;
|
||||||
if (!json.is_user) {
|
|
||||||
firstNonUserMsgSkipped = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user