From b1f1fa8a26d6add04e1ea57cc923b5379d4f784d Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Mon, 17 Jul 2023 19:32:21 -0400 Subject: [PATCH] Change the way we count non-user msgs --- public/script.js | 11 +++++---- public/scripts/RossAscends-mods.js | 11 ++++++--- server.js | 1 + statsHelpers.js | 38 ++++++++++++++++-------------- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/public/script.js b/public/script.js index f1e94d89a..944fd24a6 100644 --- a/public/script.js +++ b/public/script.js @@ -1309,7 +1309,7 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true const momentDate = timestampToMoment(mes.send_date); const timestamp = momentDate.isValid() ? momentDate.format('LL LT') : ''; - statMesProcess(mes, type); + if (mes?.extra?.display_text) { @@ -3712,15 +3712,17 @@ function calculateGenTime(gen_started, gen_finished) { return endDate - startDate; } -function updateStats() { - const response = fetch('/updatestats', { +async function updateStats() { + const response = await fetch('/updatestats', { method: 'POST', headers: getRequestHeaders(), body: JSON.stringify(charStats), }); + if (response.status !== 200) { 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'])) { type = 'normal'; } - console.log(chat); + const generationFinished = new Date(); const img = extractImageFromMessage(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"])), }; } + statMesProcess(chat[chat.length - 1], type); return { type, getMessage }; } diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 4da217610..b551a85e0 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -13,6 +13,7 @@ import { menu_type, max_context, saveSettingsDebounced, + charStats, } from "../script.js"; @@ -71,6 +72,7 @@ const observer = new MutationObserver(function (mutations) { RA_checkOnlineStatus(); } else if (mutation.target.parentNode === SelectedCharacterTab) { setTimeout(RA_CountCharTokens, 200); + setTimeout(AA_CountCharTime, 200); } }); }); @@ -107,8 +109,9 @@ function waitForElement(querySelector, timeout) { //humanize character generation time export function humanizeGenTime(character) { + let stat = charStats[character.avatar] //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); let seconds = 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 total word counts - let user_words = selected_character.stats.user_word_count; - let char_words = selected_character.stats.word_count; + let stat = charStats[selected_character.avatar] + 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(`