From 284fb684788be5f0b49c35a3c052313155524db5 Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Wed, 19 Jul 2023 09:51:22 -0400 Subject: [PATCH] Fix first chat date injestion (I'm pretty sure). --- public/scripts/stats.js | 6 +++--- statsHelpers.js | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/scripts/stats.js b/public/scripts/stats.js index f049471df..3629178e3 100644 --- a/public/scripts/stats.js +++ b/public/scripts/stats.js @@ -110,7 +110,7 @@ function createHtml(statsType, stats) { if (statsType === "User") { html += createStatBlock("Chatting Since", `${chatAge} ago`); } else { - html += createStatBlock("Chat Age", chatAge); + html += createStatBlock("First Interaction", `${chatAge} ago`); } html += createStatBlock("Chat Time", timeStirng); html += createStatBlock("User Messages", stats.user_msg_count); @@ -284,11 +284,11 @@ async function statMesProcess(line, type, characters, this_chid, oldMesssage) { stat.total_swipe_count++; } stat.date_last_chat = Date.now(); - stat.first_chat_time = Math.min( + stat.date_first_chat = Math.min( stat.date_first_chat ?? new Date("9999-12-31T23:59:59.999Z").getTime(), Date.now() ); updateStats(); } -export { userStatsHandler, characterStatsHandler, getStats, statMesProcess }; +export { userStatsHandler, characterStatsHandler, getStats, statMesProcess, charStats }; diff --git a/statsHelpers.js b/statsHelpers.js index e363ab3ce..0f0f38313 100644 --- a/statsHelpers.js +++ b/statsHelpers.js @@ -393,8 +393,9 @@ function calculateTotalGenTimeAndWordCount( } // If this is the first user message, set the first chat time - if (json.is_user && firstChatTime > Date.now()) { - firstChatTime = timestampToMoment(json.send_date); + if (json.is_user) { + //get min between firstChatTime and timestampToMoment(json.send_date) + firstChatTime = Math.min(timestampToMoment(json.send_date), firstChatTime); } } catch (error) { console.error(`Error parsing line ${line}: ${error}`);