diff --git a/dist/features/coreServerFeature.js b/dist/features/coreServerFeature.js index 0e96f10..4593e61 100644 --- a/dist/features/coreServerFeature.js +++ b/dist/features/coreServerFeature.js @@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true }); async function coreServerFeature(api, user) { let results = []; let pages = 10; - for await (const page of api.v1.accounts.$select(user.id).following.list({ limit: 80 })) { - results = results.concat(page); - pages--; - if (pages === 0 || results.length < 80) { - break; + try { + for await (const page of api.v1.accounts.$select(user.id).following.list({ limit: 80 })) { + results = results.concat(page); + pages--; + if (pages === 0 || results.length < 80) { + break; + } } } + catch (e) { + return {}; + } const serverFrequ = results.reduce((accumulator, follower) => { const server = follower.url.split("@")[0].split("https://")[1]; if (server in accumulator) { diff --git a/dist/features/favsFeature.js b/dist/features/favsFeature.js index e6f795a..23a209d 100644 --- a/dist/features/favsFeature.js +++ b/dist/features/favsFeature.js @@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true }); async function favFeature(api) { let results = []; let pages = 3; - for await (const page of api.v1.favourites.list({ limit: 80 })) { - results = results.concat(page); - pages--; - if (pages === 0 || results.length < 80) { - break; + try { + for await (const page of api.v1.favourites.list({ limit: 80 })) { + results = results.concat(page); + pages--; + if (pages === 0 || results.length < 80) { + break; + } } } + catch (e) { + return {}; + } const favFrequ = results.reduce((accumulator, status) => { if (!status.account) return accumulator; diff --git a/dist/features/interactsFeature.js b/dist/features/interactsFeature.js index 089a0e4..dd5eb75 100644 --- a/dist/features/interactsFeature.js +++ b/dist/features/interactsFeature.js @@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true }); async function interactFeature(api) { let results = []; let pages = 3; - for await (const page of api.v1.notifications.list({ limit: 80 })) { - results = results.concat(page); - pages--; - if (pages === 0 || results.length < 80) { - break; + try { + for await (const page of api.v1.notifications.list({ limit: 80 })) { + results = results.concat(page); + pages--; + if (pages === 0 || results.length < 80) { + break; + } } } + catch (e) { + return {}; + } const interactFrequ = results.reduce((accumulator, status) => { if (!status.account) return accumulator; diff --git a/dist/features/reblogsFeature.js b/dist/features/reblogsFeature.js index f9a9b62..06d7fe7 100644 --- a/dist/features/reblogsFeature.js +++ b/dist/features/reblogsFeature.js @@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true }); async function getReblogsFeature(api) { let results = []; let pages = 3; - for await (const page of api.v1.timelines.home.list({ limit: 80 })) { - results = results.concat(page); - pages--; - if (pages === 0 || results.length < 80) { - break; + try { + for await (const page of api.v1.timelines.home.list({ limit: 80 })) { + results = results.concat(page); + pages--; + if (pages === 0 || results.length < 80) { + break; + } } } + catch (e) { + return {}; + } const reblogFrequ = results.reduce((accumulator, status) => { if (status.reblog) { if (status.reblog.account.acct in accumulator) { diff --git a/dist/feeds/topPostsFeed.js b/dist/feeds/topPostsFeed.js index 202329a..d0b9416 100644 --- a/dist/feeds/topPostsFeed.js +++ b/dist/feeds/topPostsFeed.js @@ -26,6 +26,9 @@ async function getTopPostFeed(api) { const servers = Object.keys(core_servers).sort((a, b) => { return core_servers[b] - core_servers[a]; }).slice(0, 10); + if (servers.length === 0) { + return []; + } results = await Promise.all(servers.map(async (server) => { if (server === "undefined" || typeof server == "undefined" || server === "") return []; diff --git a/dist/index.js b/dist/index.js index 94ef135..fd9ad81 100644 --- a/dist/index.js +++ b/dist/index.js @@ -143,13 +143,12 @@ class TheAlgorithm { //Adjust Weights based on user interaction if (statusWeights == undefined) return; - const mean = Object.values(statusWeights).reduce((accumulator, currentValue) => accumulator + Math.abs(currentValue), 0) / Object.values(statusWeights).length; + const mean = Object.values(statusWeights).filter((value) => !isNaN(value)).reduce((accumulator, currentValue) => accumulator + Math.abs(currentValue), 0) / Object.values(statusWeights).length; const currentWeight = await this.getWeights(); - const currentMean = Object.values(currentWeight).reduce((accumulator, currentValue) => accumulator + currentValue, 0) / Object.values(currentWeight).length; + const currentMean = Object.values(currentWeight).filter((value) => !isNaN(value)).reduce((accumulator, currentValue) => accumulator + currentValue, 0) / Object.values(currentWeight).length; for (let key in currentWeight) { let reweight = 1 - (Math.abs(statusWeights[key]) / mean) / (currentWeight[key] / currentMean); currentWeight[key] = currentWeight[key] - step * currentWeight[key] * reweight; - console.log(reweight); } await this.setWeights(currentWeight); return currentWeight; diff --git a/src/index.ts b/src/index.ts index 1f057dd..2b84db0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -175,13 +175,12 @@ export default class TheAlgorithm { async weightAdjust(statusWeights: weightsType, step = 0.001): Promise { //Adjust Weights based on user interaction if (statusWeights == undefined) return; - const mean = Object.values(statusWeights).reduce((accumulator, currentValue) => accumulator + Math.abs(currentValue), 0) / Object.values(statusWeights).length; + const mean = Object.values(statusWeights).filter((value: number) => !isNaN(value)).reduce((accumulator, currentValue) => accumulator + Math.abs(currentValue), 0) / Object.values(statusWeights).length; const currentWeight: weightsType = await this.getWeights() - const currentMean = Object.values(currentWeight).reduce((accumulator, currentValue) => accumulator + currentValue, 0) / Object.values(currentWeight).length; + const currentMean = Object.values(currentWeight).filter((value: number) => !isNaN(value)).reduce((accumulator, currentValue) => accumulator + currentValue, 0) / Object.values(currentWeight).length; for (let key in currentWeight) { let reweight = 1 - (Math.abs(statusWeights[key]) / mean) / (currentWeight[key] / currentMean); currentWeight[key] = currentWeight[key] - step * currentWeight[key] * reweight; - console.log(reweight); } await this.setWeights(currentWeight); return currentWeight;