Sort results by usage count

This commit is contained in:
DominikDoom
2023-10-01 21:44:24 +02:00
parent d7e98200a8
commit 80fb247dbe
3 changed files with 71 additions and 13 deletions

View File

@@ -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