mirror of
https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git
synced 2026-02-25 01:14:11 +00:00
Sort results by usage count
This commit is contained in:
@@ -170,25 +170,31 @@ function flatten(obj, roots = [], sep = ".") {
|
||||
}
|
||||
|
||||
// Calculate biased tag score based on post count and frequent usage
|
||||
function tagBias(count, uses) {
|
||||
return Math.log(count) + Math.log(uses);
|
||||
function calculateUsageBias(count, uses) {
|
||||
return Math.log(1 + count) + Math.log(1 + uses);
|
||||
}
|
||||
// Beautify return type for easier parsing
|
||||
function mapUseCountArray(useCounts) {
|
||||
return useCounts.map(useCount => {return {"name": useCount[0], "type": useCount[1], "count": useCount[2]}});
|
||||
}
|
||||
// Call API endpoint to increase bias of tag in the database
|
||||
function increaseUseCount(tagName, type) {
|
||||
postAPI(`tacapi/v1/increase-use-count?tagname=${tagName}&ttype=${type}`, null);
|
||||
async function increaseUseCount(tagName, type) {
|
||||
await postAPI(`tacapi/v1/increase-use-count?tagname=${tagName}&ttype=${type}`, null);
|
||||
}
|
||||
// Get use count of tag from the database
|
||||
async function getUseCount(tagName, type) {
|
||||
return (await fetchAPI(`tacapi/v1/get-use-count?tagname=${tagName}&ttype=${type}`, true, false))["result"];
|
||||
}
|
||||
async function getUseCounts(tagNames, types) {
|
||||
return (await fetchAPI(`tacapi/v1/get-use-count-list?tags=${tagNames.join("&tags=")}&ttypes=${types.join("&ttypes=")}`))["result"];
|
||||
const rawArray = (await fetchAPI(`tacapi/v1/get-use-count-list?tags=${tagNames.join("&tags=")}&ttypes=${types.join("&ttypes=")}`))["result"]
|
||||
return mapUseCountArray(rawArray);
|
||||
}
|
||||
async function getAllUseCounts() {
|
||||
return (await fetchAPI(`tacapi/v1/get-all-use-counts`))["result"];
|
||||
const rawArray = (await fetchAPI(`tacapi/v1/get-all-use-counts`))["result"];
|
||||
return mapUseCountArray(rawArray);
|
||||
}
|
||||
async function resetUseCount(tagName, type) {
|
||||
putAPI(`tacapi/v1/reset-use-count?tagname=${tagName}&ttype=${type}`, null);
|
||||
await putAPI(`tacapi/v1/reset-use-count?tagname=${tagName}&ttype=${type}`, null);
|
||||
}
|
||||
|
||||
// Sliding window function to get possible combination groups of an array
|
||||
|
||||
Reference in New Issue
Block a user