mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-07 14:43:30 +01:00
#789 Add sorting by char.data strings size ("tokens")
This commit is contained in:
parent
49186dbfc1
commit
3eea8a714c
@ -2872,6 +2872,8 @@
|
||||
<option data-field="date_last_chat" data-order="desc" data-i18n="Recent">Recent</option>
|
||||
<option data-field="chat_size" data-order="desc" data-i18n="Most chats">Most chats</option>
|
||||
<option data-field="chat_size" data-order="asc" data-i18n="Least chats">Least chats</option>
|
||||
<option data-field="data_size" data-order="desc" data-i18n="Most tokens">Most tokens</option>
|
||||
<option data-field="data_size" data-order="asc" data-i18n="Least tokens">Least tokens</option>
|
||||
<option data-field="name" data-order="random" data-i18n="Random">Random</option>
|
||||
</select>
|
||||
</form>
|
||||
|
@ -1224,6 +1224,11 @@ const calculateChatSize = (charDir) => {
|
||||
return { chatSize, dateLastChat };
|
||||
}
|
||||
|
||||
// Calculate the total string length of the data object
|
||||
const calculateDataSize = (data) => {
|
||||
return typeof data === 'object' ? Object.values(data).reduce((acc, val) => acc + new String(val).length, 0) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* processCharacter - Process a given character, read its data and calculate its statistics.
|
||||
*
|
||||
@ -1245,6 +1250,7 @@ const processCharacter = async (item, i) => {
|
||||
const { chatSize, dateLastChat } = calculateChatSize(char_dir);
|
||||
characters[i]['chat_size'] = chatSize;
|
||||
characters[i]['date_last_chat'] = dateLastChat;
|
||||
characters[i]['data_size'] = calculateDataSize(jsonObject?.data);
|
||||
}
|
||||
catch (err) {
|
||||
characters[i] = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user